BrowserApp.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "BrowserApp.h"
  2. #include "WPSchemeHandlerFactory.h"
  3. #include "WallpaperEngine/Application/WallpaperApplication.h"
  4. #include "WallpaperEngine/Logging/Log.h"
  5. #include "WallpaperEngine/WebBrowser/WebBrowserContext.h"
  6. using namespace WallpaperEngine::WebBrowser::CEF;
  7. BrowserApp::BrowserApp (WallpaperEngine::Application::WallpaperApplication& application) :
  8. SubprocessApp (application) { }
  9. CefRefPtr<CefBrowserProcessHandler> BrowserApp::GetBrowserProcessHandler () { return this; }
  10. void BrowserApp::OnContextInitialized () {
  11. // domain_name = nullptr matches every host under WPENGINE_SCHEME - the factory itself picks
  12. // the right wallpaper's project per request from the host (workshop id).
  13. CefRegisterSchemeHandlerFactory (
  14. WPENGINE_SCHEME, static_cast<const char*> (nullptr), new WPSchemeHandlerFactory (this->getApplication ())
  15. );
  16. }
  17. void BrowserApp::OnBeforeCommandLineProcessing (const CefString& process_type, CefRefPtr<CefCommandLine> command_line) {
  18. command_line->AppendSwitchWithValue (
  19. "--disable-features",
  20. "IsolateOrigins,HardwareMediaKeyHandling,WebContentsOcclusion,RendererCodeIntegrityEnabled,site-per-process"
  21. );
  22. command_line->AppendSwitch ("--disable-gpu-shader-disk-cache");
  23. // no keyring is ever needed, and without this every process tries (and fails) to reach kwalletd
  24. command_line->AppendSwitchWithValue ("--password-store", "basic");
  25. command_line->AppendSwitch ("--disable-site-isolation-trials");
  26. command_line->AppendSwitch ("--disable-web-security");
  27. command_line->AppendSwitchWithValue ("--remote-allow-origins", "*");
  28. command_line->AppendSwitchWithValue ("--autoplay-policy", "no-user-gesture-required");
  29. command_line->AppendSwitch ("--disable-background-timer-throttling");
  30. command_line->AppendSwitch ("--disable-backgrounding-occluded-windows");
  31. command_line->AppendSwitch ("--disable-background-media-suspend");
  32. command_line->AppendSwitch ("--disable-renderer-backgrounding");
  33. command_line->AppendSwitch ("--disable-test-root-certs");
  34. command_line->AppendSwitch ("--disable-bundled-ppapi-flash");
  35. command_line->AppendSwitch ("--disable-breakpad");
  36. command_line->AppendSwitch ("--disable-field-trial-config");
  37. command_line->AppendSwitch ("--no-experiments");
  38. // TODO: activate mock-keychain switch for process_type.empty() if we ever support macOS
  39. }
  40. void BrowserApp::OnBeforeChildProcessLaunch (CefRefPtr<CefCommandLine> command_line) {
  41. // add back any parameters we had before so the new process can load up everything needed
  42. for (int i = 1; i < this->getApplication ().getContext ().getArgc (); i++) {
  43. command_line->AppendArgument (this->getApplication ().getContext ().getArgv ()[i]);
  44. }
  45. // The "background id" positional above is only the launch-time value - without this, a
  46. // subprocess spawned after a hotswap would resolve the wrong (or no) project for its
  47. // scheme handler lookups.
  48. const auto& currentBackground = this->getApplication ().getContext ().settings.general.defaultBackground;
  49. if (!currentBackground.empty ()) {
  50. command_line->AppendSwitchWithValue ("--current-background", currentBackground.string ());
  51. }
  52. }