#include "pch.h"
#include "CNxRenderHandler.h"
#include "CNxCefProducer.h"
#include "NxCefUtil.h"
#include "include/base/cef_callback.h"
#include "include/cef_app.h"
#include "include/cef_parser.h"
#include "include/views/cef_browser_view.h"
#include "include/views/cef_window.h"
#include "include/wrapper/cef_closure_task.h"
#include "include/wrapper/cef_helpers.h"
namespace
{
// Returns a data: URI with the specified contents.
std::string GetDataURI(const std::string& data, const std::string& mime_type)
{
return "data:" + mime_type + ";base64," +
CefURIEncode(CefBase64Encode(data.data(), data.size()), false)
.ToString();
}
} // namespace
void CNxRenderHandler::fnTick() const
{
CBrowserList::const_iterator bit = m_oBrowserList.cbegin();
for (; bit != m_oBrowserList.cend(); ++bit)
{
if (*bit)
{
(*bit)->GetHost()->SendExternalBeginFrame();
}
}
}
DWORD WINAPI fnCustomTimer(LPVOID args)
{
BOOL bRet = FALSE;
MSG msg = { 0 };
CNxRenderHandler* pSimpleHandler = (CNxRenderHandler*)args;
UINT_PTR timerid1 = SetTimer(NULL, 0, 10, NULL);
while ((bRet = GetMessage(&msg, NULL, 0, 0) != 0) && pSimpleHandler->m_bTimerLoop)
{
if (bRet == -1)
{
}
else
{
if (msg.message == WM_TIMER)
{
if (msg.wParam == timerid1)
{
printf("timerid1 reaching ...\n");
if (pSimpleHandler) {
pSimpleHandler->fnTick();
}
}
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
KillTimer(NULL, timerid1);
return 0;
}
CNxRenderHandler::CNxRenderHandler(
INxCefProducer* pParent,
SNxVideoFormatDesc sFormatDesc,
std::wstring strUrl,
bool bSendBeginFrame,
shared_ptr<d3d11::Device> const& pDevice) :
m_sFormatDesc(sFormatDesc),
m_strUrl(strUrl),
m_bIsClosing(false),
m_bTimerLoop(false),
m_hTimerThread(nullptr),
m_bInitialized(false),
m_hSeekPaintDone(NULL),
m_hInitialized(NULL),
m_psFrameBufferDesc(nullptr),
m_pParent(pParent),
m_sFrameBufferDesc(sFormatDesc),
m_bSendBeginFrame(bSendBeginFrame),
m_pD3D11Device(pDevice),
m_pViewBuffer(make_shared<d3d11::FrameBuffer>(pDevice))
{
m_bUseSharedTextures = m_pD3D11Device ? true : false;
m_hSeekPaintDone = CreateEvent(NULL, FALSE, FALSE, NULL);
m_hInitialized = CreateEvent(NULL, FALSE, FALSE, NULL);
//参见window_info.external_begin_frame_enabled = false; 如果为true,则需要自定义tick线程
//m_bTimerLoop = true;
//m_hTimerThread = (HANDLE)::CreateThread(NULL, 0, fnCustomTimer, this, 0, NULL);
}
CNxRenderHandler::~CNxRenderHandler()
{
if (m_hInitialized != NULL)
{
CloseHandle(m_hInitialized);
m_hInitialized = NULL;
}
if (m_hSeekPaintDone != NULL)
{
CloseHandle(m_hSeekPaintDone);
m_hSeekPaintDone = NULL;
}
if (m_hTimerThread) {
m_bTimerLoop = false;
WaitForSingleObject(m_hTimerThread, INFINITE);
CloseHandle(m_hTimerThread);
}
}
void CNxRenderHandler::setWinHandle(HWND hwnd)
{
m_hwnd = hwnd;
}
void CNxRenderHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
CEF_REQUIRE_UI_THREAD();
// Add to the list of existing browsers.
m_oBrowserList.push_back(browser);
}
bool CNxRenderHandler::DoClose(CefRefPtr<CefBrowser> browser)
{
CEF_REQUIRE_UI_THREAD();
// Closing the main window requires special handling. See the DoClose()
// documentation in the CEF header for a detailed destription of this
// process.
if (m_oBrowserList.size() == 1)
{
// Set a flag to indicate that the window close should be allowed.
m_bIsClosing = true;
}
// Allow the close. For windowed browsers this will result in the OS close
// event being sent.
return false;
}
void CNxRenderHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
{
CEF_REQUIRE_UI_THREAD();
// Remove from the list of existing browsers.
CBrowserList::const_iterator bit = m_oBrowserList.cbegin();
for (; bit != m_oBrowserList.cend(); ++bit)
{
if ((*bit)->IsSame(browser))
{
m_oBrowserList.erase(bit);
break;
}
}
if (m_oBrowserList.empty())
{
// All browser windows have closed. Quit the application message loop.
//CefQuitMessageLoop();
}
}
void CNxRenderHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl)
{
CEF_REQUIRE_UI_THREAD();
// Don't display an error for downloaded files.
if (errorCode == ERR_ABORTED)
return;
// Display a load error message using a data: URI.
std::stringstream ss;
ss << "<html><body bgcolor=\"white\">"
"<h2>Failed to load URL "
<< std::string(failedUrl) << " with error " << std::string(errorText)
<< " (" << errorCode << ").</h2></body></html>";
frame->LoadURL(GetDataURI(ss.str(), "text/html"));
}
void CNxRenderHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
bool isLoading,
bool canGoBack,
bool canGoForward)
{
if (isLoading) {
}
else
{
}
}
void CNxRenderHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
TransitionType transition_type)
{
}
void CNxRenderHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode)
{
//为了各种类型统一处理,先屏蔽此处的替换,在seek切换时统一做替换
//另外,这个函数执行时html模板肯定已经加载,重新构建也放在seek处实现。
//DoReplaceTexts();
//DoHtmlInitialize();
}
bool CNxRenderHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message)
{
CEF_REQUIRE_UI_THREAD();
auto name = message->GetName().ToString();
if (name == REGISTER_TEMPLATE_MESSAGE_NAME) {
CefRefPtr<CefListValue> input_args = message->GetArgumentList();
m_lstTemplateId.clear();
m_lstIdValue.clear();
for (int i = 0; i < input_args->GetSize(); i++)
{
m_lstTemplateId.push_back(input_args->GetString(i).ToWString());
i++;
m_lstIdValue.push_back(input_args->GetString(i).ToWString());
}
}
else if (name == REG_HTML_DURATION_MESSAGE_NAME)
{
CefRefPtr<CefListValue> input_args = message->GetArgumentList();
m_sFormatDesc.dOrigFrameCount = input_args->GetDouble(0) * m_sFormatDesc.dFps;
((CNxCefProducer*)m_pParent)->SetOriginalFrameCount(m_sFormatDesc.dOrigFrameCount);
}
else if (name == REGISTER_HTML_MESSAGE_NAME)
{
CefRefPtr<CefListValue> input_args = message->GetArgumentList();
std::wstring strParams = input_args->GetString(0).ToWString();
m_bInitialized = true;
SetEvent(m_hInitialized);
}
else if (name == LYRA_LOADCALLBACK_MESSAGE_NAME)
{
OnMessageLyraLoadCallback(message);
}
return false;
}
LRESULT CNxRenderHandler::OnMessageLyraLoadCallback(CefRefPtr<CefProcessMessage> message)
{
// Lyra CG load callback:
// void loadCallback(code, status, message, baseData, extraData)
// code: int类型, 0表示成功,其他都是错误。
// status: string类型,取值为OK或者Error。
// message: string类型,成功时为空字符串,错误时为错误描述字符串。
// baseData: string<JSON>类型,成功时为基础数据,错误时为空字符串。
// extraData: string<JSON>类型,成功时为扩展数据,错误时为空字符串。
CefRefPtr<CefListValue> input_args = message->GetArgumentList();
size_t iSize = input_args->GetSize();
int iCode = input_args->GetInt(0);
if (iCode != 0)
return E_FAIL;
if (m_bInitialized == false)
{
m_strBaseDataJson.clear();
m_strBaseDataJson = input_args->GetString(3).ToString();
std::wstring strTemp = codecvt_to_wide(m_strBaseDataJson);
m_strExtraDataJson.clear();
m_strExtraDataJson = input_args->GetString(4).ToString();
strTemp = codecvt_to_wide(m_strExtraDataJson);
json baseData;
if (SetJsonStringToObject(baseData, m_strBaseDataJson))
{
if (!baseData.empty())
{
if (baseData.contains("duration"))
{
没有合适的资源?快使用搜索试试~ 我知道了~
cef 与 js 的交互,内存共享sharemememory
共488个文件
h:278个
pak:58个
obj:32个
需积分: 5 0 下载量 172 浏览量
2023-03-22
15:17:05
上传
评论
收藏 170.67MB RAR 举报
温馨提示
对于render进程与 browser进程之间的交互 使用共享内存实现交互。对于网页自动登陆 使用sessionid。 MFC应用程序嵌入Chrome网页的实现. (1)包含头文件:NxCefManagerExp.h (2)创建Browser,作为子窗口嵌入 CNxCEFManager* pCEFManager = CNxCEFManager::GetCefManager(); //得到全局Manager pCEFManager->Initialize(AfxGetInstanceHandle(), true); //初始化 INxCefBrowser* pCEFBrowser = pCEFManager->CreateBrowser(网址, 父窗口Wnd,clientRect, nullptr, nullptr); //显示网页 (3)可获取Browser窗口WND HWND hWnd = pCEFBrowser->GetBrowserW
资源推荐
资源详情
资源评论
收起资源包目录
cef 与 js 的交互,内存共享sharemememory (488个子文件)
CustomBuild.bat 370B
CustomBuild.bat 35B
v8_context_snapshot.bin 715KB
snapshot_blob.bin 399KB
NxCefD3d11.cc 30KB
NxCefUtil.cc 10KB
CNxRenderHandler.cpp 21KB
CNxSimpleHandler.cpp 14KB
CNxCefBrowser.cpp 10KB
CNxRenderApp.cpp 8KB
CNxCefManager.cpp 8KB
CNxRenderApp-old.cpp 8KB
CNxCefProducerSong.cpp 7KB
CNxCefProducer.cpp 6KB
CNxLyraProducer.cpp 6KB
CNxCefTrustee.cpp 3KB
dllmain.cpp 551B
NxCefRenderMain.cpp 414B
pch.cpp 158B
icudtl.dat 9.97MB
libcef.dll 167.51MB
libGLESv2.dll 6.14MB
d3dcompiler_47.dll 4.66MB
vk_swiftshader.dll 3.87MB
NxCefManager.dll 3.36MB
chrome_elf.dll 1.17MB
vulkan-1.dll 815KB
NxCefManager.dll 536KB
libEGL.dll 436KB
NxCefRender.exe 2.66MB
NxCefRender.exe 296KB
NxCefManager.exp 6KB
NxCefManager.exp 6KB
NxCefManager.vcxproj.filters 4KB
NxCefRender.vcxproj.filters 2KB
cef_pack_strings.h 450KB
cef_types.h 92KB
cef_pack_resources.h 78KB
cef_bind_internal.h 52KB
cef_browser_capi.h 39KB
cef_net_error_list.h 37KB
cef_v8_capi.h 37KB
cef_browser.h 36KB
cef_v8.h 33KB
cef_types_wrappers.h 31KB
cef_logging.h 29KB
cef_values_capi.h 27KB
cef_string_wrappers.h 27KB
cef_values.h 23KB
cef_translator_test_capi.h 23KB
cef_trace_event.h 22KB
cef_translator_test.h 20KB
cef_menu_model_capi.h 19KB
cef_message_router.h 18KB
cef_request_context_capi.h 17KB
cef_command_ids.h 16KB
cef_template_util.h 16KB
cef_ref_counted.h 16KB
cef_menu_model.h 16KB
cef_view_capi.h 15KB
cef_compiler_specific.h 15KB
cef_request_context.h 15KB
cef_callback_list.h 15KB
cef_server_capi.h 15KB
cef_weak_ptr.h 15KB
cef_resource_manager.h 14KB
cef_bind.h 14KB
cef_view.h 14KB
cef_server.h 14KB
cef_scoped_refptr.h 13KB
cef_window_capi.h 13KB
cef_render_handler_capi.h 13KB
cef_media_router_capi.h 12KB
cef_request_handler_capi.h 12KB
cef_resource_request_handler.h 12KB
cef_request_capi.h 12KB
cef_resource_request_handler_capi.h 12KB
cef_request_handler.h 12KB
CNxRenderApp.h 11KB
cef_render_handler.h 11KB
cef_life_span_handler_capi.h 11KB
cef_window.h 11KB
cef_life_span_handler.h 11KB
cef_context_menu_handler_capi.h 11KB
cef_dom_capi.h 11KB
cef_media_router.h 10KB
cef_callback_internal.h 10KB
cef_callback.h 10KB
NxCefD3d11.h 10KB
cef_xml_reader_capi.h 10KB
cef_request.h 10KB
cef_frame_handler_capi.h 10KB
cef_context_menu_handler.h 10KB
cef_resource_handler_capi.h 9KB
cef_textfield_capi.h 9KB
cef_frame_capi.h 9KB
cef_build.h 9KB
cef_frame_handler.h 9KB
cef_extension_handler_capi.h 9KB
cef_callback_helpers.h 9KB
共 488 条
- 1
- 2
- 3
- 4
- 5
资源评论
徐秀丽
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功