关于cef:cef-JS与C互调

JS调用C++函数(1)继承CefRenderProcessHandler(2)重写OnContextCreated虚函数(3)绑定值或者JS对象(数组)到window对象上(4)在js中拜访window对象上绑定的值(或者JS对象、数组等)// Called immediately after the V8 context for a frame has been created. To // retrieve the JavaScript 'window' object use the CefV8Context::GetGlobal() // method. V8 handles can only be accessed from the thread on which they are // created. A task runner for posting tasks on the associated thread can be // retrieved via the CefV8Context::GetTaskRunner() method. /// /*--cef()--*/ virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,OnContextCreated接口切实chrome的V8引擎创立后调用的,在这里咱们须要将JS外面调用的函数和C++的执行函数关联起来,这样JS就能够“执行”C++代码了。 咱们的函数都是定义在window对象中的,依据正文咱们须要GetGlobal获取这个对象。 void SimpleApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context){ // The var type can accept all object or variable CefRefPtr<CefV8Value> window = context->GetGlobal(); // bind value into window[or you can bind value into window sub node] CefRefPtr<CefV8Value> strValue = CefV8Value::CreateString("say yes"); window->SetValue("say_yes", strValue, V8_PROPERTY_ATTRIBUTE_NONE);}CefRefPtr<CefV8Handler> myV8handle = new CCefV8Handler(); CefRefPtr<CefV8Value> myFun = CefV8Value::CreateFunction(L"SetAppState", myV8handle); static_cast<CCefV8Handler*>(myV8handle.get())->AddFun(L"SetAppState", &CChromeJsCallback::JsSetAppState); pObjApp->SetValue(L"SetAppState", myFun, V8_PROPERTY_ATTRIBUTE_NONE);

December 14, 2022 · 1 min · jiezi

关于cef:cef-进程间通信

因为CEF3运行在多过程环境下,所以须要提供一个过程间通信机制。CefBrowser和CefFrame对象在Borwser和Render过程里都有代理对象。CefBrowser和CefFrame对象都有一个惟一ID值绑定,便于在两个过程间定位匹配的代理对象。 解决启动音讯为了给所有的Render过程提供一样的启动信息在Browser过程实现CefBrowserProcessHander::OnRenderProcessThreadCreated()办法。在这里传入的信息会在Render过程的CefRenderProcessHandler::OnRenderThreadCreated()办法里承受。 解决运行时音讯在过程申明周期内,任何时候你都能够通过CefProcessMessage类传递过程间音讯。这些信息和特定的CefBrowser实例绑定在一起,用户能够通过CefBrowser::SendProcessMessage()办法发送。过程间音讯能够蕴含任意的状态信息,用户能够通过CefProcessMessage::GetArgumentList()获取。 // Create the message object.CefRefPtr<CefProcessMessage> msg= CefProcessMessage::Create(“my_message”);// Retrieve the argument list object.CefRefPtr<CefListValue> args = msg>GetArgumentList();// Populate the argument values.args->SetString(0, “my string”);args->SetInt(0, 10);一个从Browser过程发送到Render过程的音讯将会在CefRenderProcessHandler::OnProcessMessageReceived()办法里被接管。一个从Render过程发送到Browser过程的音讯将会在CefClient::OnProcessMessageReceived()办法里被接管。 bool MyHandler::OnProcessMessageReceived( CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> 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;}咱们能够调用CefFrame::GerIdentifier()获取CefFrame的ID,并通过过程间音讯发送给另一个过程,而后在接收端通过CefBrowser::GetFrame()找到对应的CefFrame。通过这种形式能够将过程间音讯和特定的CefFrame分割在一起。 // Helper macros for splitting and combining the int64 frame ID value.#define MAKE_INT64(int_low, int_high) \ ((int64) (((int) (int_low)) | ((int64) ((int) (int_high))) << 32))#define LOW_INT(int64_val) ((int) (int64_val))#define HIGH_INT(int64_val) ((int) (((int64) (int64_val) >> 32) & 0xFFFFFFFFL))// Sending the frame ID.const int64 frame_id = frame->GetIdentifier();args->SetInt(0, LOW_INT(frame_id));args->SetInt(1, HIGH_INT(frame_id));// Receiving the frame ID.const int64 frame_id = MAKE_INT64(args->GetInt(0), args->GetInt(1));CefRefPtr<CefFrame> frame = browser->GetFrame(frame_id);

November 20, 2022 · 1 min · jiezi

关于cef:cef-CefbwserCefFrame

Cefbwser、CefFrame

November 20, 2022 · 1 min · jiezi

关于cef:cef-CefV8HandlerCefV8ValueCefV8Context

CefV8Handler、CefV8Value、CefV8Context

November 20, 2022 · 1 min · jiezi

关于cef:cef-CefClient

/*--cef(source=client,no_debugct_check)--*/class CefClient : public virtual CefBase { public: /// // Return the handler for context menus. If no handler is provided the default // implementation will be used. /// /*--cef()--*/ virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() { return NULL; } /// // Return the handler for dialogs. If no handler is provided the default // implementation will be used. /// /*--cef()--*/ virtual CefRefPtr<CefDialogHandler> GetDialogHandler() { return NULL; } /// // Return the handler for browser display state events. /// /*--cef()--*/ virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() { return NULL; } /// // Return the handler for download events. If no handler is returned downloads // will not be allowed. /// /*--cef()--*/ virtual CefRefPtr<CefDownloadHandler> GetDownloadHandler() { return NULL; } /// // Return the handler for drag events. /// /*--cef()--*/ virtual CefRefPtr<CefDragHandler> GetDragHandler() { return NULL; } /// // Return the handler for find result events. /// /*--cef()--*/ virtual CefRefPtr<CefFindHandler> GetFindHandler() { return NULL; } /// // Return the handler for focus events. /// /*--cef()--*/ virtual CefRefPtr<CefFocusHandler> GetFocusHandler() { return NULL; } /// // Return the handler for geolocation permissions requests. If no handler is // provided geolocation access will be denied by default. /// /*--cef()--*/ virtual CefRefPtr<CefGeolocationHandler> GetGeolocationHandler() { return NULL; } /// // Return the handler for JavaScript dialogs. If no handler is provided the // default implementation will be used. /// /*--cef()--*/ virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() { return NULL; } /// // Return the handler for keyboard events. /// /*--cef()--*/ virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() { return NULL; } /// // Return the handler for browser life span events. /// /*--cef()--*/ virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() { return NULL; } /// // Return the handler for browser load status events. /// /*--cef()--*/ virtual CefRefPtr<CefLoadHandler> GetLoadHandler() { return NULL; } /// // Return the handler for off-screen rendering events. /// /*--cef()--*/ virtual CefRefPtr<CefRenderHandler> GetRenderHandler() { return NULL; } /// // Return the handler for browser request events. /// /*--cef()--*/ virtual CefRefPtr<CefRequestHandler> GetRequestHandler() { return NULL; } /// // Called when a new message is received from a different process. Return true // if the message was handled or false otherwise. Do not keep a reference to // or attempt to access the message outside of this callback. /// /*--cef()--*/ virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message) { return false; }};

November 20, 2022 · 2 min · jiezi

关于cef:cef-类和接口说明

CefApp:次要解决浏览器自身相干事件 CefClient:次要解决了浏览器网页之间的事件 CefV8Handler,CefV8Value和CefV8Context是被用来创立和拜访JavaScript对象。 Cefbwser是次要的浏览器窗口类,能够用动态的函数CreateBrowser() 和CreateBrowserSync() 来创立一个新的浏览器窗口,公开由浏览器提供的性能。包含后退后退导航,起源检索,加载申请等。 Ceframe代表一个浏览器窗口的框架,每个浏览器窗口有一个顶层的主框架,而这个主框架能够用GetMainFrame() 办法失去。 (Cefbwser和CefFrame对象被用来发送命令给浏览器以及在回调函数里获取状态信息。每个CefBrowser对象蕴含一个主 CefFrame对象,主CefFrame对象代表页面的顶层frame;同时每个CefBrowser对象能够蕴含零个或多个的CefFrame对象, 别离代表不同的子Frame。例如,一个浏览器加载了两个iframe,则该CefBrowser对象领有三个CefFrame对象(顶层frame和两 个iframe)。)这两个类须要重写

November 20, 2022 · 1 min · jiezi

关于cef:cef-概述

CEFApp/*--cef(source=client,no_debugct_check)--*/class CefApp : public virtual CefBase { public: /// // Provides an opportunity to view and/or modify command-line arguments before // processing by CEF and Chromium. The |process_type| value will be empty for // the browser process. Do not keep a reference to the CefCommandLine object // passed to this method. The CefSettings.command_line_args_disabled value // can be used to start with an empty command-line object. Any values // specified in CefSettings that equate to command-line arguments will be set // before this method is called. Be cautious when using this method to modify // command-line arguments for non-browser processes as this may result in // undefined behavior including crashes. /// /*--cef(optional_param=process_type)--*/ virtual void OnBeforeCommandLineProcessing( const CefString& process_type, CefRefPtr<CefCommandLine> command_line) { } /// // Provides an opportunity to register custom schemes. Do not keep a reference // to the |registrar| object. This method is called on the main thread for // each process and the registered schemes should be the same across all // processes. /// /*--cef()--*/ virtual void OnRegisterCustomSchemes( CefRefPtr<CefSchemeRegistrar> registrar) { } /// // Return the handler for resource bundle events. If // CefSettings.pack_loading_disabled is true a handler must be returned. If no // handler is returned resources will be loaded from pack files. This method // is called by the browser and render processes on multiple threads. /// /*--cef()--*/ virtual CefRefPtr<CefResourceBundleHandler> GetResourceBundleHandler() { return NULL; } /// // Return the handler for functionality specific to the browser process. This // method is called on multiple threads in the browser process. /// /*--cef()--*/ virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() { return NULL; } /// // Return the handler for functionality specific to the render process. This // method is called on the render process main thread. /// /*--cef()--*/ virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() { return NULL; }};接口阐明: ...

November 20, 2022 · 2 min · jiezi

关于cef:cef-类与接口介绍

应用程序构造每个CEF3应用程序都有一个雷同的构造: 提供一个入口函数以初始化CEF和运行每个子过程逻辑和CEF音讯解决提供一个CefApp子类解决某个过程的回调提供一个CefClinet子类解决某个浏览过程的回调调用CefBrowserHost::CreateBrowser()函数创立浏览过程实例并应用CefLifeSpanHandler来管- 理浏览生命周期typedef struct _cef_settings_t { /// // Size of this structure. /// size_t size; /// // Set to true (1) to use a single process for the browser and renderer. This // run mode is not officially supported by Chromium and is less stable than // the multi-process default. Also configurable using the "single-process" // command-line switch. /// bool single_process; /// // The path to a separate executable that will be launched for sub-processes. // By default the browser process executable is used. See the comments on // CefExecuteProcess() for details. Also configurable using the // "browser-subprocess-path" command-line switch. /// cef_string_t browser_subprocess_path; /// // Set to true (1) to have the browser process message loop run in a separate // thread. If false (0) than the CefDoMessageLoopWork() function must be // called from your application message loop. /// bool multi_threaded_message_loop; /// // Set to true (1) to disable configuration of browser process features using // standard CEF and Chromium command-line arguments. Configuration can still // be specified using CEF data structures or via the // CefApp::OnBeforeCommandLineProcessing() method. /// bool command_line_args_disabled; /// // The location where cache data will be stored on disk. If empty an in-memory // cache will be used for some features and a temporary disk cache for others. // HTML5 databases such as localStorage will only persist across sessions if a // cache path is specified. /// cef_string_t cache_path; /// // To persist session cookies (cookies without an expiry date or validity // interval) by default when using the global cookie manager set this value to // true. Session cookies are generally intended to be transient and most Web // browsers do not persist them. A |cache_path| value must also be specified to // enable this feature. Also configurable using the "persist-session-cookies" // command-line switch. /// bool persist_session_cookies; /// // Value that will be returned as the User-Agent HTTP header. If empty the // default User-Agent string will be used. Also configurable using the // "user-agent" command-line switch. /// cef_string_t user_agent; /// // Value that will be inserted as the product portion of the default // User-Agent string. If empty the Chromium product version will be used. If // |userAgent| is specified this value will be ignored. Also configurable // using the "product-version" command-line switch. /// cef_string_t product_version; /// // The locale string that will be passed to WebKit. If empty the default // locale of "en-US" will be used. This value is ignored on Linux where locale // is determined using environment variable parsing with the precedence order: // LANGUAGE, LC_ALL, LC_MESSAGES and LANG. Also configurable using the "lang" // command-line switch. /// cef_string_t locale; /// // The directory and file name to use for the debug log. If empty, the // default name of "debug.log" will be used and the file will be written // to the application directory. Also configurable using the "log-file" // command-line switch. /// cef_string_t log_file; /// // The log severity. Only messages of this severity level or higher will be // logged. Also configurable using the "log-severity" command-line switch with // a value of "verbose", "info", "warning", "error", "error-report" or // "disable". /// cef_log_severity_t log_severity; /// // Enable DCHECK in release mode to ease debugging. Also configurable using the // "enable-release-dcheck" command-line switch. /// bool release_dcheck_enabled; /// // Custom flags that will be used when initializing the V8 JavaScript engine. // The consequences of using custom flags may not be well tested. Also // configurable using the "js-flags" command-line switch. /// cef_string_t javascript_flags; /// // The fully qualified path for the resources directory. If this value is // empty the cef.pak and/or devtools_resources.pak files must be located in // the module directory on Windows/Linux or the app bundle Resources directory // on Mac OS X. Also configurable using the "resources-dir-path" command-line // switch. /// cef_string_t resources_dir_path; /// // The fully qualified path for the locales directory. If this value is empty // the locales directory must be located in the module directory. This value // is ignored on Mac OS X where pack files are always loaded from the app // bundle Resources directory. Also configurable using the "locales-dir-path" // command-line switch. /// cef_string_t locales_dir_path; /// // Set to true (1) to disable loading of pack files for resources and locales. // A resource bundle handler must be provided for the browser and render // processes via CefApp::GetResourceBundleHandler() if loading of pack files // is disabled. Also configurable using the "disable-pack-loading" command- // line switch. /// bool pack_loading_disabled; /// // Set to a value between 1024 and 65535 to enable remote debugging on the // specified port. For example, if 8080 is specified the remote debugging URL // will be http://localhost:8080. CEF can be remotely debugged from any CEF or // Chrome browser window. Also configurable using the "remote-debugging-port" // command-line switch. /// int remote_debugging_port; /// // The number of stack trace frames to capture for uncaught exceptions. // Specify a positive value to enable the CefV8ContextHandler:: // OnUncaughtException() callback. Specify 0 (default value) and // OnUncaughtException() will not be called. Also configurable using the // "uncaught-exception-stack-size" command-line switch. /// int uncaught_exception_stack_size; /// // By default CEF V8 references will be invalidated (the IsValid() method will // return false) after the owning context has been released. This reduces the // need for external record keeping and avoids crashes due to the use of V8 // references after the associated context has been released. // // CEF currently offers two context safety implementations with different // performance characteristics. The default implementation (value of 0) uses a // map of hash values and should provide better performance in situations with // a small number contexts. The alternate implementation (value of 1) uses a // hidden value attached to each context and should provide better performance // in situations with a large number of contexts. // // If you need better performance in the creation of V8 references and you // plan to manually track context lifespan you can disable context safety by // specifying a value of -1. // // Also configurable using the "context-safety-implementation" command-line // switch. /// int context_safety_implementation; /// // Set to true (1) to ignore errors related to invalid SSL certificates. // Enabling this setting can lead to potential security vulnerabilities like // "man in the middle" attacks. Applications that load content from the // internet should not enable this setting. Also configurable using the // "ignore-certificate-errors" command-line switch. /// bool ignore_certificate_errors; /// // Used on Mac OS X to specify the background color for hardware accelerated // content. /// cef_color_t background_color;} cef_settings_t;罕用成员single_process 设置为true将为浏览器和渲染应用单过程。也可配置应用单个过程的命令行开关。browser_subprocess_path 子过程的单个执行体门路,multi_threaded_message_loop为true示意浏览器过程的音讯循环以单线程运行。command_line_args_idsabled为true示意禁用应用规范的CEF和Chrominum命令行参数的浏览器过程配置的个性。cache_path缓存数据保留在磁盘上,如果为空,内存缓存会被某些个性应用,长期磁盘缓存会被其余中央应用。如果不为空,如HTML5本地存储数据库会跨域。locale locale字符串会传递给blink,默认为en-USlog_file为debuglog文件门路log_severity日志等级resources_dir_path材料的目录门路。即cef.pak或devtools_resources.pak文件的保留门路locales_dir_pathlocales_dir_path locales的保留门路remote_debugging_port近程调试端口。范畴在1024~65535 ...

August 19, 2022 · 6 min · jiezi