Set appropriate defaults for webview options (#12271)
* Persist defaults to webPreferences object to JS land can read the inferred values instead of just user defined values * Test inherited default propogation * Refactor to remove coupling from fetching values and defaults * Test description type * Fix up tests
This commit is contained in:
parent
f54c94d6c9
commit
c2673aa970
11 changed files with 110 additions and 11 deletions
|
@ -48,6 +48,28 @@ WebContentsPreferences::WebContentsPreferences(
|
|||
web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
|
||||
|
||||
instances_.push_back(this);
|
||||
|
||||
// Set WebPreferences defaults onto the JS object
|
||||
SetDefaultBoolIfUndefined("plugins", false);
|
||||
SetDefaultBoolIfUndefined(options::kExperimentalFeatures, false);
|
||||
SetDefaultBoolIfUndefined(options::kExperimentalCanvasFeatures, false);
|
||||
bool node = SetDefaultBoolIfUndefined(options::kNodeIntegration, true);
|
||||
SetDefaultBoolIfUndefined(options::kNodeIntegrationInWorker, false);
|
||||
SetDefaultBoolIfUndefined(options::kWebviewTag, node);
|
||||
SetDefaultBoolIfUndefined("sandbox", false);
|
||||
SetDefaultBoolIfUndefined("nativeWindowOpen", false);
|
||||
SetDefaultBoolIfUndefined(options::kContextIsolation, false);
|
||||
SetDefaultBoolIfUndefined("javascript", true);
|
||||
SetDefaultBoolIfUndefined("images", true);
|
||||
SetDefaultBoolIfUndefined("textAreasAreResizable", true);
|
||||
SetDefaultBoolIfUndefined("webgl", true);
|
||||
SetDefaultBoolIfUndefined("webSecurity", true);
|
||||
SetDefaultBoolIfUndefined("allowRunningInsecureContent", false);
|
||||
#if defined(OS_MACOSX)
|
||||
SetDefaultBoolIfUndefined(options::kScrollBounce, false);
|
||||
#endif
|
||||
SetDefaultBoolIfUndefined("offscreen", false);
|
||||
last_web_preferences_.MergeDictionary(&web_preferences_);
|
||||
}
|
||||
|
||||
WebContentsPreferences::~WebContentsPreferences() {
|
||||
|
@ -56,6 +78,16 @@ WebContentsPreferences::~WebContentsPreferences() {
|
|||
instances_.end());
|
||||
}
|
||||
|
||||
bool WebContentsPreferences::SetDefaultBoolIfUndefined(const std::string key,
|
||||
bool val) {
|
||||
bool existing;
|
||||
if (!web_preferences_.GetBoolean(key, &existing)) {
|
||||
web_preferences_.SetBoolean(key, val);
|
||||
return val;
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
|
||||
void WebContentsPreferences::Merge(const base::DictionaryValue& extend) {
|
||||
web_preferences_.MergeDictionary(&extend);
|
||||
}
|
||||
|
@ -80,6 +112,12 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
|||
|
||||
base::DictionaryValue& web_preferences = self->web_preferences_;
|
||||
|
||||
// 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);
|
||||
|
||||
bool b;
|
||||
// Check if plugins are enabled.
|
||||
if (web_preferences.GetBoolean("plugins", &b) && b)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue