Index: chrome/browser/extensions/extension_font_settings_api.cc |
diff --git a/chrome/browser/extensions/extension_font_settings_api.cc b/chrome/browser/extensions/extension_font_settings_api.cc |
index d606135fb111d722b3aec367d8ab2cf7199cf447..ad54cd2f25fbf2f9e4e6cf1e4f5cf4e3677be3b0 100644 |
--- a/chrome/browser/extensions/extension_font_settings_api.cc |
+++ b/chrome/browser/extensions/extension_font_settings_api.cc |
@@ -46,20 +46,9 @@ const char kOnFontChanged[] = "experimental.fontSettings.onFontChanged"; |
const char kOnMinimumFontSizeChanged[] = |
"experimental.fontSettings.onMinimumFontSizeChanged"; |
-// Format for per-script font preference keys. |
-// E.g., "webkit.webprefs.fonts.standard.Hrkt" |
-const char kWebKitPerScriptFontPrefFormat[] = "webkit.webprefs.fonts.%s.%s"; |
-const char kWebKitPerScriptFontPrefPrefix[] = "webkit.webprefs.fonts."; |
- |
-// Format for global (non per-script) font preference keys. |
-// E.g., "webkit.webprefs.global.fixed_font_family" |
-// Note: there are two meanings of "global" here. The "Global" in the const name |
-// means "not per-script". The "global" in the key itself means "not per-tab" |
-// (per-profile). |
-const char kWebKitGlobalFontPrefFormat[] = |
- "webkit.webprefs.global.%s_font_family"; |
-const char kWebKitGlobalFontPrefPrefix[] = "webkit.webprefs.global."; |
-const char kWebKitGlobalFontPrefSuffix[] = "_font_family"; |
+// Format for font preference keys. |
+const char kWebKitFontPrefFormat[] = "webkit.webprefs.fonts.%s.%s"; |
+const char kWebKitFontPrefPrefix[] = "webkit.webprefs.fonts."; |
// Gets the font name preference path from |details| which contains key |
// |kGenericFamilyKey| and optionally |kScriptKey|. |
@@ -68,18 +57,14 @@ bool GetFontNamePrefPath(DictionaryValue* details, std::string* pref_path) { |
if (!details->GetString(kGenericFamilyKey, &generic_family)) |
return false; |
- if (details->HasKey(kScriptKey)) { |
- std::string script; |
- if (!details->GetString(kScriptKey, &script)) |
- return false; |
- *pref_path = StringPrintf(kWebKitPerScriptFontPrefFormat, |
- generic_family.c_str(), |
- script.c_str()); |
- } else { |
- *pref_path = StringPrintf(kWebKitGlobalFontPrefFormat, |
- generic_family.c_str()); |
- } |
- |
+ std::string script; |
+ if (!details->HasKey(kScriptKey)) |
Matt Perry
2012/05/11 20:47:15
use braces when an else is present.
falken
2012/05/14 09:08:23
Always? The style guide says "if one part of an if
Peter Kasting
2012/05/14 18:18:32
Braces aren't needed here.
|
+ script = prefs::kWebKitCommonScript; |
+ else if (!details->GetString(kScriptKey, &script)) |
Matt Perry
2012/05/11 20:47:15
extra space before (
falken
2012/05/14 09:08:23
Done.
|
+ return false; |
+ *pref_path = StringPrintf(kWebKitFontPrefFormat, |
+ generic_family.c_str(), |
+ script.c_str()); |
return true; |
} |
@@ -87,25 +72,16 @@ bool GetFontNamePrefPath(DictionaryValue* details, std::string* pref_path) { |
bool ParseFontNamePrefPath(std::string pref_path, |
std::string* generic_family, |
std::string* script) { |
- if (StartsWithASCII(pref_path, kWebKitPerScriptFontPrefPrefix, true)) { |
- size_t start = strlen(kWebKitPerScriptFontPrefPrefix); |
- size_t pos = pref_path.find('.', start); |
- if (pos == std::string::npos || pos + 1 == pref_path.length()) |
- return false; |
- *generic_family = pref_path.substr(start, pos - start); |
- *script = pref_path.substr(pos + 1); |
- return true; |
- } else if (StartsWithASCII(pref_path, kWebKitGlobalFontPrefPrefix, true) && |
- EndsWith(pref_path, kWebKitGlobalFontPrefSuffix, true)) { |
- size_t start = strlen(kWebKitGlobalFontPrefPrefix); |
- size_t pos = pref_path.find('_', start); |
- if (pos == std::string::npos || pos + 1 == pref_path.length()) |
- return false; |
- *generic_family = pref_path.substr(start, pos - start); |
- *script = ""; |
- return true; |
- } |
- return false; |
+ if (!StartsWithASCII(pref_path, kWebKitFontPrefPrefix, true)) |
+ return false; |
+ |
+ size_t start = strlen(kWebKitFontPrefPrefix); |
+ size_t pos = pref_path.find('.', start); |
+ if (pos == std::string::npos || pos + 1 == pref_path.length()) |
+ return false; |
+ *generic_family = pref_path.substr(start, pos - start); |
+ *script = pref_path.substr(pos + 1); |
+ return true; |
} |
// Returns the localized name of a font so that it can be matched within the |
@@ -156,12 +132,6 @@ void ExtensionFontSettingsEventRouter::Init() { |
kOnDefaultCharacterSetChanged, |
kCharsetKey); |
- registrar_.Add(prefs::kWebKitGlobalStandardFontFamily, this); |
- registrar_.Add(prefs::kWebKitGlobalSerifFontFamily, this); |
- registrar_.Add(prefs::kWebKitGlobalSansSerifFontFamily, this); |
- registrar_.Add(prefs::kWebKitGlobalFixedFontFamily, this); |
- registrar_.Add(prefs::kWebKitGlobalCursiveFontFamily, this); |
- registrar_.Add(prefs::kWebKitGlobalFantasyFontFamily, this); |
RegisterFontFamilyMapObserver(®istrar_, |
prefs::kWebKitStandardFontFamilyMap, this); |
RegisterFontFamilyMapObserver(®istrar_, |
@@ -240,8 +210,7 @@ void ExtensionFontSettingsEventRouter::OnFontNamePrefChanged( |
args.Append(dict); |
dict->SetString(kFontNameKey, font_name); |
dict->SetString(kGenericFamilyKey, generic_family); |
- if (!script.empty()) |
- dict->SetString(kScriptKey, script); |
+ dict->SetString(kScriptKey, script); |
extension_preference_helpers::DispatchEventToExtensions( |
profile_, |
@@ -326,7 +295,7 @@ bool SetFontFunction::RunImpl() { |
std::string font_name; |
EXTENSION_FUNCTION_VALIDATE(details->GetString(kFontNameKey, &font_name)); |
- // Ensure |pref_path| really is for a registered per-script font pref. |
+ // Ensure |pref_path| really is for a registered font pref. |
EXTENSION_FUNCTION_VALIDATE( |
profile_->GetPrefs()->FindPreference(pref_path.c_str())); |