| 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 92b7288288b39dfc9a2eb519cc294fd62a5fb814..eb7353c69b653d4ac50bf6352eed7536c1fcf5de 100644
|
| --- a/chrome/browser/extensions/extension_font_settings_api.cc
|
| +++ b/chrome/browser/extensions/extension_font_settings_api.cc
|
| @@ -37,20 +37,9 @@ const char kScriptKey[] = "script";
|
|
|
| const char kOnFontChanged[] = "experimental.fontSettings.onFontChanged";
|
|
|
| -// 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|.
|
| @@ -59,18 +48,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))
|
| + script = prefs::kWebKitCommonScript;
|
| + else if (!details->GetString(kScriptKey, &script))
|
| + return false;
|
| + *pref_path = StringPrintf(kWebKitFontPrefFormat,
|
| + generic_family.c_str(),
|
| + script.c_str());
|
| return true;
|
| }
|
|
|
| @@ -78,25 +63,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
|
| @@ -133,12 +109,6 @@ ExtensionFontSettingsEventRouter::~ExtensionFontSettingsEventRouter() {}
|
|
|
| void ExtensionFontSettingsEventRouter::Init() {
|
| registrar_.Init(profile_->GetPrefs());
|
| - 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_,
|
| @@ -191,8 +161,7 @@ void ExtensionFontSettingsEventRouter::Observe(
|
| 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_,
|
| @@ -235,7 +204,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()));
|
|
|
|
|