• Cef笔记:进程间通信


    原文出处: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;
    }

  • 相关阅读:
    Linux学习-数据类型学习
    存储系统架构演变
    什么是一阶逻辑?
    【开源】EValidator Java简单校验工具二
    如何通过pywinauto开始PC端自动化
    零零信安-D&D数据泄露报警日报【第29期】
    第09章 文本特征向量化
    除了「加机器」,其实你的微服务还能这样优化
    业务处理系统(TPS)
    Linux下的静态链接库和动态链接库
  • 原文地址:https://blog.csdn.net/s634772208/article/details/133815598