Cef笔记:进程间通信
  WtpFkP2ympcR 2023年11月02日 47 0


原文出处:https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage#markdown-header-threads

Inter-Process Communication (IPC)

Since CEF3 runs in multiple processes it is necessary to provide mechanisms for communicating between those processes. CefBrowser and CefFrame objects exist in both the browser and render processes which helps to facilitate this process. Each CefBrowser and CefFrame object also has a unique ID value associated with it that will match on both sides of the process boundary.

Process Startup Messages

Startup data can be associated with a specific CefBrowser instance at creation time via the CefRefPtr extra_info parameter to CefBrowserHost::CreateBrowser. That extra_info data will be delivered to every renderer process associated with that CefBrowser via the CefRenderProcessHandler::OnBrowserCreated callback. See the “Processes” section for more information about when and how a new renderer process will be spawned.

Process Runtime Messages

Messages can be passed between processes at runtime using the CefProcessMessage class. These messages are associated with a specific CefBrowser and CefFrame instance and sent using the CefFrame::SendProcessMessage() method. The process message should contain whatever state information is required via CefProcessMessage::GetArgumentList().

// Create the message object.
 CefRefPtr msg= CefProcessMessage::Create(“my_message”);// Retrieve the argument list object.
 CefRefPtr args = msg>GetArgumentList();// Populate the argument values.
 args->SetString(0, “my string”);
 args->SetInt(0, 10);// Send the process message to the main frame in the render process.
 // Use PID_BROWSER instead when sending a message to the browser process.
 browser->GetMainFrame()->SendProcessMessage(PID_RENDERER, msg);
 A message sent from the browser process to the render process will arrive in CefRenderProcessHandler::OnProcessMessageReceived(). A message sent from the render process to the browser process will arrive in CefClient::OnProcessMessageReceived().bool MyHandler::OnProcessMessageReceived(
 CefRefPtr browser,
 CefRefPtr frame,
 CefProcessId source_process,
 CefRefPtr message) {
 // Check the message name.
 const std::string& message_name = message->GetName();
 if (message_name == “my_message”) {
 // Handle the message here…
 return true;
 }
 return false;
 }


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
WtpFkP2ympcR