web_prefrences() => dict()
Having property name being the same with class name is making code harder to understand, and dict is much shorter.
This commit is contained in:
parent
d323ce2c42
commit
9772777919
6 changed files with 38 additions and 32 deletions
|
@ -118,11 +118,10 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate,
|
||||||
WebContentsPreferences::FromWebContents(web_contents->web_contents());
|
WebContentsPreferences::FromWebContents(web_contents->web_contents());
|
||||||
base::DictionaryValue web_preferences_dict;
|
base::DictionaryValue web_preferences_dict;
|
||||||
if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(),
|
if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(),
|
||||||
&web_preferences_dict)) {
|
&web_preferences_dict)) {
|
||||||
existing_preferences->web_preferences()->Clear();
|
existing_preferences->dict()->Clear();
|
||||||
existing_preferences->Merge(web_preferences_dict);
|
existing_preferences->Merge(web_preferences_dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Creates the WebContents used by BrowserWindow.
|
// Creates the WebContents used by BrowserWindow.
|
||||||
web_contents = WebContents::Create(isolate, web_preferences);
|
web_contents = WebContents::Create(isolate, web_preferences);
|
||||||
|
|
|
@ -1125,8 +1125,8 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||||
WebContentsPreferences* web_preferences =
|
WebContentsPreferences* web_preferences =
|
||||||
WebContentsPreferences::FromWebContents(web_contents());
|
WebContentsPreferences::FromWebContents(web_contents());
|
||||||
std::string color_name;
|
std::string color_name;
|
||||||
if (web_preferences->web_preferences()->GetString(options::kBackgroundColor,
|
if (web_preferences->dict()->GetString(options::kBackgroundColor,
|
||||||
&color_name)) {
|
&color_name)) {
|
||||||
view->SetBackgroundColor(ParseHexColor(color_name));
|
view->SetBackgroundColor(ParseHexColor(color_name));
|
||||||
} else {
|
} else {
|
||||||
view->SetBackgroundColor(SK_ColorTRANSPARENT);
|
view->SetBackgroundColor(SK_ColorTRANSPARENT);
|
||||||
|
@ -1844,7 +1844,7 @@ v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
|
||||||
WebContentsPreferences::FromWebContents(web_contents());
|
WebContentsPreferences::FromWebContents(web_contents());
|
||||||
if (!web_preferences)
|
if (!web_preferences)
|
||||||
return v8::Null(isolate);
|
return v8::Null(isolate);
|
||||||
return mate::ConvertToV8(isolate, *web_preferences->web_preferences());
|
return mate::ConvertToV8(isolate, *web_preferences->dict());
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> WebContents::GetLastWebPreferences(v8::Isolate* isolate) {
|
v8::Local<v8::Value> WebContents::GetLastWebPreferences(v8::Isolate* isolate) {
|
||||||
|
@ -1852,7 +1852,7 @@ v8::Local<v8::Value> WebContents::GetLastWebPreferences(v8::Isolate* isolate) {
|
||||||
WebContentsPreferences::FromWebContents(web_contents());
|
WebContentsPreferences::FromWebContents(web_contents());
|
||||||
if (!web_preferences)
|
if (!web_preferences)
|
||||||
return v8::Null(isolate);
|
return v8::Null(isolate);
|
||||||
return mate::ConvertToV8(isolate, *web_preferences->last_web_preferences());
|
return mate::ConvertToV8(isolate, *web_preferences->last_dict());
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> WebContents::GetOwnerBrowserWindow() {
|
v8::Local<v8::Value> WebContents::GetOwnerBrowserWindow() {
|
||||||
|
|
|
@ -238,7 +238,7 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
||||||
auto* web_preferences = web_contents ?
|
auto* web_preferences = web_contents ?
|
||||||
WebContentsPreferences::FromWebContents(web_contents) : nullptr;
|
WebContentsPreferences::FromWebContents(web_contents) : nullptr;
|
||||||
if (web_preferences &&
|
if (web_preferences &&
|
||||||
web_preferences->web_preferences()->GetString("affinity", &affinity) &&
|
web_preferences->dict()->GetString("affinity", &affinity) &&
|
||||||
!affinity.empty()) {
|
!affinity.empty()) {
|
||||||
affinity = base::ToLowerASCII(affinity);
|
affinity = base::ToLowerASCII(affinity);
|
||||||
auto iter = site_per_affinities.find(affinity);
|
auto iter = site_per_affinities.find(affinity);
|
||||||
|
|
|
@ -1373,7 +1373,7 @@ void NativeWindowViews::ShowAutofillPopup(
|
||||||
auto* web_contents_preferences =
|
auto* web_contents_preferences =
|
||||||
WebContentsPreferences::FromWebContents(web_contents);
|
WebContentsPreferences::FromWebContents(web_contents);
|
||||||
if (web_contents_preferences) {
|
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);
|
web_preferences->GetBoolean("offscreen", &is_offsceen);
|
||||||
int guest_instance_id = 0;
|
int guest_instance_id = 0;
|
||||||
|
|
|
@ -45,7 +45,7 @@ WebContentsPreferences::WebContentsPreferences(
|
||||||
copied.Delete("isGuest");
|
copied.Delete("isGuest");
|
||||||
copied.Delete("session");
|
copied.Delete("session");
|
||||||
|
|
||||||
mate::ConvertFromV8(isolate, copied.GetHandle(), &web_preferences_);
|
mate::ConvertFromV8(isolate, copied.GetHandle(), &dict_);
|
||||||
web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
|
web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
|
||||||
|
|
||||||
instances_.push_back(this);
|
instances_.push_back(this);
|
||||||
|
@ -70,7 +70,8 @@ WebContentsPreferences::WebContentsPreferences(
|
||||||
SetDefaultBoolIfUndefined(options::kScrollBounce, false);
|
SetDefaultBoolIfUndefined(options::kScrollBounce, false);
|
||||||
#endif
|
#endif
|
||||||
SetDefaultBoolIfUndefined("offscreen", false);
|
SetDefaultBoolIfUndefined("offscreen", false);
|
||||||
last_web_preferences_.MergeDictionary(&web_preferences_);
|
|
||||||
|
last_dict_.MergeDictionary(&web_preferences_);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContentsPreferences::~WebContentsPreferences() {
|
WebContentsPreferences::~WebContentsPreferences() {
|
||||||
|
@ -90,7 +91,7 @@ bool WebContentsPreferences::SetDefaultBoolIfUndefined(const std::string key,
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContentsPreferences::Merge(const base::DictionaryValue& extend) {
|
void WebContentsPreferences::Merge(const base::DictionaryValue& extend) {
|
||||||
web_preferences_.MergeDictionary(&extend);
|
dict_.MergeDictionary(&extend);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -111,13 +112,13 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||||
if (!self)
|
if (!self)
|
||||||
return;
|
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
|
// 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
|
// of our preferences object so that during the lifetime of the WebContents
|
||||||
// we can fetch the options used to initally configure the WebContents
|
// we can fetch the options used to initally configure the WebContents
|
||||||
self->last_web_preferences_.Clear();
|
self->last_dict_.Clear();
|
||||||
self->last_web_preferences_.MergeDictionary(&web_preferences);
|
self->last_dict_.MergeDictionary(&web_preferences);
|
||||||
|
|
||||||
bool b;
|
bool b;
|
||||||
// Check if plugins are enabled.
|
// Check if plugins are enabled.
|
||||||
|
@ -274,7 +275,7 @@ bool WebContentsPreferences::IsPreferenceEnabled(
|
||||||
if (!self)
|
if (!self)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
base::DictionaryValue& web_preferences = self->web_preferences_;
|
base::DictionaryValue& web_preferences = self->dict_;
|
||||||
bool bool_value = false;
|
bool bool_value = false;
|
||||||
web_preferences.GetBoolean(attribute_name, &bool_value);
|
web_preferences.GetBoolean(attribute_name, &bool_value);
|
||||||
return bool_value;
|
return bool_value;
|
||||||
|
@ -288,24 +289,30 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool b;
|
bool b;
|
||||||
if (self->web_preferences_.GetBoolean("javascript", &b))
|
if (self->dict_.GetBoolean("javascript", &b))
|
||||||
prefs->javascript_enabled = b;
|
prefs->javascript_enabled = b;
|
||||||
if (self->web_preferences_.GetBoolean("images", &b))
|
if (self->dict_.GetBoolean("images", &b))
|
||||||
prefs->images_enabled = b;
|
prefs->images_enabled = b;
|
||||||
if (self->web_preferences_.GetBoolean("textAreasAreResizable", &b))
|
if (self->dict_.GetBoolean("textAreasAreResizable", &b))
|
||||||
prefs->text_areas_are_resizable = b;
|
prefs->text_areas_are_resizable = b;
|
||||||
|
<<<<<<< HEAD
|
||||||
if (self->web_preferences_.GetBoolean("webgl", &b)) {
|
if (self->web_preferences_.GetBoolean("webgl", &b)) {
|
||||||
prefs->webgl1_enabled = b;
|
prefs->webgl1_enabled = b;
|
||||||
prefs->webgl2_enabled = b;
|
prefs->webgl2_enabled = b;
|
||||||
}
|
}
|
||||||
if (self->web_preferences_.GetBoolean("webSecurity", &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->web_security_enabled = b;
|
||||||
prefs->allow_running_insecure_content = !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;
|
prefs->allow_running_insecure_content = b;
|
||||||
const base::DictionaryValue* fonts = nullptr;
|
const base::DictionaryValue* fonts = nullptr;
|
||||||
if (self->web_preferences_.GetDictionary("defaultFontFamily", &fonts)) {
|
if (self->dict_.GetDictionary("defaultFontFamily", &fonts)) {
|
||||||
base::string16 font;
|
base::string16 font;
|
||||||
if (fonts->GetString("standard", &font))
|
if (fonts->GetString("standard", &font))
|
||||||
prefs->standard_font_family_map[content::kCommonScript] = font;
|
prefs->standard_font_family_map[content::kCommonScript] = font;
|
||||||
|
@ -328,18 +335,18 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
||||||
if (self->GetInteger("minimumFontSize", &size))
|
if (self->GetInteger("minimumFontSize", &size))
|
||||||
prefs->minimum_font_size = size;
|
prefs->minimum_font_size = size;
|
||||||
std::string encoding;
|
std::string encoding;
|
||||||
if (self->web_preferences_.GetString("defaultEncoding", &encoding))
|
if (self->dict_.GetString("defaultEncoding", &encoding))
|
||||||
prefs->default_encoding = encoding;
|
prefs->default_encoding = encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContentsPreferences::GetInteger(const std::string& attributeName,
|
bool WebContentsPreferences::GetInteger(const std::string& attributeName,
|
||||||
int* intValue) {
|
int* intValue) {
|
||||||
// if it is already an integer, no conversion needed
|
// if it is already an integer, no conversion needed
|
||||||
if (web_preferences_.GetInteger(attributeName, intValue))
|
if (dict_.GetInteger(attributeName, intValue))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
base::string16 stringValue;
|
base::string16 stringValue;
|
||||||
if (web_preferences_.GetString(attributeName, &stringValue))
|
if (dict_.GetString(attributeName, &stringValue))
|
||||||
return base::StringToInt(stringValue, intValue);
|
return base::StringToInt(stringValue, intValue);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -351,7 +358,7 @@ bool WebContentsPreferences::GetString(const std::string& attribute_name,
|
||||||
WebContentsPreferences* self = FromWebContents(web_contents);
|
WebContentsPreferences* self = FromWebContents(web_contents);
|
||||||
if (!self)
|
if (!self)
|
||||||
return false;
|
return false;
|
||||||
return self->web_preferences()->GetString(attribute_name, string_value);
|
return self->dict()->GetString(attribute_name, string_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -52,14 +52,13 @@ class WebContentsPreferences
|
||||||
const mate::Dictionary& web_preferences);
|
const mate::Dictionary& web_preferences);
|
||||||
~WebContentsPreferences() override;
|
~WebContentsPreferences() override;
|
||||||
|
|
||||||
// $.extend(|web_preferences_|, |new_web_preferences|).
|
// $.extend(|web_preferences|, |new_web_preferences|).
|
||||||
void Merge(const base::DictionaryValue& new_web_preferences);
|
void Merge(const base::DictionaryValue& new_web_preferences);
|
||||||
|
|
||||||
// Returns the web preferences.
|
// Returns the web preferences.
|
||||||
base::DictionaryValue* web_preferences() { return &web_preferences_; }
|
base::DictionaryValue* dict() { return &dict_; }
|
||||||
base::DictionaryValue* last_web_preferences() {
|
const base::DictionaryValue* dict() const { return &dict_; }
|
||||||
return &last_web_preferences_;
|
base::DictionaryValue* last_dict() { return &last_dict_; }
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class content::WebContentsUserData<WebContentsPreferences>;
|
friend class content::WebContentsUserData<WebContentsPreferences>;
|
||||||
|
@ -73,8 +72,9 @@ class WebContentsPreferences
|
||||||
static std::vector<WebContentsPreferences*> instances_;
|
static std::vector<WebContentsPreferences*> instances_;
|
||||||
|
|
||||||
content::WebContents* web_contents_;
|
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);
|
DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue