diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index e2add8564e9c..c83a99c2b387 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -167,11 +167,14 @@ void AtomBrowserClient::RenderProcessWillLaunch( content::WebContents* web_contents = GetWebContentsFromProcessID(process_id); ProcessPreferences process_prefs; - process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents); - process_prefs.native_window_open - = WebContentsPreferences::UsesNativeWindowOpen(web_contents); - process_prefs.disable_popups - = WebContentsPreferences::DisablePopups(web_contents); + process_prefs.sandbox = + WebContentsPreferences::IsPreferenceEnabled("sandbox", web_contents); + process_prefs.native_window_open = + WebContentsPreferences::IsPreferenceEnabled("nativeWindowOpen", + web_contents); + process_prefs.disable_popups = + WebContentsPreferences::IsPreferenceEnabled("disablePopups", + web_contents); AddProcessPreferences(host->GetID(), process_prefs); // ensure the ProcessPreferences is removed later host->AddObserver(this); @@ -204,7 +207,7 @@ void AtomBrowserClient::OverrideWebkitPrefs( } void AtomBrowserClient::OverrideSiteInstanceForNavigation( - content::RenderFrameHost* render_frame_host, + content::RenderFrameHost* rfh, content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& url, @@ -214,8 +217,7 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation( return; } - if (!ShouldCreateNewSiteInstance(render_frame_host, browser_context, - current_instance, url)) + if (!ShouldCreateNewSiteInstance(rfh, browser_context, current_instance, url)) return; bool is_new_instance = true; @@ -223,10 +225,12 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation( // Do we have an affinity site to manage ? std::string affinity; - auto web_contents = - content::WebContents::FromRenderFrameHost(render_frame_host); - if (WebContentsPreferences::GetAffinity(web_contents, &affinity) - && !affinity.empty()) { + auto* web_contents = content::WebContents::FromRenderFrameHost(rfh); + auto* web_preferences = web_contents ? + WebContentsPreferences::FromWebContents(web_contents) : nullptr; + if (web_preferences && + web_preferences->web_preferences()->GetString("affinity", &affinity) && + !affinity.empty()) { affinity = base::ToLowerASCII(affinity); auto iter = site_per_affinities.find(affinity); if (iter != site_per_affinities.end()) { @@ -262,19 +266,6 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation( } } -// We are storing weak_ptr, is it fundamental to maintain the map up-to-date -// when an instance is destroyed. -void AtomBrowserClient::SiteInstanceDeleting( - content::SiteInstance* site_instance) { - for (auto iter = site_per_affinities.begin(); - iter != site_per_affinities.end(); ++iter) { - if (iter->second == site_instance) { - site_per_affinities.erase(iter); - break; - } - } -} - void AtomBrowserClient::AppendExtraCommandLineSwitches( base::CommandLine* command_line, int process_id) { @@ -436,6 +427,19 @@ void AtomBrowserClient::GetAdditionalAllowedSchemesForFileSystem( additional_schemes->push_back(content::kChromeDevToolsScheme); } +void AtomBrowserClient::SiteInstanceDeleting( + content::SiteInstance* site_instance) { + // We are storing weak_ptr, is it fundamental to maintain the map up-to-date + // when an instance is destroyed. + for (auto iter = site_per_affinities.begin(); + iter != site_per_affinities.end(); ++iter) { + if (iter->second == site_instance) { + site_per_affinities.erase(iter); + break; + } + } +} + brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts( const content::MainFunctionParams&) { v8::V8::Initialize(); // Init V8 before creating main parts. diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index 1e35d5c426fa..54ade8170a73 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -98,6 +98,7 @@ class AtomBrowserClient : public brightray::BrowserClient, bool* no_javascript_access) override; void GetAdditionalAllowedSchemesForFileSystem( std::vector* schemes) override; + void SiteInstanceDeleting(content::SiteInstance* site_instance) override; // brightray::BrowserClient: brightray::BrowserMainParts* OverrideCreateBrowserMainParts( @@ -113,17 +114,15 @@ class AtomBrowserClient : public brightray::BrowserClient, base::TerminationStatus status, int exit_code) override; - void SiteInstanceDeleting(content::SiteInstance* site_instance) override; - private: bool ShouldCreateNewSiteInstance(content::RenderFrameHost* render_frame_host, content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& dest_url); struct ProcessPreferences { - bool sandbox; - bool native_window_open; - bool disable_popups; + bool sandbox = false; + bool native_window_open = false; + bool disable_popups = false; }; void AddProcessPreferences(int process_id, ProcessPreferences prefs); void RemoveProcessPreferences(int process_id); diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.cc b/atom/browser/atom_resource_dispatcher_host_delegate.cc index 59f3909b5ce2..beca6c193541 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.cc +++ b/atom/browser/atom_resource_dispatcher_host_delegate.cc @@ -75,7 +75,7 @@ void OnPdfResourceIntercepted( if (!web_contents) return; - if (!WebContentsPreferences::IsPluginsEnabled(web_contents)) { + if (!WebContentsPreferences::IsPreferenceEnabled("plugins", web_contents)) { auto browser_context = web_contents->GetBrowserContext(); auto download_manager = content::BrowserContext::GetDownloadManager(browser_context); diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 85ccb47a5960..2cbf07be86a8 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -112,7 +112,8 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( // If the `sandbox` option was passed to the BrowserWindow's webPreferences, // pass `--enable-sandbox` to the renderer so it won't have any node.js // integration. - if (IsSandboxed(web_contents)) { + bool sandbox = false; + if (web_preferences.GetBoolean("sandbox", &sandbox) && sandbox) { command_line->AppendSwitch(switches::kEnableSandbox); } else if (!command_line->HasSwitch(switches::kEnableSandbox)) { command_line->AppendSwitch(::switches::kNoSandbox); @@ -237,47 +238,6 @@ bool WebContentsPreferences::IsPreferenceEnabled( return bool_value; } -bool WebContentsPreferences::GetPreferenceString( - const std::string& attribute_name, - content::WebContents* web_contents, - std::string* strValue) { - WebContentsPreferences* self; - if (!web_contents) - return false; - - self = FromWebContents(web_contents); - if (!self) - return false; - - base::DictionaryValue& web_preferences = self->web_preferences_; - return web_preferences.GetString(attribute_name, strValue); -} - -bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) { - return IsPreferenceEnabled("sandbox", web_contents); -} - -bool WebContentsPreferences::UsesNativeWindowOpen( - content::WebContents* web_contents) { - return IsPreferenceEnabled("nativeWindowOpen", web_contents); -} - -bool WebContentsPreferences::IsPluginsEnabled( - content::WebContents* web_contents) { - return IsPreferenceEnabled("plugins", web_contents); -} - -bool WebContentsPreferences::DisablePopups( - content::WebContents* web_contents) { - return IsPreferenceEnabled("disablePopups", web_contents); -} - -bool WebContentsPreferences::GetAffinity( - content::WebContents* web_contents, - std::string* string_value) { - return GetPreferenceString("affinity", web_contents, string_value); -} - // static void WebContentsPreferences::OverrideWebkitPrefs( content::WebContents* web_contents, content::WebPreferences* prefs) { diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 650e5bbdc587..94dd8dc598be 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -39,15 +39,6 @@ class WebContentsPreferences static bool IsPreferenceEnabled(const std::string& attribute_name, content::WebContents* web_contents); - static bool GetPreferenceString(const std::string& attribute_name, - content::WebContents* web_contents, - std::string* strValue); - static bool IsSandboxed(content::WebContents* web_contents); - static bool UsesNativeWindowOpen(content::WebContents* web_contents); - static bool DisablePopups(content::WebContents* web_contents); - static bool IsPluginsEnabled(content::WebContents* web_contents); - static bool GetAffinity(content::WebContents* web_contents, - std::string* string_value); // Modify the WebPreferences according to |web_contents|'s preferences. static void OverrideWebkitPrefs(