1 // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #include "tests/shared/browser/client_app_browser.h" 6 7 #include "include/base/cef_logging.h" 8 #include "include/cef_cookie.h" 9 #include "tests/shared/browser/main_message_loop_external_pump.h" 10 #include "tests/shared/common/client_switches.h" 11 12 namespace client { 13 ClientAppBrowser()14ClientAppBrowser::ClientAppBrowser() { 15 CreateDelegates(delegates_); 16 } 17 18 // static PopulateSettings(CefRefPtr<CefCommandLine> command_line,CefSettings & settings)19void ClientAppBrowser::PopulateSettings(CefRefPtr<CefCommandLine> command_line, 20 CefSettings& settings) { 21 #if (defined(OS_WIN) || defined(OS_LINUX)) 22 settings.multi_threaded_message_loop = 23 command_line->HasSwitch(client::switches::kMultiThreadedMessageLoop); 24 #endif 25 26 if (!settings.multi_threaded_message_loop) { 27 settings.external_message_pump = 28 command_line->HasSwitch(client::switches::kExternalMessagePump); 29 } 30 31 std::vector<std::string> cookieable_schemes; 32 RegisterCookieableSchemes(cookieable_schemes); 33 if (!cookieable_schemes.empty()) { 34 std::string list_str; 35 for (const auto& scheme : cookieable_schemes) { 36 if (!list_str.empty()) 37 list_str += ","; 38 list_str += scheme; 39 } 40 CefString(&settings.cookieable_schemes_list) = list_str; 41 } 42 } 43 OnBeforeCommandLineProcessing(const CefString & process_type,CefRefPtr<CefCommandLine> command_line)44void ClientAppBrowser::OnBeforeCommandLineProcessing( 45 const CefString& process_type, 46 CefRefPtr<CefCommandLine> command_line) { 47 // Pass additional command-line flags to the browser process. 48 if (process_type.empty()) { 49 // Pass additional command-line flags when off-screen rendering is enabled. 50 if (command_line->HasSwitch(switches::kOffScreenRenderingEnabled) && 51 !command_line->HasSwitch(switches::kSharedTextureEnabled)) { 52 // Use software rendering and compositing (disable GPU) for increased FPS 53 // and decreased CPU usage. This will also disable WebGL so remove these 54 // switches if you need that capability. 55 // See https://bitbucket.org/chromiumembedded/cef/issues/1257 for details. 56 if (!command_line->HasSwitch(switches::kEnableGPU)) { 57 command_line->AppendSwitch("disable-gpu"); 58 command_line->AppendSwitch("disable-gpu-compositing"); 59 } 60 } 61 62 if (command_line->HasSwitch(switches::kUseViews) && 63 !command_line->HasSwitch("top-chrome-md")) { 64 // Use non-material mode on all platforms by default. Among other things 65 // this causes menu buttons to show hover state. See usage of 66 // MaterialDesignController::IsModeMaterial() in Chromium code. 67 command_line->AppendSwitchWithValue("top-chrome-md", "non-material"); 68 } 69 70 if (!command_line->HasSwitch(switches::kCachePath) && 71 !command_line->HasSwitch("disable-gpu-shader-disk-cache")) { 72 // Don't create a "GPUCache" directory when cache-path is unspecified. 73 command_line->AppendSwitch("disable-gpu-shader-disk-cache"); 74 } 75 76 // Disable popup blocking for the chrome runtime. 77 command_line->AppendSwitch("disable-popup-blocking"); 78 79 #if defined(OS_MAC) 80 // Disable the toolchain prompt on macOS. 81 command_line->AppendSwitch("use-mock-keychain"); 82 #endif 83 84 DelegateSet::iterator it = delegates_.begin(); 85 for (; it != delegates_.end(); ++it) 86 (*it)->OnBeforeCommandLineProcessing(this, command_line); 87 } 88 } 89 OnContextInitialized()90void ClientAppBrowser::OnContextInitialized() { 91 DelegateSet::iterator it = delegates_.begin(); 92 for (; it != delegates_.end(); ++it) 93 (*it)->OnContextInitialized(this); 94 } 95 OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line)96void ClientAppBrowser::OnBeforeChildProcessLaunch( 97 CefRefPtr<CefCommandLine> command_line) { 98 DelegateSet::iterator it = delegates_.begin(); 99 for (; it != delegates_.end(); ++it) 100 (*it)->OnBeforeChildProcessLaunch(this, command_line); 101 } 102 OnScheduleMessagePumpWork(int64 delay)103void ClientAppBrowser::OnScheduleMessagePumpWork(int64 delay) { 104 // Only used when `--external-message-pump` is passed via the command-line. 105 MainMessageLoopExternalPump* message_pump = 106 MainMessageLoopExternalPump::Get(); 107 if (message_pump) 108 message_pump->OnScheduleMessagePumpWork(delay); 109 } 110 111 } // namespace client 112