当前位置: 首页 > news >正文

CEF调试Render进程

首先我们按照CefSample的Demo去模仿自己的工程,然后在通过SimpleApp继承了CefRenderProcessHandler,并且重写了CefRenderProcessHandler的部分函数,结果发现CefSample关于Render进程的代码都没有调用。额。。。怎么回事呢?哦,对了Cef是多进程的,所以我们调试Cef Browser 进程的时候当然不会调用关于Render进程的代码(跨进程了)。所以我们需要把Render进程附加到VS调试器。

 

此时理论上就可以调试Cef Render进程了。额。。。结果还是不能?这就奇怪,试着在
CRenderApp::OnContextCreated 弹出MessageBox,结果还是没有弹出来。说明Render进程根本就没有调用我们这里的Render实现的代码。是哪里问题呢???肯定和多进程有关系,于是继续看看CefSample的例子,一步步的整理。此时突然发现CefExecuteProcess,这个函数会调用起子进程。但是只有是Browser进程的时候exit_code才返回-1,所以下面这段代码在如果是Render进程的时候就直接返回了,根本不会调用到我们重写Render进程的地方。

int exit_code = CefExecuteProcess(main_args, NULL, sandbox_info);
if (exit_code >= 0) {
	// The sub-process has completed so return here.
	return exit_code;
}

此时有点懵逼了,那么我们该怎么处理Render进程的消息和事件呢???不过可以确定问题就在CefExecuteProcess,所以在仔细查看一下这个函数原型。

///
// This function should be called from the application entry point function to
// execute a secondary process. It can be used to run secondary processes from
// the browser client executable (default behavior) or from a separate
// executable specified by the CefSettings.browser_subprocess_path value. If
// called for the browser process (identified by no "type" command-line value)
// it will return immediately with a value of -1. If called for a recognized
// secondary process it will block until the process should exit and then return
// the process exit code. The |application| parameter may be empty. The
// |windows_sandbox_info| parameter is only used on Windows and may be NULL (see
// cef_sandbox_win.h for details).
///
/*--cef(api_hash_check,optional_param=application,
        optional_param=windows_sandbox_info)--*/
int CefExecuteProcess(const CefMainArgs& args,
                      CefRefPtr<CefApp> application,
                      void* windows_sandbox_info);

有么有新发现?第二个参数是CefApp 而CefApp就是我们重写Browser进程,Render进程的基类。所以既然我们想调试Render进程,那么试着尝试把Render进程App参数传入进去。代码如下:

CefRefPtr<CefApp> g_app = NULL;

bool ExecuteCefProcess(HINSTANCE hist)
{
	CefEnableHighDPISupport();

	CefMainArgs cef_main_args(hist);
	CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
	command_line->InitFromString(::GetCommandLineW());

	//通过启动参数判断进程类型,如果没有type则是Browser进程,type说明可以查看CefExecuteProcess函数说明
	if (!command_line->HasSwitch("type"))
	{
		g_app = new CBrowserApp();
	}

	//如果有type并且value=renderer则为Render进程
	const std::string& process_type = command_line->GetSwitchValue("type");//RenderProcess
	if (process_type == "renderer")
	{
		g_app = new CRenderApp();
	}

	//启动子进程
	int nexit_code = CefExecuteProcess(cef_main_args, g_app.get(), NULL);
	if (nexit_code >= 0)
	{
		return false;
	}
	return true;
}

此时我们在附加进程,调试一下add函数试试。

相关文章:

  • Chrome V8引擎介绍
  • c++中的 extern “C“
  • 中断向量表
  • WM_NCCREATE与WM_CREATE的区别
  • GetWindowLongPtr
  • WNDCLASSEX
  • C++强制类型转换运算符(static_cast、reinterpret_cast、const_cast和dynamic_cast)
  • C++ 虚函数表 vfptr
  • WM_NCHITTEST
  • CreateProcess函数详解
  • CEF类笔记-cef_app
  • cef_client.h
  • cef_browser.h
  • C++ List的用法(整理)
  • cef_v8.h
  • 4. 路由到控制器 - Laravel从零开始教程
  • Angular js 常用指令ng-if、ng-class、ng-option、ng-value、ng-click是如何使用的?
  • Apache的80端口被占用以及访问时报错403
  • electron原来这么简单----打包你的react、VUE桌面应用程序
  • ES6核心特性
  • idea + plantuml 画流程图
  • JavaScript服务器推送技术之 WebSocket
  • javascript面向对象之创建对象
  • Laravel Mix运行时关于es2015报错解决方案
  • LeetCode算法系列_0891_子序列宽度之和
  • MySQL数据库运维之数据恢复
  • PHP那些事儿
  • Protobuf3语言指南
  • sublime配置文件
  • Web Storage相关
  • 浮现式设计
  • 开源地图数据可视化库——mapnik
  • 如何使用 JavaScript 解析 URL
  • 什么软件可以提取视频中的音频制作成手机铃声
  • 温故知新之javascript面向对象
  • 学习ES6 变量的解构赋值
  • 白色的风信子
  • elasticsearch-head插件安装
  • PostgreSQL之连接数修改
  • ​ 轻量应用服务器:亚马逊云科技打造全球领先的云计算解决方案
  • ​flutter 代码混淆
  • #中的引用型是什么意识_Java中四种引用有什么区别以及应用场景
  • (9)YOLO-Pose:使用对象关键点相似性损失增强多人姿态估计的增强版YOLO
  • (C)一些题4
  • (安卓)跳转应用市场APP详情页的方式
  • (二)学习JVM —— 垃圾回收机制
  • (附源码)spring boot校园健康监测管理系统 毕业设计 151047
  • (规划)24届春招和25届暑假实习路线准备规划
  • (免费领源码)Java#ssm#MySQL 创意商城03663-计算机毕业设计项目选题推荐
  • (三)c52学习之旅-点亮LED灯
  • (十三)Maven插件解析运行机制
  • (四)TensorRT | 基于 GPU 端的 Python 推理
  • (循环依赖问题)学习spring的第九天
  • (转)Java socket中关闭IO流后,发生什么事?(以关闭输出流为例) .
  • (转)重识new