diff options
Diffstat (limited to 'chrome/browser/extensions')
3 files changed, 45 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extension_font_settings_api.cc b/chrome/browser/extensions/extension_font_settings_api.cc index 3359264..3f76f8b 100644 --- a/chrome/browser/extensions/extension_font_settings_api.cc +++ b/chrome/browser/extensions/extension_font_settings_api.cc @@ -12,6 +12,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/extension_error_utils.h" +#include "chrome/common/pref_names.h" #include "content/public/browser/font_list_async.h" namespace { @@ -19,6 +20,7 @@ namespace { const char kGenericFamilyKey[] = "genericFamily"; const char kFontNameKey[] = "fontName"; const char kLocalizedNameKey[] = "localizedName"; +const char kPixelSizeKey[] = "pixelSize"; const char kScriptKey[] = "script"; // Format for per-script font preference keys. @@ -35,8 +37,7 @@ const char kWebKitGlobalFontPrefFormat[] = // Gets the font name preference path from |details| which contains key // |kGenericFamilyKey| and optionally |kScriptKey|. -bool GetFontNamePrefPath(DictionaryValue* details, std::string* pref_path) -{ +bool GetFontNamePrefPath(DictionaryValue* details, std::string* pref_path) { std::string generic_family; if (!details->GetString(kGenericFamilyKey, &generic_family)) return false; @@ -110,8 +111,7 @@ void GetFontListFunction::FontListHasLoaded(scoped_ptr<ListValue> list) { SendResponse(success); } -bool GetFontListFunction::CopyFontsToResult(ListValue* fonts) -{ +bool GetFontListFunction::CopyFontsToResult(ListValue* fonts) { scoped_ptr<ListValue> result(new ListValue()); for (ListValue::iterator it = fonts->begin(); it != fonts->end(); ++it) { ListValue* font_list_value; @@ -141,3 +141,28 @@ bool GetFontListFunction::CopyFontsToResult(ListValue* fonts) result_.reset(result.release()); return true; } + +bool GetDefaultFontSizeFunction::RunImpl() { + PrefService* prefs = profile_->GetPrefs(); + int size = prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize); + + DictionaryValue* result = new DictionaryValue(); + result->SetInteger(kPixelSizeKey, size); + result_.reset(result); + return true; +} + +bool SetDefaultFontSizeFunction::RunImpl() { + DictionaryValue* details = NULL; + EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); + + int size; + EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kPixelSizeKey, &size)); + + ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); + prefs->SetExtensionControlledPref(extension_id(), + prefs::kWebKitGlobalDefaultFontSize, + kExtensionPrefsScopeRegular, + Value::CreateIntegerValue(size)); + return true; +} diff --git a/chrome/browser/extensions/extension_font_settings_api.h b/chrome/browser/extensions/extension_font_settings_api.h index f27e8be..49776f2 100644 --- a/chrome/browser/extensions/extension_font_settings_api.h +++ b/chrome/browser/extensions/extension_font_settings_api.h @@ -30,4 +30,18 @@ class GetFontListFunction : public AsyncExtensionFunction { bool CopyFontsToResult(base::ListValue* fonts); }; +class GetDefaultFontSizeFunction : public SyncExtensionFunction { + public: + virtual bool RunImpl() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME( + "experimental.fontSettings.getDefaultFontSize") +}; + +class SetDefaultFontSizeFunction : public SyncExtensionFunction { + public: + virtual bool RunImpl() OVERRIDE; + DECLARE_EXTENSION_FUNCTION_NAME( + "experimental.fontSettings.setDefaultFontSize") +}; + #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FONT_SETTINGS_API_H__ diff --git a/chrome/browser/extensions/extension_function_registry.cc b/chrome/browser/extensions/extension_function_registry.cc index a6c3ebc..a6773b9 100644 --- a/chrome/browser/extensions/extension_function_registry.cc +++ b/chrome/browser/extensions/extension_function_registry.cc @@ -420,6 +420,8 @@ void ExtensionFunctionRegistry::ResetFunctions() { RegisterFunction<GetFontListFunction>(); RegisterFunction<GetFontNameFunction>(); RegisterFunction<SetFontNameFunction>(); + RegisterFunction<GetDefaultFontSizeFunction>(); + RegisterFunction<SetDefaultFontSizeFunction>(); // ChromeAuth settings. RegisterFunction<SetCloudPrintCredentialsFunction>(); |