diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 5afa3070f06f..1182e2859fc3 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -254,15 +254,28 @@ void WebContentsPreferences::OverrideWebkitPrefs( prefs->fantasy_font_family_map[content::kCommonScript] = font; } int size; - if (self->web_preferences_.GetInteger("defaultFontSize", &size)) + if (self->GetInteger("defaultFontSize", &size)) prefs->default_font_size = size; - if (self->web_preferences_.GetInteger("defaultMonospaceFontSize", &size)) + if (self->GetInteger("defaultMonospaceFontSize", &size)) prefs->default_fixed_font_size = size; - if (self->web_preferences_.GetInteger("minimumFontSize", &size)) + if (self->GetInteger("minimumFontSize", &size)) prefs->minimum_font_size = size; std::string encoding; if (self->web_preferences_.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)) + return true; + + base::string16 stringValue; + if (web_preferences_.GetString(attributeName, &stringValue)) + return base::StringToInt(stringValue, intValue); + + return false; +} + } // namespace atom diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 3a04ea9eea0b..f6e44c51b10a 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -5,6 +5,7 @@ #ifndef ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_ #define ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_ +#include #include #include "base/values.h" @@ -60,6 +61,9 @@ class WebContentsPreferences content::WebContents* web_contents_; base::DictionaryValue web_preferences_; + // Get preferences value as integer possibly coercing it from a string + bool GetInteger(const std::string& attributeName, int* intValue); + DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences); };