From 97727779197b4100b611d3718f47dee0f52afdda Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 8 Mar 2018 16:05:12 +0900 Subject: [PATCH 1/7] web_prefrences() => dict() Having property name being the same with class name is making code harder to understand, and dict is much shorter. --- atom/browser/api/atom_api_browser_window.cc | 5 ++- atom/browser/api/atom_api_web_contents.cc | 8 ++--- atom/browser/atom_browser_client.cc | 2 +- atom/browser/native_window_views.cc | 2 +- atom/browser/web_contents_preferences.cc | 39 ++++++++++++--------- atom/browser/web_contents_preferences.h | 14 ++++---- 6 files changed, 38 insertions(+), 32 deletions(-) diff --git a/atom/browser/api/atom_api_browser_window.cc b/atom/browser/api/atom_api_browser_window.cc index 362ca1ac9d89..3607077b69c2 100644 --- a/atom/browser/api/atom_api_browser_window.cc +++ b/atom/browser/api/atom_api_browser_window.cc @@ -118,11 +118,10 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate, WebContentsPreferences::FromWebContents(web_contents->web_contents()); base::DictionaryValue web_preferences_dict; if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(), - &web_preferences_dict)) { - existing_preferences->web_preferences()->Clear(); + &web_preferences_dict)) { + existing_preferences->dict()->Clear(); existing_preferences->Merge(web_preferences_dict); } - } else { // Creates the WebContents used by BrowserWindow. web_contents = WebContents::Create(isolate, web_preferences); diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 695ac4346cd6..a3db5dbd19e0 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1125,8 +1125,8 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { WebContentsPreferences* web_preferences = WebContentsPreferences::FromWebContents(web_contents()); std::string color_name; - if (web_preferences->web_preferences()->GetString(options::kBackgroundColor, - &color_name)) { + if (web_preferences->dict()->GetString(options::kBackgroundColor, + &color_name)) { view->SetBackgroundColor(ParseHexColor(color_name)); } else { view->SetBackgroundColor(SK_ColorTRANSPARENT); @@ -1844,7 +1844,7 @@ v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { WebContentsPreferences::FromWebContents(web_contents()); if (!web_preferences) return v8::Null(isolate); - return mate::ConvertToV8(isolate, *web_preferences->web_preferences()); + return mate::ConvertToV8(isolate, *web_preferences->dict()); } v8::Local WebContents::GetLastWebPreferences(v8::Isolate* isolate) { @@ -1852,7 +1852,7 @@ v8::Local WebContents::GetLastWebPreferences(v8::Isolate* isolate) { WebContentsPreferences::FromWebContents(web_contents()); if (!web_preferences) return v8::Null(isolate); - return mate::ConvertToV8(isolate, *web_preferences->last_web_preferences()); + return mate::ConvertToV8(isolate, *web_preferences->last_dict()); } v8::Local WebContents::GetOwnerBrowserWindow() { diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 5dbde2a0d4ab..d7c6857c7f7f 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -238,7 +238,7 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation( auto* web_preferences = web_contents ? WebContentsPreferences::FromWebContents(web_contents) : nullptr; if (web_preferences && - web_preferences->web_preferences()->GetString("affinity", &affinity) && + web_preferences->dict()->GetString("affinity", &affinity) && !affinity.empty()) { affinity = base::ToLowerASCII(affinity); auto iter = site_per_affinities.find(affinity); diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index c40cc025c010..5bb9fe65ed2f 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -1373,7 +1373,7 @@ void NativeWindowViews::ShowAutofillPopup( auto* web_contents_preferences = WebContentsPreferences::FromWebContents(web_contents); if (web_contents_preferences) { - const auto* web_preferences = web_contents_preferences->web_preferences(); + const auto* web_preferences = web_contents_preferences->dict(); web_preferences->GetBoolean("offscreen", &is_offsceen); int guest_instance_id = 0; diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 6b912469f89e..8b0b6bc9a641 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -45,7 +45,7 @@ WebContentsPreferences::WebContentsPreferences( copied.Delete("isGuest"); copied.Delete("session"); - mate::ConvertFromV8(isolate, copied.GetHandle(), &web_preferences_); + mate::ConvertFromV8(isolate, copied.GetHandle(), &dict_); web_contents->SetUserData(UserDataKey(), base::WrapUnique(this)); instances_.push_back(this); @@ -70,7 +70,8 @@ WebContentsPreferences::WebContentsPreferences( SetDefaultBoolIfUndefined(options::kScrollBounce, false); #endif SetDefaultBoolIfUndefined("offscreen", false); - last_web_preferences_.MergeDictionary(&web_preferences_); + + last_dict_.MergeDictionary(&web_preferences_); } WebContentsPreferences::~WebContentsPreferences() { @@ -90,7 +91,7 @@ bool WebContentsPreferences::SetDefaultBoolIfUndefined(const std::string key, } void WebContentsPreferences::Merge(const base::DictionaryValue& extend) { - web_preferences_.MergeDictionary(&extend); + dict_.MergeDictionary(&extend); } // static @@ -111,13 +112,13 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( if (!self) return; - base::DictionaryValue& web_preferences = self->web_preferences_; + base::DictionaryValue& web_preferences = self->dict_; // We are appending args to a webContents so let's save the current state // of our preferences object so that during the lifetime of the WebContents // we can fetch the options used to initally configure the WebContents - self->last_web_preferences_.Clear(); - self->last_web_preferences_.MergeDictionary(&web_preferences); + self->last_dict_.Clear(); + self->last_dict_.MergeDictionary(&web_preferences); bool b; // Check if plugins are enabled. @@ -274,7 +275,7 @@ bool WebContentsPreferences::IsPreferenceEnabled( if (!self) return false; - base::DictionaryValue& web_preferences = self->web_preferences_; + base::DictionaryValue& web_preferences = self->dict_; bool bool_value = false; web_preferences.GetBoolean(attribute_name, &bool_value); return bool_value; @@ -288,24 +289,30 @@ void WebContentsPreferences::OverrideWebkitPrefs( return; bool b; - if (self->web_preferences_.GetBoolean("javascript", &b)) + if (self->dict_.GetBoolean("javascript", &b)) prefs->javascript_enabled = b; - if (self->web_preferences_.GetBoolean("images", &b)) + if (self->dict_.GetBoolean("images", &b)) prefs->images_enabled = b; - if (self->web_preferences_.GetBoolean("textAreasAreResizable", &b)) + if (self->dict_.GetBoolean("textAreasAreResizable", &b)) prefs->text_areas_are_resizable = b; +<<<<<<< HEAD if (self->web_preferences_.GetBoolean("webgl", &b)) { prefs->webgl1_enabled = b; prefs->webgl2_enabled = b; } if (self->web_preferences_.GetBoolean("webSecurity", &b)) { +======= + if (self->dict_.GetBoolean("webgl", &b)) + prefs->experimental_webgl_enabled = b; + if (self->dict_.GetBoolean("webSecurity", &b)) { +>>>>>>> web_prefrences() => dict() prefs->web_security_enabled = b; prefs->allow_running_insecure_content = !b; } - if (self->web_preferences_.GetBoolean("allowRunningInsecureContent", &b)) + if (self->dict_.GetBoolean("allowRunningInsecureContent", &b)) prefs->allow_running_insecure_content = b; const base::DictionaryValue* fonts = nullptr; - if (self->web_preferences_.GetDictionary("defaultFontFamily", &fonts)) { + if (self->dict_.GetDictionary("defaultFontFamily", &fonts)) { base::string16 font; if (fonts->GetString("standard", &font)) prefs->standard_font_family_map[content::kCommonScript] = font; @@ -328,18 +335,18 @@ void WebContentsPreferences::OverrideWebkitPrefs( if (self->GetInteger("minimumFontSize", &size)) prefs->minimum_font_size = size; std::string encoding; - if (self->web_preferences_.GetString("defaultEncoding", &encoding)) + if (self->dict_.GetString("defaultEncoding", &encoding)) prefs->default_encoding = encoding; } bool WebContentsPreferences::GetInteger(const std::string& attributeName, int* intValue) { // if it is already an integer, no conversion needed - if (web_preferences_.GetInteger(attributeName, intValue)) + if (dict_.GetInteger(attributeName, intValue)) return true; base::string16 stringValue; - if (web_preferences_.GetString(attributeName, &stringValue)) + if (dict_.GetString(attributeName, &stringValue)) return base::StringToInt(stringValue, intValue); return false; @@ -351,7 +358,7 @@ bool WebContentsPreferences::GetString(const std::string& attribute_name, WebContentsPreferences* self = FromWebContents(web_contents); if (!self) return false; - return self->web_preferences()->GetString(attribute_name, string_value); + return self->dict()->GetString(attribute_name, string_value); } } // namespace atom diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index b7174525a4f7..7493523e0272 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -52,14 +52,13 @@ class WebContentsPreferences const mate::Dictionary& web_preferences); ~WebContentsPreferences() override; - // $.extend(|web_preferences_|, |new_web_preferences|). + // $.extend(|web_preferences|, |new_web_preferences|). void Merge(const base::DictionaryValue& new_web_preferences); // Returns the web preferences. - base::DictionaryValue* web_preferences() { return &web_preferences_; } - base::DictionaryValue* last_web_preferences() { - return &last_web_preferences_; - } + base::DictionaryValue* dict() { return &dict_; } + const base::DictionaryValue* dict() const { return &dict_; } + base::DictionaryValue* last_dict() { return &last_dict_; } private: friend class content::WebContentsUserData; @@ -73,8 +72,9 @@ class WebContentsPreferences static std::vector instances_; content::WebContents* web_contents_; - base::DictionaryValue web_preferences_; - base::DictionaryValue last_web_preferences_; + + base::DictionaryValue dict_; + base::DictionaryValue last_dict_; DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences); }; From 887bc123505d35a04a4aea545c81731c034a6982 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 8 Mar 2018 16:12:45 +0900 Subject: [PATCH 2/7] Add WebContentsPreferences::From that checks parameter --- atom/browser/api/atom_api_browser_window.cc | 2 +- atom/browser/api/atom_api_web_contents.cc | 6 ++---- atom/browser/api/atom_api_web_view_manager.cc | 2 +- atom/browser/atom_browser_client.cc | 3 +-- atom/browser/native_window_views.cc | 12 +++++------- atom/browser/web_contents_preferences.cc | 8 ++++++++ atom/browser/web_contents_preferences.h | 3 +++ 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/atom/browser/api/atom_api_browser_window.cc b/atom/browser/api/atom_api_browser_window.cc index 3607077b69c2..33695d5ef293 100644 --- a/atom/browser/api/atom_api_browser_window.cc +++ b/atom/browser/api/atom_api_browser_window.cc @@ -115,7 +115,7 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate, // These preferences will be used when the webContent launches new // render processes. auto* existing_preferences = - WebContentsPreferences::FromWebContents(web_contents->web_contents()); + WebContentsPreferences::From(web_contents->web_contents()); base::DictionaryValue web_preferences_dict; if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(), &web_preferences_dict)) { diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index a3db5dbd19e0..d702a8e5a131 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1122,8 +1122,7 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { // created after loading a page. const auto view = web_contents()->GetRenderWidgetHostView(); if (view) { - WebContentsPreferences* web_preferences = - WebContentsPreferences::FromWebContents(web_contents()); + auto* web_preferences = WebContentsPreferences::From(web_contents()); std::string color_name; if (web_preferences->dict()->GetString(options::kBackgroundColor, &color_name)) { @@ -1840,8 +1839,7 @@ void WebContents::OnGetZoomLevel(content::RenderFrameHost* rfh, } v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { - WebContentsPreferences* web_preferences = - WebContentsPreferences::FromWebContents(web_contents()); + auto* web_preferences = WebContentsPreferences::From(web_contents()); if (!web_preferences) return v8::Null(isolate); return mate::ConvertToV8(isolate, *web_preferences->dict()); diff --git a/atom/browser/api/atom_api_web_view_manager.cc b/atom/browser/api/atom_api_web_view_manager.cc index 2a0cbd8a3ebf..347bcc2336bc 100644 --- a/atom/browser/api/atom_api_web_view_manager.cc +++ b/atom/browser/api/atom_api_web_view_manager.cc @@ -34,7 +34,7 @@ void AddGuest(int guest_instance_id, ->SetDefaultZoomFactor(zoom_factor); } - WebContentsPreferences::FromWebContents(guest_web_contents)->Merge(options); + WebContentsPreferences::From(guest_web_contents)->Merge(options); } void RemoveGuest(content::WebContents* embedder, int guest_instance_id) { diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index d7c6857c7f7f..f96f3ce6d31f 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -235,8 +235,7 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation( // Do we have an affinity site to manage ? std::string affinity; auto* web_contents = content::WebContents::FromRenderFrameHost(rfh); - auto* web_preferences = web_contents ? - WebContentsPreferences::FromWebContents(web_contents) : nullptr; + auto* web_preferences = WebContentsPreferences::From(web_contents); if (web_preferences && web_preferences->dict()->GetString("affinity", &affinity) && !affinity.empty()) { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 5bb9fe65ed2f..c824d0a76d1c 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -1370,14 +1370,12 @@ void NativeWindowViews::ShowAutofillPopup( bool is_offsceen = false; bool is_embedder_offscreen = false; - auto* web_contents_preferences = - WebContentsPreferences::FromWebContents(web_contents); - if (web_contents_preferences) { - const auto* web_preferences = web_contents_preferences->dict(); - - web_preferences->GetBoolean("offscreen", &is_offsceen); + auto* web_preferences = WebContentsPreferences::From(web_contents); + if (web_preferences) { + web_preferences->dict()->GetBoolean("offscreen", &is_offsceen); int guest_instance_id = 0; - web_preferences->GetInteger(options::kGuestInstanceID, &guest_instance_id); + web_preferences->dict()->GetInteger(options::kGuestInstanceID, + &guest_instance_id); if (guest_instance_id) { auto manager = WebViewManager::GetWebViewManager(web_contents); diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 8b0b6bc9a641..e45a6167c99b 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -105,6 +105,14 @@ content::WebContents* WebContentsPreferences::GetWebContentsFromProcessID( return nullptr; } +// static +WebContentsPreferences* WebContentsPreferences::From( + content::WebContents* web_contents) { + if (!web_contents) + return nullptr; + return FromWebContents(web_contents); +} + // static void WebContentsPreferences::AppendExtraCommandLineSwitches( content::WebContents* web_contents, base::CommandLine* command_line) { diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 7493523e0272..50165bbc43e3 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -33,6 +33,9 @@ class WebContentsPreferences // FIXME(zcbenz): This method does not belong here. static content::WebContents* GetWebContentsFromProcessID(int process_id); + // Get self from WebContents. + static WebContentsPreferences* From(content::WebContents* web_contents); + // Append command paramters according to |web_contents|'s preferences. static void AppendExtraCommandLineSwitches( content::WebContents* web_contents, base::CommandLine* command_line); From 3d47a8a2fd0bda657ad297f85282137c8dd622f0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 8 Mar 2018 16:36:21 +0900 Subject: [PATCH 3/7] Remove the static getter methods from WebContentsPreferences --- atom/browser/atom_browser_client.cc | 19 +++--- atom/browser/atom_browser_client.h | 9 +-- .../browser/atom_javascript_dialog_manager.cc | 16 ++--- .../atom_resource_dispatcher_host_delegate.cc | 7 +- atom/browser/native_window_views.cc | 9 +-- atom/browser/web_contents_preferences.cc | 66 +++++++------------ atom/browser/web_contents_preferences.h | 16 ++--- 7 files changed, 60 insertions(+), 82 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index f96f3ce6d31f..5a6aa19a56e7 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -173,17 +173,14 @@ void AtomBrowserClient::RenderProcessWillLaunch( host->AddFilter( new WidevineCdmMessageFilter(process_id, host->GetBrowserContext())); - content::WebContents* web_contents = GetWebContentsFromProcessID(process_id); - ProcessPreferences process_prefs; - 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); + ProcessPreferences prefs; + auto* web_preferences = WebContentsPreferences::From(process_id); + if (web_preferences) { + prefs.sandbox = web_preferences->IsEnabled("sandbox"); + prefs.native_window_open = web_preferences->IsEnabled("nativeWindowOpen"); + prefs.disable_popups = web_preferences->IsEnabled("disablePopups"); + } + AddProcessPreferences(host->GetID(), prefs); // ensure the ProcessPreferences is removed later host->AddObserver(this); } diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index ceacd354ab3d..38b412dc6de1 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -118,15 +118,16 @@ class AtomBrowserClient : public brightray::BrowserClient, int exit_code) 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 = false; bool native_window_open = false; bool disable_popups = false; }; + + bool ShouldCreateNewSiteInstance(content::RenderFrameHost* render_frame_host, + content::BrowserContext* browser_context, + content::SiteInstance* current_instance, + const GURL& dest_url); void AddProcessPreferences(int process_id, ProcessPreferences prefs); void RemoveProcessPreferences(int process_id); bool IsProcessObserved(int process_id); diff --git a/atom/browser/atom_javascript_dialog_manager.cc b/atom/browser/atom_javascript_dialog_manager.cc index 8e80e58a94c6..16eab2989dbf 100644 --- a/atom/browser/atom_javascript_dialog_manager.cc +++ b/atom/browser/atom_javascript_dialog_manager.cc @@ -55,13 +55,13 @@ void AtomJavaScriptDialogManager::RunJavaScriptDialog( origin_counts_[origin]++; - std::string checkbox_string; - if (origin_counts_[origin] > 1 && - WebContentsPreferences::IsPreferenceEnabled("safeDialogs", - web_contents)) { - if (!WebContentsPreferences::GetString("safeDialogsMessage", - &checkbox_string, web_contents)) { - checkbox_string = "Prevent this app from creating additional dialogs"; + std::string checkbox; + if (origin_counts_[origin] > 1) { + auto* web_preferences = WebContentsPreferences::From(web_contents); + if (web_preferences && + web_preferences->IsEnabled("safeDialogs") && + !web_preferences->dict()->GetString("safeDialogsMessage", &checkbox)) { + checkbox = "Prevent this app from creating additional dialogs"; } } @@ -70,7 +70,7 @@ void AtomJavaScriptDialogManager::RunJavaScriptDialog( relay ? relay->window.get() : nullptr, atom::MessageBoxType::MESSAGE_BOX_TYPE_NONE, buttons, -1, 0, atom::MessageBoxOptions::MESSAGE_BOX_NONE, "", - base::UTF16ToUTF8(message_text), "", checkbox_string, + base::UTF16ToUTF8(message_text), "", checkbox, false, gfx::ImageSkia(), base::Bind(&AtomJavaScriptDialogManager::OnMessageBoxCallback, base::Unretained(this), diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.cc b/atom/browser/atom_resource_dispatcher_host_delegate.cc index d53adc9446ee..046f6e45f583 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.cc +++ b/atom/browser/atom_resource_dispatcher_host_delegate.cc @@ -80,9 +80,10 @@ void OnPdfResourceIntercepted( if (!web_contents) return; - if (!WebContentsPreferences::IsPreferenceEnabled("plugins", web_contents)) { - auto browser_context = web_contents->GetBrowserContext(); - auto download_manager = + auto* web_preferences = WebContentsPreferences::From(web_contents); + if (!web_preferences || !web_preferences->IsEnabled("plugins")) { + auto* browser_context = web_contents->GetBrowserContext(); + auto* download_manager = content::BrowserContext::GetDownloadManager(browser_context); download_manager->DownloadUrl( diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index c824d0a76d1c..602bb01b665a 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -1378,12 +1378,13 @@ void NativeWindowViews::ShowAutofillPopup( &guest_instance_id); if (guest_instance_id) { - auto manager = WebViewManager::GetWebViewManager(web_contents); + auto* manager = WebViewManager::GetWebViewManager(web_contents); if (manager) { - auto embedder = manager->GetEmbedder(guest_instance_id); + auto* embedder = manager->GetEmbedder(guest_instance_id); if (embedder) { - is_embedder_offscreen = WebContentsPreferences::IsPreferenceEnabled( - "offscreen", embedder); + auto* embedder_prefs = WebContentsPreferences::From(embedder); + is_embedder_offscreen = embedder_prefs && + embedder_prefs->IsEnabled("offscreen"); } } } diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index e45a6167c99b..02bea454fb91 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -80,16 +80,23 @@ WebContentsPreferences::~WebContentsPreferences() { instances_.end()); } -bool WebContentsPreferences::SetDefaultBoolIfUndefined(const std::string key, - bool val) { +bool WebContentsPreferences::SetDefaultBoolIfUndefined( + const base::StringPiece& key, bool val) { bool existing; - if (!web_preferences_.GetBoolean(key, &existing)) { - web_preferences_.SetBoolean(key, val); + if (!dict_.GetBoolean(key, &existing)) { + dict_.SetBoolean(key, val); return val; } return existing; } +bool WebContentsPreferences::IsEnabled(const base::StringPiece& name, + bool default_value) { + bool bool_value = default_value; + dict_.GetBoolean(name, &bool_value); + return bool_value; +} + void WebContentsPreferences::Merge(const base::DictionaryValue& extend) { dict_.MergeDictionary(&extend); } @@ -113,6 +120,11 @@ WebContentsPreferences* WebContentsPreferences::From( return FromWebContents(web_contents); } +// static +WebContentsPreferences* WebContentsPreferences::From(int process_id) { + return From(GetWebContentsFromProcessID(process_id)); +} + // static void WebContentsPreferences::AppendExtraCommandLineSwitches( content::WebContents* web_contents, base::CommandLine* command_line) { @@ -272,23 +284,6 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( } } -bool WebContentsPreferences::IsPreferenceEnabled( - const std::string& attribute_name, - content::WebContents* web_contents) { - WebContentsPreferences* self; - if (!web_contents) - return false; - - self = FromWebContents(web_contents); - if (!self) - return false; - - base::DictionaryValue& web_preferences = self->dict_; - bool bool_value = false; - web_preferences.GetBoolean(attribute_name, &bool_value); - return bool_value; -} - // static void WebContentsPreferences::OverrideWebkitPrefs( content::WebContents* web_contents, content::WebPreferences* prefs) { @@ -303,17 +298,11 @@ void WebContentsPreferences::OverrideWebkitPrefs( prefs->images_enabled = b; if (self->dict_.GetBoolean("textAreasAreResizable", &b)) prefs->text_areas_are_resizable = b; -<<<<<<< HEAD - if (self->web_preferences_.GetBoolean("webgl", &b)) { + if (self->dict_.GetBoolean("webgl", &b)) { prefs->webgl1_enabled = b; prefs->webgl2_enabled = b; } - if (self->web_preferences_.GetBoolean("webSecurity", &b)) { -======= - if (self->dict_.GetBoolean("webgl", &b)) - prefs->experimental_webgl_enabled = b; if (self->dict_.GetBoolean("webSecurity", &b)) { ->>>>>>> web_prefrences() => dict() prefs->web_security_enabled = b; prefs->allow_running_insecure_content = !b; } @@ -347,26 +336,17 @@ void WebContentsPreferences::OverrideWebkitPrefs( prefs->default_encoding = encoding; } -bool WebContentsPreferences::GetInteger(const std::string& attributeName, - int* intValue) { +bool WebContentsPreferences::GetInteger(const base::StringPiece& attribute_name, + int* val) { // if it is already an integer, no conversion needed - if (dict_.GetInteger(attributeName, intValue)) + if (dict_.GetInteger(attribute_name, val)) return true; - base::string16 stringValue; - if (dict_.GetString(attributeName, &stringValue)) - return base::StringToInt(stringValue, intValue); + std::string str; + if (dict_.GetString(attribute_name, &str)) + return base::StringToInt(str, val); return false; } -bool WebContentsPreferences::GetString(const std::string& attribute_name, - std::string* string_value, - content::WebContents* web_contents) { - WebContentsPreferences* self = FromWebContents(web_contents); - if (!self) - return false; - return self->dict()->GetString(attribute_name, string_value); -} - } // namespace atom diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 50165bbc43e3..ab2837d983d4 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -35,18 +35,13 @@ class WebContentsPreferences // Get self from WebContents. static WebContentsPreferences* From(content::WebContents* web_contents); + // Get self from procese ID. + static WebContentsPreferences* From(int process_id); // Append command paramters according to |web_contents|'s preferences. static void AppendExtraCommandLineSwitches( content::WebContents* web_contents, base::CommandLine* command_line); - static bool IsPreferenceEnabled(const std::string& attribute_name, - content::WebContents* web_contents); - - static bool GetString(const std::string& attribute_name, - std::string* string_value, - content::WebContents* web_contents); - // Modify the WebPreferences according to |web_contents|'s preferences. static void OverrideWebkitPrefs( content::WebContents* web_contents, content::WebPreferences* prefs); @@ -55,6 +50,9 @@ class WebContentsPreferences const mate::Dictionary& web_preferences); ~WebContentsPreferences() override; + // A simple way to know whether a Boolean property is enabled. + bool IsEnabled(const base::StringPiece& name, bool default_value = false); + // $.extend(|web_preferences|, |new_web_preferences|). void Merge(const base::DictionaryValue& new_web_preferences); @@ -67,10 +65,10 @@ class WebContentsPreferences friend class content::WebContentsUserData; // Set preference value to given bool if user did not provide value - bool SetDefaultBoolIfUndefined(const std::string key, bool val); + bool SetDefaultBoolIfUndefined(const base::StringPiece& key, bool val); // Get preferences value as integer possibly coercing it from a string - bool GetInteger(const std::string& attributeName, int* intValue); + bool GetInteger(const base::StringPiece& attribute_name, int* val); static std::vector instances_; From 001275339b4a26004b85e76d1bb10b5c693d45d9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 8 Mar 2018 16:45:37 +0900 Subject: [PATCH 4/7] Hide WebContentPreferences::GetWebContentsFromProcessID from public --- atom/browser/atom_permission_manager.cc | 10 ++++++---- atom/browser/web_contents_preferences.h | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/atom/browser/atom_permission_manager.cc b/atom/browser/atom_permission_manager.cc index 88b31debee9d..e3e9c94ce96e 100644 --- a/atom/browser/atom_permission_manager.cc +++ b/atom/browser/atom_permission_manager.cc @@ -6,6 +6,7 @@ #include +#include "atom/browser/atom_browser_client.h" #include "atom/browser/web_contents_preferences.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/permission_type.h" @@ -19,11 +20,12 @@ namespace atom { namespace { bool WebContentsDestroyed(int process_id) { - auto contents = - WebContentsPreferences::GetWebContentsFromProcessID(process_id); - if (!contents) + content::WebContents* web_contents = + static_cast(AtomBrowserClient::Get())-> + GetWebContentsFromProcessID(process_id); + if (!web_contents) return true; - return contents->IsBeingDestroyed(); + return web_contents->IsBeingDestroyed(); } void PermissionRequestResponseCallbackWrapper( diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index ab2837d983d4..1ab2c7ab3e19 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -29,10 +29,6 @@ namespace atom { class WebContentsPreferences : public content::WebContentsUserData { public: - // Get WebContents according to process ID. - // FIXME(zcbenz): This method does not belong here. - static content::WebContents* GetWebContentsFromProcessID(int process_id); - // Get self from WebContents. static WebContentsPreferences* From(content::WebContents* web_contents); // Get self from procese ID. @@ -63,6 +59,10 @@ class WebContentsPreferences private: friend class content::WebContentsUserData; + friend class AtomBrowserClient; + + // Get WebContents according to process ID. + static content::WebContents* GetWebContentsFromProcessID(int process_id); // Set preference value to given bool if user did not provide value bool SetDefaultBoolIfUndefined(const base::StringPiece& key, bool val); From 6df2326a3084dd4603afc6c7cdf2c18f6b131533 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 8 Mar 2018 17:01:54 +0900 Subject: [PATCH 5/7] Cleanup the static methods of WebContentsPreferences The static methods are totally unnecessary, and it makes code harder to understand since we are using different ways to do the same things. --- atom/browser/atom_browser_client.cc | 11 +- atom/browser/web_contents_preferences.cc | 122 +++++++++-------------- atom/browser/web_contents_preferences.h | 14 ++- 3 files changed, 62 insertions(+), 85 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 5a6aa19a56e7..cf7cc2c96939 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -208,8 +208,10 @@ void AtomBrowserClient::OverrideWebkitPrefs( prefs->allow_running_insecure_content = false; // Custom preferences of guest page. - auto web_contents = content::WebContents::FromRenderViewHost(host); - WebContentsPreferences::OverrideWebkitPrefs(web_contents, prefs); + auto* web_contents = content::WebContents::FromRenderViewHost(host); + auto* web_preferences = WebContentsPreferences::From(web_contents); + if (web_preferences) + web_preferences->OverrideWebkitPrefs(prefs); } void AtomBrowserClient::OverrideSiteInstanceForNavigation( @@ -319,8 +321,9 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches( content::WebContents* web_contents = GetWebContentsFromProcessID(process_id); if (web_contents) { - WebContentsPreferences::AppendExtraCommandLineSwitches( - web_contents, command_line); + auto* web_preferences = WebContentsPreferences::From(web_contents); + if (web_preferences) + web_preferences->AppendCommandLineSwitches(command_line); SessionPreferences::AppendExtraCommandLineSwitches( web_contents->GetBrowserContext(), command_line); diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 02bea454fb91..8a081b6039b9 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -125,70 +125,55 @@ WebContentsPreferences* WebContentsPreferences::From(int process_id) { return From(GetWebContentsFromProcessID(process_id)); } -// static -void WebContentsPreferences::AppendExtraCommandLineSwitches( - content::WebContents* web_contents, base::CommandLine* command_line) { - WebContentsPreferences* self = FromWebContents(web_contents); - if (!self) - return; - - base::DictionaryValue& web_preferences = self->dict_; - - // We are appending args to a webContents so let's save the current state - // of our preferences object so that during the lifetime of the WebContents - // we can fetch the options used to initally configure the WebContents - self->last_dict_.Clear(); - self->last_dict_.MergeDictionary(&web_preferences); - +void WebContentsPreferences::AppendCommandLineSwitches( + base::CommandLine* command_line) { bool b; // Check if plugins are enabled. - if (web_preferences.GetBoolean("plugins", &b) && b) + if (dict_.GetBoolean("plugins", &b) && b) command_line->AppendSwitch(switches::kEnablePlugins); // Experimental flags. - if (web_preferences.GetBoolean(options::kExperimentalFeatures, &b) && b) + if (dict_.GetBoolean(options::kExperimentalFeatures, &b) && b) command_line->AppendSwitch( ::switches::kEnableExperimentalWebPlatformFeatures); - if (web_preferences.GetBoolean(options::kExperimentalCanvasFeatures, &b) && b) + if (dict_.GetBoolean(options::kExperimentalCanvasFeatures, &b) && b) command_line->AppendSwitch(::switches::kEnableExperimentalCanvasFeatures); // Check if we have node integration specified. bool node_integration = true; - web_preferences.GetBoolean(options::kNodeIntegration, &node_integration); + dict_.GetBoolean(options::kNodeIntegration, &node_integration); command_line->AppendSwitchASCII(switches::kNodeIntegration, node_integration ? "true" : "false"); // Whether to enable node integration in Worker. - if (web_preferences.GetBoolean(options::kNodeIntegrationInWorker, &b) && b) + if (dict_.GetBoolean(options::kNodeIntegrationInWorker, &b) && b) command_line->AppendSwitch(switches::kNodeIntegrationInWorker); // Check if webview tag creation is enabled, default to nodeIntegration value. // TODO(kevinsawicki): Default to false in 2.0 bool webview_tag = node_integration; - web_preferences.GetBoolean(options::kWebviewTag, &webview_tag); + dict_.GetBoolean(options::kWebviewTag, &webview_tag); command_line->AppendSwitchASCII(switches::kWebviewTag, webview_tag ? "true" : "false"); // 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. - bool sandbox = false; - if (web_preferences.GetBoolean("sandbox", &sandbox) && sandbox) { + if (dict_.GetBoolean("sandbox", &b) && b) command_line->AppendSwitch(switches::kEnableSandbox); - } else if (!command_line->HasSwitch(switches::kEnableSandbox)) { + else if (!command_line->HasSwitch(switches::kEnableSandbox)) command_line->AppendSwitch(::switches::kNoSandbox); - } - if (web_preferences.GetBoolean("nativeWindowOpen", &b) && b) + if (dict_.GetBoolean("nativeWindowOpen", &b) && b) command_line->AppendSwitch(switches::kNativeWindowOpen); // The preload script. base::FilePath::StringType preload; - if (web_preferences.GetString(options::kPreloadScript, &preload)) { + if (dict_.GetString(options::kPreloadScript, &preload)) { if (base::FilePath(preload).IsAbsolute()) command_line->AppendSwitchNative(switches::kPreloadScript, preload); else LOG(ERROR) << "preload script must have absolute path."; - } else if (web_preferences.GetString(options::kPreloadURL, &preload)) { + } else if (dict_.GetString(options::kPreloadURL, &preload)) { // Translate to file path if there is "preload-url" option. base::FilePath preload_path; if (net::FileURLToFilePath(GURL(preload), &preload_path)) @@ -199,49 +184,44 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( // Custom args for renderer process base::Value* customArgs; - if ((web_preferences.Get(options::kCustomArgs, &customArgs)) - && (customArgs->is_list())) { + if (dict_.Get(options::kCustomArgs, &customArgs) && + customArgs->is_list()) { for (const base::Value& customArg : customArgs->GetList()) { - if (customArg.is_string()) { + if (customArg.is_string()) command_line->AppendArg(customArg.GetString()); - } } } // Run Electron APIs and preload script in isolated world - bool isolated; - if (web_preferences.GetBoolean(options::kContextIsolation, &isolated) && - isolated) + if (dict_.GetBoolean(options::kContextIsolation, &b) && b) command_line->AppendSwitch(switches::kContextIsolation); // --background-color. - std::string color; - if (web_preferences.GetString(options::kBackgroundColor, &color)) - command_line->AppendSwitchASCII(switches::kBackgroundColor, color); + std::string s; + if (dict_.GetString(options::kBackgroundColor, &s)) + command_line->AppendSwitchASCII(switches::kBackgroundColor, s); // --guest-instance-id, which is used to identify guest WebContents. int guest_instance_id = 0; - if (web_preferences.GetInteger(options::kGuestInstanceID, &guest_instance_id)) + if (dict_.GetInteger(options::kGuestInstanceID, &guest_instance_id)) command_line->AppendSwitchASCII(switches::kGuestInstanceID, base::IntToString(guest_instance_id)); // Pass the opener's window id. int opener_id; - if (web_preferences.GetInteger(options::kOpenerID, &opener_id)) + if (dict_.GetInteger(options::kOpenerID, &opener_id)) command_line->AppendSwitchASCII(switches::kOpenerID, base::IntToString(opener_id)); #if defined(OS_MACOSX) // Enable scroll bounce. - bool scroll_bounce; - if (web_preferences.GetBoolean(options::kScrollBounce, &scroll_bounce) && - scroll_bounce) + if (dict_.GetBoolean(options::kScrollBounce, &b) && b) command_line->AppendSwitch(switches::kScrollBounce); #endif // Custom command line switches. const base::ListValue* args; - if (web_preferences.GetList("commandLineSwitches", &args)) { + if (dict_.GetList("commandLineSwitches", &args)) { for (size_t i = 0; i < args->GetSize(); ++i) { std::string arg; if (args->GetString(i, &arg) && !arg.empty()) @@ -250,26 +230,21 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( } // Enable blink features. - std::string blink_features; - if (web_preferences.GetString(options::kBlinkFeatures, &blink_features)) - command_line->AppendSwitchASCII(::switches::kEnableBlinkFeatures, - blink_features); + if (dict_.GetString(options::kBlinkFeatures, &s)) + command_line->AppendSwitchASCII(::switches::kEnableBlinkFeatures, s); // Disable blink features. - std::string disable_blink_features; - if (web_preferences.GetString(options::kDisableBlinkFeatures, - &disable_blink_features)) - command_line->AppendSwitchASCII(::switches::kDisableBlinkFeatures, - disable_blink_features); + if (dict_.GetString(options::kDisableBlinkFeatures, &s)) + command_line->AppendSwitchASCII(::switches::kDisableBlinkFeatures, s); if (guest_instance_id) { // Webview `document.visibilityState` tracks window visibility so we need // to let it know if the window happens to be hidden right now. - auto manager = WebViewManager::GetWebViewManager(web_contents); + auto* manager = WebViewManager::GetWebViewManager(web_contents_); if (manager) { - auto embedder = manager->GetEmbedder(guest_instance_id); + auto* embedder = manager->GetEmbedder(guest_instance_id); if (embedder) { - auto* relay = NativeWindowRelay::FromWebContents(web_contents); + auto* relay = NativeWindowRelay::FromWebContents(embedder); if (relay) { auto* window = relay->window.get(); if (window) { @@ -282,34 +257,35 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( } } } + + // We are appending args to a webContents so let's save the current state + // of our preferences object so that during the lifetime of the WebContents + // we can fetch the options used to initally configure the WebContents + last_dict_.Clear(); + last_dict_.MergeDictionary(&dict_); } -// static void WebContentsPreferences::OverrideWebkitPrefs( - content::WebContents* web_contents, content::WebPreferences* prefs) { - WebContentsPreferences* self = FromWebContents(web_contents); - if (!self) - return; - + content::WebPreferences* prefs) { bool b; - if (self->dict_.GetBoolean("javascript", &b)) + if (dict_.GetBoolean("javascript", &b)) prefs->javascript_enabled = b; - if (self->dict_.GetBoolean("images", &b)) + if (dict_.GetBoolean("images", &b)) prefs->images_enabled = b; - if (self->dict_.GetBoolean("textAreasAreResizable", &b)) + if (dict_.GetBoolean("textAreasAreResizable", &b)) prefs->text_areas_are_resizable = b; - if (self->dict_.GetBoolean("webgl", &b)) { + if (dict_.GetBoolean("webgl", &b)) { prefs->webgl1_enabled = b; prefs->webgl2_enabled = b; } - if (self->dict_.GetBoolean("webSecurity", &b)) { + if (dict_.GetBoolean("webSecurity", &b)) { prefs->web_security_enabled = b; prefs->allow_running_insecure_content = !b; } - if (self->dict_.GetBoolean("allowRunningInsecureContent", &b)) + if (dict_.GetBoolean("allowRunningInsecureContent", &b)) prefs->allow_running_insecure_content = b; const base::DictionaryValue* fonts = nullptr; - if (self->dict_.GetDictionary("defaultFontFamily", &fonts)) { + if (dict_.GetDictionary("defaultFontFamily", &fonts)) { base::string16 font; if (fonts->GetString("standard", &font)) prefs->standard_font_family_map[content::kCommonScript] = font; @@ -325,14 +301,14 @@ void WebContentsPreferences::OverrideWebkitPrefs( prefs->fantasy_font_family_map[content::kCommonScript] = font; } int size; - if (self->GetInteger("defaultFontSize", &size)) + if (GetInteger("defaultFontSize", &size)) prefs->default_font_size = size; - if (self->GetInteger("defaultMonospaceFontSize", &size)) + if (GetInteger("defaultMonospaceFontSize", &size)) prefs->default_fixed_font_size = size; - if (self->GetInteger("minimumFontSize", &size)) + if (GetInteger("minimumFontSize", &size)) prefs->minimum_font_size = size; std::string encoding; - if (self->dict_.GetString("defaultEncoding", &encoding)) + if (dict_.GetString("defaultEncoding", &encoding)) prefs->default_encoding = encoding; } diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 1ab2c7ab3e19..c44fa0b46046 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -34,14 +34,6 @@ class WebContentsPreferences // Get self from procese ID. static WebContentsPreferences* From(int process_id); - // Append command paramters according to |web_contents|'s preferences. - static void AppendExtraCommandLineSwitches( - content::WebContents* web_contents, base::CommandLine* command_line); - - // Modify the WebPreferences according to |web_contents|'s preferences. - static void OverrideWebkitPrefs( - content::WebContents* web_contents, content::WebPreferences* prefs); - WebContentsPreferences(content::WebContents* web_contents, const mate::Dictionary& web_preferences); ~WebContentsPreferences() override; @@ -52,6 +44,12 @@ class WebContentsPreferences // $.extend(|web_preferences|, |new_web_preferences|). void Merge(const base::DictionaryValue& new_web_preferences); + // Append command paramters according to preferences. + void AppendCommandLineSwitches(base::CommandLine* command_line); + + // Modify the WebPreferences according to preferences. + void OverrideWebkitPrefs(content::WebPreferences* prefs); + // Returns the web preferences. base::DictionaryValue* dict() { return &dict_; } const base::DictionaryValue* dict() const { return &dict_; } From 0abbedcdae9c29da3fffeb2aa7937083ea6cc728 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 8 Mar 2018 17:52:46 +0900 Subject: [PATCH 6/7] Fix error caused by refactor --- atom/browser/atom_browser_client.cc | 3 ++- atom/browser/web_contents_preferences.cc | 5 ----- atom/browser/web_contents_preferences.h | 2 -- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index cf7cc2c96939..997d6a1bdb4f 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -174,7 +174,8 @@ void AtomBrowserClient::RenderProcessWillLaunch( new WidevineCdmMessageFilter(process_id, host->GetBrowserContext())); ProcessPreferences prefs; - auto* web_preferences = WebContentsPreferences::From(process_id); + auto* web_preferences = WebContentsPreferences::From( + GetWebContentsFromProcessID(process_id)); if (web_preferences) { prefs.sandbox = web_preferences->IsEnabled("sandbox"); prefs.native_window_open = web_preferences->IsEnabled("nativeWindowOpen"); diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 8a081b6039b9..37bf27ff70fc 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -120,11 +120,6 @@ WebContentsPreferences* WebContentsPreferences::From( return FromWebContents(web_contents); } -// static -WebContentsPreferences* WebContentsPreferences::From(int process_id) { - return From(GetWebContentsFromProcessID(process_id)); -} - void WebContentsPreferences::AppendCommandLineSwitches( base::CommandLine* command_line) { bool b; diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index c44fa0b46046..f08a614bf8c1 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -31,8 +31,6 @@ class WebContentsPreferences public: // Get self from WebContents. static WebContentsPreferences* From(content::WebContents* web_contents); - // Get self from procese ID. - static WebContentsPreferences* From(int process_id); WebContentsPreferences(content::WebContents* web_contents, const mate::Dictionary& web_preferences); From 05fcec829e05f3deb18ca26560077a11c3031e42 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 22 Mar 2018 15:29:20 +0900 Subject: [PATCH 7/7] Use Clone explicitly instead of MergeDictionary --- atom/browser/web_contents_preferences.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 37bf27ff70fc..c2545a7fe364 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -71,7 +71,7 @@ WebContentsPreferences::WebContentsPreferences( #endif SetDefaultBoolIfUndefined("offscreen", false); - last_dict_.MergeDictionary(&web_preferences_); + last_dict_ = std::move(*dict_.CreateDeepCopy()); } WebContentsPreferences::~WebContentsPreferences() { @@ -256,8 +256,7 @@ void WebContentsPreferences::AppendCommandLineSwitches( // We are appending args to a webContents so let's save the current state // of our preferences object so that during the lifetime of the WebContents // we can fetch the options used to initally configure the WebContents - last_dict_.Clear(); - last_dict_.MergeDictionary(&dict_); + last_dict_ = std::move(*dict_.CreateDeepCopy()); } void WebContentsPreferences::OverrideWebkitPrefs(