CEF类笔记-cef_app

cef_app.h

int CefExecuteProcess(const CefMainArgs& args, CefRefPtr<CefApp> application, void* windows_sandbox_info);

应该从应用程序入口点函数调用此函数以执行辅助进程。它可用于从浏览器客户端可执行文件(默认行为)或由CefSettings.browser_subprocess_path的值指定的单独可执行文件运行辅助进程。如果为浏览器进程调用(在命令行中没有“type”进行标识),它将立即返回值-1。如果为可识别的辅助进程调用,它将阻塞,直到该进程应该退出然后返回进程退出代码。application 参数可以为空。windows_sandbox_info参数仅在windows上使用,可以为空(请参阅 cef_sandbox_win.h获取详细信息)。

bool CefInitialize(const CefMainArgs& args, const CefSettings& settings, CefRefPtr<CefApp> application, void* windows_sandbox_info);

应该在主应用程序线程上调用此函数以初始化CEF browser进程。application参数可以为空。返回值true表示成功,返回值false表示失败。

void CefShutdown();

应该在主应用程序线程上调用此函数,以便在应用程序退出之前关闭CEF browser进程。

void CefDoMessageLoopWork();

执行CEF消息循环处理的单个迭代。此函数用于CEF消息循环必须集成到现有应用程序消息循环中的情况。不建议大多数用户使用此函数;如果可能的话,请使用CefRunMessageLoop()函数或CefSettings.multi_threaded_message_loop。在使用这个函数时,必须注意平衡性能和CPU的过度使用。建议启用CefSettings.external_message_pump选项,以便CefBrowserProcessHandler::OnScheduleMessagePumpWork()回调可以促进调度过程。此函数只能在主应用程序线程上调用,并且只能在使用CefSettings.multi_threaded_message_loop值为false。此功能不会阻塞。

void CefRunMessageLoop();

运行CEF消息循环。使用此函数而不是应用程序提供的消息循环,以在性能和CPU使用之间获得最佳平衡。此函数只能在主应用程序线程上调用,并且只能在使用CefSettings.multi_threaded_message_loop值为false。此功能将一直阻塞,直到系统接收到退出消息。

void CefQuitMessageLoop();

退出通过调用CefRunMessageLoop()启动的CEF消息循环。此函数只能在主应用程序线程上调用,并且只能在使用CefRunMessageLoop()时调用。

void CefSetOSModalLoop(bool osModalLoop);

在调用诸如TrackPopupMenu之类的Windows api(这些api进入模式消息循环)之前设置为true。退出模式消息循环后设置为false。

void CefEnableHighDPISupport();

在进程启动期间调用以在Windows 7或Windows 7上启用高DPI支持新的。旧的Windows版本应该让DPI不知道,因为它们不支持DirectWrite,而且GDI字体的紧排非常严重。

CefApp

实现此接口以提供处理程序实现。方法将由指定的进程和/或线程调用。

virtual void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) {}

提供了在CEF和Chromium处理之前查看和(或)修改命令行参数的机会。浏览器进程的process_type值将为空。不要保留对传递给此方法的CefCommandLine对象的引用。这个CefSettings.command_line_args_disabled的值可用于从空命令行对象开始。在调用此方法之前,将设置CefSettings中指定的、等同于命令行参数的任何值。使用此方法修改非浏览器进程的命令行参数时要小心,因为这可能会导致未定义的行为,包括崩溃。

virtual void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) {}

提供注册自定义方案的机会。不要保留对“注册器”对象的引用。在每个进程的主线程上调用此方法,并且在所有进程中注册的方案应该相同。

virtual CefRefPtr<CefResourceBundleHandler> GetResourceBundleHandler() {
    return nullptr;
}

返回资源包事件的处理程序。如果CefSettings.pack_loading_disabled为true,则必须返回处理程序。如果没有返回处理程序,将从包文件加载资源。此方法由浏览器调用,并在多个线程上渲染进程。

virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() {
    return nullptr;
}

返回浏览器进程特定功能的处理程序。在浏览器进程中的多个线程上调用此方法。

virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() {
    return nullptr;
}

返回特定于呈现过程的功能的处理程序。在渲染进程主线程上调用此方法。

已标记关键词 清除标记
<div><p>Todo: Compare cefpython/src/subprocess/main_message_loop<em> files with cef/tests/shared/browser/main_message_loop</em> files. These files may have been changed after v66 update.</p> <p>--</p> <p>Using external message pump will improve performance, but it is also required to get rid of some bugs, like missing keyboard events on Mac/Windows reported on the CEF Forum in <a href="https://magpcss.org/ceforum/viewtopic.php?f=6&t=11141">this topic</a>, and <a href="http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=13302">this</a>.</p> <p>Examples that call <code>cefpython.MessageLoopWork</code> should implement external message pump.</p> <p>In CEF there are two functions for running message loop: 1. <code>CefRunMessageLoop</code> (cefpython.MessageLoop) 2. <code>CefDoMessageLoopWork</code> (cefpython.MessageLoopWork) - for integrating into existing frameworks. </p> <p>In CEF Python we use message loop work in most examples (only PyWin32 uses MessageLoop). According to CEF doc comments <code>CefRunMessageLoop</code> will always have the best performance.</p> <h3>Task 1: GTK example should call MessageLoop() on Linux</h3> <p>The pygtk_.py example could use <code>cefpython.MessageLoop</code> on Linux. CEF will call GTK's native loop and it should work good - tested in idriissha's fork. Currently <code>cefpython.MessageLoopWork</code> is called in a timer.</p> <p>Update: gtk2.py example uses MessageLoop() by default and MessageLoopWork when --message-loop-timer flag is passed. I tried to use MessageLoop() in gtk3.py, but it didn't work.</p> <h3>Task 2: Use external message pump in other examples</h3> <p>There is <a href="https://bitbucket.org/chromiumembedded/cef/issues/1805/improve-support-for-a-host-owned-message">issue 1805</a> in upstream CEF to improve support for a host owned message loop. It is now marked as Resolved. The <code>CefSettings.external_message_pump</code> option and <code>CefBrowserProcessHandler::OnScheduleMessagePumpWork</code> method already landed in master and in branch 2743. See this <a href="https://bitbucket.org/chromiumembedded/cef/commits/1ff26aa">commit</a>. You can pass the <code>--external-message-pump</code> flag to cefclient to test the new mode and see how it performs.</p> <p>Example implementation in upstream cefclient: 1. All platforms - <a href="https://bitbucket.org/chromiumembedded/cef/src/master/tests/cefclient/browser/main_message_loop_external_pump.cc">main_message_loop_external_pump.cc</a> 2. Linux - <a href="https://bitbucket.org/chromiumembedded/cef/src/master/tests/cefclient/browser/main_message_loop_external_pump_linux.cc">main_message_loop_external_pump_linux.cc</a> 3. Windows - <a href="https://bitbucket.org/chromiumembedded/cef/src/master/tests/cefclient/browser/main_message_loop_external_pump_win.cc">main_message_loop_external_pump_win.cc</a> 4. Mac - <a href="https://bitbucket.org/chromiumembedded/cef/src/master/tests/cefclient/browser/main_message_loop_external_pump_mac.mm">main_message_loop_external_pump_mac.mm</a></p> <p>Doc comments for the new functionality:</p> <pre><code> /// // Set to true (1) to control browser process main (UI) thread message pump // scheduling via the CefBrowserProcessHandler::OnScheduleMessagePumpWork() // callback. This option is recommended for use in combination with the // CefDoMessageLoopWork() function in cases where the CEF message loop must be // integrated into an existing application message loop (see additional // comments and warnings on CefDoMessageLoopWork). Enabling this option is not // recommended for most users; leave this option disabled and use either the // CefRunMessageLoop() function or multi_threaded_message_loop if possible. /// int external_message_pump; /// // Called from any thread when work has been scheduled for the browser process // main (UI) thread. This callback is used in combination with CefSettings. // external_message_pump and CefDoMessageLoopWork() in cases where the CEF // message loop must be integrated into an existing application message loop // (see additional comments and warnings on CefDoMessageLoopWork). This // callback should schedule a CefDoMessageLoopWork() call to happen on the // main (UI) thread. |delay_ms| is the requested delay in milliseconds. If // |delay_ms| is <= 0 then the call should happen reasonably soon. If // |delay_ms| is > 0 then the call should be scheduled to happen after the // specified delay and any currently pending scheduled call should be // cancelled. /// virtual void OnScheduleMessagePumpWork(int64 delay_ms) {} /// // Perform a single iteration of CEF message loop processing. This function is // provided for cases where the CEF message loop must be integrated into an // existing application message loop. Use of this function is not recommended // for most users; use either the CefRunMessageLoop() function or // CefSettings.multi_threaded_message_loop if possible. When using this function // care must be taken to balance performance against excessive CPU usage. It is // recommended to enable the CefSettings.external_message_pump option when using // this function so that CefBrowserProcessHandler::OnScheduleMessagePumpWork() // callbacks can facilitate the scheduling process. This function should only be // called on the main application thread and only if CefInitialize() is called // with a CefSettings.multi_threaded_message_loop value of false. This function // will not block. /// void CefDoMessageLoopWork(); </code></pre><p>该提问来源于开源项目:cztomczak/cefpython</p></div>
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页