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; WebContentsPreferences* self;
if (!web_contents) if (!web_contents)
return false; return false;
@ -216,41 +218,23 @@ bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) {
return false; return false;
base::DictionaryValue& web_preferences = self->web_preferences_; base::DictionaryValue& web_preferences = self->web_preferences_;
bool sandboxed = false; bool boolValue = false;
web_preferences.GetBoolean("sandbox", &sandboxed); web_preferences.GetBoolean(attributeName, &boolValue);
return sandboxed; return boolValue;
}
bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) {
return IsPreferenceEnabled("sandbox", web_contents);
} }
bool WebContentsPreferences::UsesNativeWindowOpen( bool WebContentsPreferences::UsesNativeWindowOpen(
content::WebContents* web_contents) { content::WebContents* web_contents) {
WebContentsPreferences* self; return IsPreferenceEnabled("nativeWindowOpen", web_contents);
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;
} }
bool WebContentsPreferences::IsPluginsEnabled( bool WebContentsPreferences::IsPluginsEnabled(
content::WebContents* web_contents) { content::WebContents* web_contents) {
WebContentsPreferences* self; return IsPreferenceEnabled("plugins", web_contents);
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;
} }
// static // static

View file

@ -37,6 +37,8 @@ class WebContentsPreferences
static void AppendExtraCommandLineSwitches( static void AppendExtraCommandLineSwitches(
content::WebContents* web_contents, base::CommandLine* command_line); 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 IsSandboxed(content::WebContents* web_contents);
static bool UsesNativeWindowOpen(content::WebContents* web_contents); static bool UsesNativeWindowOpen(content::WebContents* web_contents);
static bool IsPluginsEnabled(content::WebContents* web_contents); static bool IsPluginsEnabled(content::WebContents* web_contents);