Extract common code into IsPreferenceEnabled method

This commit is contained in:
rreimann 2017-05-19 11:51:12 +02:00 committed by Kevin Sawicki
parent 65da983ccb
commit 791486433d
2 changed files with 14 additions and 28 deletions

View file

@ -206,7 +206,9 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
}
}
bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) {
bool WebContentsPreferences::IsPreferenceEnabled(
const std::string& attributeName,
content::WebContents* web_contents) {
WebContentsPreferences* self;
if (!web_contents)
return false;
@ -216,41 +218,23 @@ bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) {
return false;
base::DictionaryValue& web_preferences = self->web_preferences_;
bool sandboxed = false;
web_preferences.GetBoolean("sandbox", &sandboxed);
return sandboxed;
bool boolValue = false;
web_preferences.GetBoolean(attributeName, &boolValue);
return boolValue;
}
bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) {
return IsPreferenceEnabled("sandbox", web_contents);
}
bool WebContentsPreferences::UsesNativeWindowOpen(
content::WebContents* web_contents) {
WebContentsPreferences* self;
if (!web_contents)
return false;
self = FromWebContents(web_contents);
if (!self)
return false;
base::DictionaryValue& web_preferences = self->web_preferences_;
bool use = false;
web_preferences.GetBoolean("nativeWindowOpen", &use);
return use;
return IsPreferenceEnabled("nativeWindowOpen", web_contents);
}
bool WebContentsPreferences::IsPluginsEnabled(
content::WebContents* web_contents) {
WebContentsPreferences* self;
if (!web_contents)
return false;
self = FromWebContents(web_contents);
if (!self)
return false;
base::DictionaryValue& web_preferences = self->web_preferences_;
bool plugins = false;
web_preferences.GetBoolean("plugins", &plugins);
return plugins;
return IsPreferenceEnabled("plugins", web_contents);
}
// static

View file

@ -37,6 +37,8 @@ class WebContentsPreferences
static void AppendExtraCommandLineSwitches(
content::WebContents* web_contents, base::CommandLine* command_line);
static bool IsPreferenceEnabled(const std::string& attributeName,
content::WebContents* web_contents);
static bool IsSandboxed(content::WebContents* web_contents);
static bool UsesNativeWindowOpen(content::WebContents* web_contents);
static bool IsPluginsEnabled(content::WebContents* web_contents);