From 97727779197b4100b611d3718f47dee0f52afdda Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 8 Mar 2018 16:05:12 +0900 Subject: [PATCH] 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); };