зеркало из https://github.com/electron/electron.git
Make int converter helper an instance method
This commit is contained in:
Родитель
7ec88d16a6
Коммит
4de637779b
|
@ -215,24 +215,6 @@ bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) {
|
|||
return sandboxed;
|
||||
}
|
||||
|
||||
// static
|
||||
bool WebContentsPreferences::ConvertValueToIntegerFromString(
|
||||
WebContentsPreferences* pref, std::string attributeName, int* intValue) {
|
||||
|
||||
// if it is already an integer, no conversion needed
|
||||
if (pref->web_preferences_.GetInteger(attributeName, intValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
base::string16 stringValue;
|
||||
|
||||
if (pref->web_preferences_.GetString(attributeName, &stringValue)) {
|
||||
return base::StringToInt(stringValue, intValue);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
void WebContentsPreferences::OverrideWebkitPrefs(
|
||||
content::WebContents* web_contents, content::WebPreferences* prefs) {
|
||||
|
@ -272,15 +254,28 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
|||
prefs->fantasy_font_family_map[content::kCommonScript] = font;
|
||||
}
|
||||
int size;
|
||||
if (ConvertValueToIntegerFromString(self, "defaultFontSize", &size))
|
||||
if (self->GetInteger("defaultFontSize", &size))
|
||||
prefs->default_font_size = size;
|
||||
if (ConvertValueToIntegerFromString(self, "defaultMonospaceFontSize", &size))
|
||||
if (self->GetInteger("defaultMonospaceFontSize", &size))
|
||||
prefs->default_fixed_font_size = size;
|
||||
if (ConvertValueToIntegerFromString(self, "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
|
||||
|
|
|
@ -39,9 +39,6 @@ class WebContentsPreferences
|
|||
|
||||
static bool IsSandboxed(content::WebContents* web_contents);
|
||||
|
||||
static bool ConvertValueToIntegerFromString(
|
||||
WebContentsPreferences* pref, std::string attributeName, int* intValue);
|
||||
|
||||
// Modify the WebPreferences according to |web_contents|'s preferences.
|
||||
static void OverrideWebkitPrefs(
|
||||
content::WebContents* web_contents, content::WebPreferences* prefs);
|
||||
|
@ -64,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);
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче