#include "include/cef_client.h" #include "client_renderer_app.h" #if defined DEBUG || defined _DEBUG const char kSubProcess[] = "mbcsubprocess.exe"; #else const char kSubProcess[] = "mbcsubprocess.exe"; #endif void RenderProcessClientApp::OnBeforeCommandLineProcessing( const CefString& process_type, CefRefPtr command_line) { // Pass additional command-line flags to the browser process. if (process_type.empty()) { // Pass additional command-line flags when off-screen rendering is enabled. // If the PDF extension is enabled then cc Surfaces must be disabled for // PDFs to render correctly. // See https://bitbucket.org/chromiumembedded/cef/issues/1689 for details. if (!command_line->HasSwitch("disable-extensions") && !command_line->HasSwitch("disable-pdf-extension")) { command_line->AppendSwitch("disable-surfaces"); } // Use software rendering and compositing (disable GPU) for increased FPS // and decreased CPU usage. This will also disable WebGL so remove these // switches if you need that capability. // See https://bitbucket.org/chromiumembedded/cef/issues/1257 for details. command_line->AppendSwitch("disable-gpu"); command_line->AppendSwitch("disable-gpu-compositing"); // Synchronize the frame rate between all processes. This results in // decreased CPU usage by avoiding the generation of extra frames that // would otherwise be discarded. The frame rate can be set at browser // creation time via CefBrowserSettings.windowless_frame_rate or changed // dynamically using CefBrowserHost::SetWindowlessFrameRate. In cefclient // it can be set via the command-line using `--off-screen-frame-rate=XX`. // See https://bitbucket.org/chromiumembedded/cef/issues/1368 for details. command_line->AppendSwitch("enable-begin-frame-scheduling"); command_line->AppendSwitch("--ignore-certificate-errors"); command_line->AppendSwitch("--no-proxy-server"); // ´Ë²ÎÊý½â¾ö¶à´°¿ÚÎÊÌâ command_line->AppendSwitch("process-per-site"); //command_line->AppendSwitch("enable-npapi"); //command_line->AppendSwitchWithValue("register-pepper-plugins", "PepperFlash/pepflashplayer.dll;application/x-shockwave-flash"); command_line->AppendSwitchWithValue("--force-device-scale-factor","1"); //command_line->AppendSwitchWithValue("ppapi-flash-version", "22.0.0.209");//PepperFlash\manifest.jsonÖеÄversion //command_line->AppendSwitchWithValue("ppapi-flash-path", "PepperFlash\\pepflashplayer.dll"); command_line->AppendSwitchWithValue("--renderer-process-limit", "1"); command_line->AppendSwitchWithValue("--browser-subprocess-path", kSubProcess); } } CefRefPtr& RenderProcessClientApp::Instance() { static CefRefPtr pApp; if (pApp == NULL) { pApp = new RenderProcessClientApp(); } return pApp; } void RenderProcessClientApp::OnWebKitInitialized() { std::string app_code = //----------------------------------- //ÉùÃ÷JavaScriptÀïÒªµ÷ÓõÄCpp·½·¨ "var mbcapp;" "if (!mbcapp)" " mbcapp = {};" "(function() {" // jsInvokeCPlusPlus " mbcapp.GetBackUrl = function() {" " native function GetBackUrl();" " return GetBackUrl();" " };" "})();"; /* FILE *fp = fopen("D://1.txt", "a+"); fseek(fp, 0, SEEK_END); char sz_add[] = "OnWebKitInitialized\n"; fwrite(sz_add, strlen(sz_add), 1, fp); fclose(fp);*/ // Register app extension module // JavaScriptÀïµ÷ÓÃapp.jsInvokeCPlusPlusʱ£¬¾Í»áȥͨ¹ýCefRegisterExtension×¢²áµÄCefV8HandlerÁбíÀï²éÕÒ // ÕÒµ½"v8/app"¶ÔÓ¦µÄCCEFV8HandlerEx£¬¾Íµ÷ÓÃËüµÄExecute·½·¨ // ¼ÙÉèv8Handler_ÊÇCCefClientAppµÄÒ»¸ö³ÉÔ±±äÁ¿ //v8Handler_ = new CCEFV8HandlerEx(); CefRegisterExtension("v8/app", app_code, v8Handler_); } void RenderProcessClientApp::OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) { /*FILE *fp = fopen("1.txt", "a+"); fseek(fp, 0, SEEK_END); char sz_add[] = "OnContextCreated\n"; fwrite(sz_add, strlen(sz_add), 1, fp); fclose(fp);*/ CefRefPtr object = context->GetGlobal();// »ñÈ¡µ½window CefRefPtr str = CefV8Value::CreateString("C++ created Value!"); object->SetValue("jsValue", str, V8_PROPERTY_ATTRIBUTE_NONE); /*CefRefPtr accessor = new MyV8Accessor; CefRefPtr obj = CefV8Value::CreateObject(accessor); obj->SetValue("myval", V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE); object->SetValue("myobject", obj, V8_PROPERTY_ATTRIBUTE_NONE);*/ } void RenderProcessClientApp::OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) { v8Handler_ = nullptr; } void RenderProcessClientApp::OnFocusedNodeChanged(CefRefPtr browser, CefRefPtr frame, CefRefPtr node) { //if(node) { // node->IsFormControlElement(); // std::string strNode = node->GetFormControlElementType().ToString() + " " + node->GetName().ToString() +" /n"; // // FILE *fp = fopen("D://1.txt", "a+"); // fseek(fp, 0, SEEK_END); // fwrite(strNode.c_str(), strNode.length(), 1, fp); // fclose(fp); // } } void RenderProcessClientApp::OnUncaughtException(CefRefPtr browser, CefRefPtr frame, CefRefPtr context, CefRefPtr exception, CefRefPtr stackTrace) { } bool RenderProcessClientApp::OnProcessMessageReceived( CefRefPtr browser, CefProcessId source_process, CefRefPtr message) { if (message->GetName() == _T("func_backurl")) { CefRefPtr argList = message->GetArgumentList(); CefString cefURL = argList->GetString(0); if( v8Handler_ != NULL ) { v8Handler_->GetUrlMgr()->AddUrl(cefURL); } } /*FILE *fp = fopen("D://1.txt", "a+"); fseek(fp, 0, SEEK_END); char sz_add[] = "OnProcessMessageReceived\n"; fwrite(sz_add, strlen(sz_add), 1, fp); fclose(fp);*/ return true; }