| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FONT_SETTINGS_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FONT_SETTINGS_API_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FONT_SETTINGS_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FONT_SETTINGS_API_H__ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "chrome/browser/extensions/extension_function.h" | 11 #include "chrome/browser/extensions/extension_function.h" |
| 12 #include "chrome/browser/prefs/pref_change_registrar.h" | 12 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 13 | 13 |
| 14 class ExtensionFontSettingsEventRouter : public content::NotificationObserver { | 14 class ExtensionFontSettingsEventRouter : public content::NotificationObserver { |
| 15 public: | 15 public: |
| 16 explicit ExtensionFontSettingsEventRouter(Profile* profile); | 16 explicit ExtensionFontSettingsEventRouter(Profile* profile); |
| 17 virtual ~ExtensionFontSettingsEventRouter(); | 17 virtual ~ExtensionFontSettingsEventRouter(); |
| 18 | 18 |
| 19 void Init(); | 19 void Init(); |
| 20 | 20 |
| 21 private: | 21 private: |
| 22 typedef std::map<std::string, std::string> PrefEventMap; | 22 typedef std::pair<std::string, std::string> EventAndKeyPair; |
| 23 // Map of pref name to a pair of event name and key (defined in the API) for |
| 24 // dispatching a pref changed event. For example, |
| 25 // "webkit.webprefs.default_font_size" to ("onDefaultFontSizedChanged", |
| 26 // "pixelSize"). |
| 27 typedef std::map<std::string, EventAndKeyPair> PrefEventMap; |
| 28 |
| 29 void AddPrefToObserve(const char* pref_name, |
| 30 const char* event_name, |
| 31 const char* key); |
| 23 | 32 |
| 24 // content::NotificationObserver implementation. | 33 // content::NotificationObserver implementation. |
| 25 virtual void Observe(int type, | 34 virtual void Observe(int type, |
| 26 const content::NotificationSource& source, | 35 const content::NotificationSource& source, |
| 27 const content::NotificationDetails& details) OVERRIDE; | 36 const content::NotificationDetails& details) OVERRIDE; |
| 37 |
| 28 void OnFontNamePrefChanged(PrefService* pref_service, | 38 void OnFontNamePrefChanged(PrefService* pref_service, |
| 29 const std::string& pref_key, | 39 const std::string& pref_name, |
| 30 const std::string& generic_family, | 40 const std::string& generic_family, |
| 31 const std::string& script, | 41 const std::string& script, |
| 32 bool incognito); | 42 bool incognito); |
| 33 void OnFontSizePrefChanged(PrefService* pref_service, | 43 void OnFontPrefChanged(PrefService* pref_service, |
| 34 const std::string& pref_key, | 44 const std::string& pref_name, |
| 35 const std::string& event_name, | 45 const std::string& event_name, |
| 36 bool incognito); | 46 const std::string& key, |
| 47 bool incognito); |
| 37 | 48 |
| 38 PrefChangeRegistrar registrar_; | 49 PrefChangeRegistrar registrar_; |
| 39 | 50 |
| 40 // Map of pref key to event name. | 51 PrefEventMap pref_event_map_; |
| 41 std::map<std::string, std::string> pref_event_map_; | |
| 42 | 52 |
| 43 // Weak, owns us (transitively via ExtensionService). | 53 // Weak, owns us (transitively via ExtensionService). |
| 44 Profile* profile_; | 54 Profile* profile_; |
| 45 | 55 |
| 46 DISALLOW_COPY_AND_ASSIGN(ExtensionFontSettingsEventRouter); | 56 DISALLOW_COPY_AND_ASSIGN(ExtensionFontSettingsEventRouter); |
| 47 }; | 57 }; |
| 48 | 58 |
| 49 class GetFontFunction : public SyncExtensionFunction { | 59 class GetFontFunction : public SyncExtensionFunction { |
| 50 public: | 60 public: |
| 51 virtual bool RunImpl() OVERRIDE; | 61 virtual bool RunImpl() OVERRIDE; |
| 52 DECLARE_EXTENSION_FUNCTION_NAME("experimental.fontSettings.getFont") | 62 DECLARE_EXTENSION_FUNCTION_NAME("experimental.fontSettings.getFont") |
| 53 }; | 63 }; |
| 54 | 64 |
| 55 class SetFontFunction : public SyncExtensionFunction { | 65 class SetFontFunction : public SyncExtensionFunction { |
| 56 public: | 66 public: |
| 57 virtual bool RunImpl() OVERRIDE; | 67 virtual bool RunImpl() OVERRIDE; |
| 58 DECLARE_EXTENSION_FUNCTION_NAME("experimental.fontSettings.setFont") | 68 DECLARE_EXTENSION_FUNCTION_NAME("experimental.fontSettings.setFont") |
| 59 }; | 69 }; |
| 60 | 70 |
| 61 class GetFontListFunction : public AsyncExtensionFunction { | 71 class GetFontListFunction : public AsyncExtensionFunction { |
| 62 public: | 72 public: |
| 63 virtual bool RunImpl() OVERRIDE; | 73 virtual bool RunImpl() OVERRIDE; |
| 64 DECLARE_EXTENSION_FUNCTION_NAME("experimental.fontSettings.getFontList") | 74 DECLARE_EXTENSION_FUNCTION_NAME("experimental.fontSettings.getFontList") |
| 65 | 75 |
| 66 private: | 76 private: |
| 67 void FontListHasLoaded(scoped_ptr<base::ListValue> list); | 77 void FontListHasLoaded(scoped_ptr<base::ListValue> list); |
| 68 bool CopyFontsToResult(base::ListValue* fonts); | 78 bool CopyFontsToResult(base::ListValue* fonts); |
| 69 }; | 79 }; |
| 70 | 80 |
| 71 // Base class for functions that get a font size. | 81 // Base class for functions that get a font pref. |
| 72 class GetFontSizeExtensionFunction : public SyncExtensionFunction { | 82 class GetFontPrefExtensionFunction : public SyncExtensionFunction { |
| 73 protected: | 83 protected: |
| 74 virtual bool RunImpl() OVERRIDE; | 84 virtual bool RunImpl() OVERRIDE; |
| 75 | 85 |
| 76 // Implementations should return the name of the font size preference to get. | 86 // Implementations should return the name of the preference to get, like |
| 87 // "webkit.webprefs.default_font_size". |
| 77 virtual const char* GetPrefName() = 0; | 88 virtual const char* GetPrefName() = 0; |
| 89 |
| 90 // Implementations should return the key for the value in the extension API, |
| 91 // like "pixelSize". |
| 92 virtual const char* GetKey() = 0; |
| 78 }; | 93 }; |
| 79 | 94 |
| 80 // Base class for functions that set a font size. | 95 // Base class for functions that set a font pref. |
| 81 class SetFontSizeExtensionFunction : public SyncExtensionFunction { | 96 class SetFontPrefExtensionFunction : public SyncExtensionFunction { |
| 82 protected: | 97 protected: |
| 83 virtual bool RunImpl() OVERRIDE; | 98 virtual bool RunImpl() OVERRIDE; |
| 84 | 99 |
| 85 // Implementations should return the name of the font size preference to set. | 100 // Implementations should return the name of the preference to set, like |
| 101 // "webkit.webprefs.default_font_size". |
| 86 virtual const char* GetPrefName() = 0; | 102 virtual const char* GetPrefName() = 0; |
| 103 |
| 104 // Implementations should return the key for the value in the extension API, |
| 105 // like "pixelSize". |
| 106 virtual const char* GetKey() = 0; |
| 87 }; | 107 }; |
| 88 | 108 |
| 89 class GetDefaultFontSizeFunction : public GetFontSizeExtensionFunction { | 109 class GetDefaultFontSizeFunction : public GetFontPrefExtensionFunction { |
| 90 public: | 110 public: |
| 91 DECLARE_EXTENSION_FUNCTION_NAME( | 111 DECLARE_EXTENSION_FUNCTION_NAME( |
| 92 "experimental.fontSettings.getDefaultFontSize") | 112 "experimental.fontSettings.getDefaultFontSize") |
| 93 | 113 |
| 94 protected: | 114 protected: |
| 95 virtual const char* GetPrefName() OVERRIDE; | 115 virtual const char* GetPrefName() OVERRIDE; |
| 116 virtual const char* GetKey() OVERRIDE; |
| 96 }; | 117 }; |
| 97 | 118 |
| 98 class SetDefaultFontSizeFunction : public SetFontSizeExtensionFunction { | 119 class SetDefaultFontSizeFunction : public SetFontPrefExtensionFunction { |
| 99 public: | 120 public: |
| 100 DECLARE_EXTENSION_FUNCTION_NAME( | 121 DECLARE_EXTENSION_FUNCTION_NAME( |
| 101 "experimental.fontSettings.setDefaultFontSize") | 122 "experimental.fontSettings.setDefaultFontSize") |
| 102 | 123 |
| 103 protected: | 124 protected: |
| 104 virtual const char* GetPrefName() OVERRIDE; | 125 virtual const char* GetPrefName() OVERRIDE; |
| 126 virtual const char* GetKey() OVERRIDE; |
| 105 }; | 127 }; |
| 106 | 128 |
| 107 class GetDefaultFixedFontSizeFunction : public GetFontSizeExtensionFunction { | 129 class GetDefaultFixedFontSizeFunction : public GetFontPrefExtensionFunction { |
| 108 public: | 130 public: |
| 109 DECLARE_EXTENSION_FUNCTION_NAME( | 131 DECLARE_EXTENSION_FUNCTION_NAME( |
| 110 "experimental.fontSettings.getDefaultFixedFontSize") | 132 "experimental.fontSettings.getDefaultFixedFontSize") |
| 111 | 133 |
| 112 protected: | 134 protected: |
| 113 virtual const char* GetPrefName() OVERRIDE; | 135 virtual const char* GetPrefName() OVERRIDE; |
| 136 virtual const char* GetKey() OVERRIDE; |
| 114 }; | 137 }; |
| 115 | 138 |
| 116 class SetDefaultFixedFontSizeFunction : public SetFontSizeExtensionFunction { | 139 class SetDefaultFixedFontSizeFunction : public SetFontPrefExtensionFunction { |
| 117 public: | 140 public: |
| 118 DECLARE_EXTENSION_FUNCTION_NAME( | 141 DECLARE_EXTENSION_FUNCTION_NAME( |
| 119 "experimental.fontSettings.setDefaultFixedFontSize") | 142 "experimental.fontSettings.setDefaultFixedFontSize") |
| 120 | 143 |
| 121 protected: | 144 protected: |
| 122 virtual const char* GetPrefName() OVERRIDE; | 145 virtual const char* GetPrefName() OVERRIDE; |
| 146 virtual const char* GetKey() OVERRIDE; |
| 123 }; | 147 }; |
| 124 | 148 |
| 125 class GetMinimumFontSizeFunction : public GetFontSizeExtensionFunction { | 149 class GetMinimumFontSizeFunction : public GetFontPrefExtensionFunction { |
| 126 public: | 150 public: |
| 127 DECLARE_EXTENSION_FUNCTION_NAME( | 151 DECLARE_EXTENSION_FUNCTION_NAME( |
| 128 "experimental.fontSettings.getMinimumFontSize") | 152 "experimental.fontSettings.getMinimumFontSize") |
| 129 | 153 |
| 130 protected: | 154 protected: |
| 131 virtual const char* GetPrefName() OVERRIDE; | 155 virtual const char* GetPrefName() OVERRIDE; |
| 156 virtual const char* GetKey() OVERRIDE; |
| 132 }; | 157 }; |
| 133 | 158 |
| 134 class SetMinimumFontSizeFunction : public SetFontSizeExtensionFunction { | 159 class SetMinimumFontSizeFunction : public SetFontPrefExtensionFunction { |
| 135 public: | 160 public: |
| 136 DECLARE_EXTENSION_FUNCTION_NAME( | 161 DECLARE_EXTENSION_FUNCTION_NAME( |
| 137 "experimental.fontSettings.setMinimumFontSize") | 162 "experimental.fontSettings.setMinimumFontSize") |
| 138 | 163 |
| 139 protected: | 164 protected: |
| 140 virtual const char* GetPrefName() OVERRIDE; | 165 virtual const char* GetPrefName() OVERRIDE; |
| 166 virtual const char* GetKey() OVERRIDE; |
| 167 }; |
| 168 |
| 169 class GetDefaultCharacterSetFunction : public GetFontPrefExtensionFunction { |
| 170 public: |
| 171 DECLARE_EXTENSION_FUNCTION_NAME( |
| 172 "experimental.fontSettings.getDefaultCharacterSet") |
| 173 |
| 174 protected: |
| 175 virtual const char* GetPrefName() OVERRIDE; |
| 176 virtual const char* GetKey() OVERRIDE; |
| 177 }; |
| 178 |
| 179 class SetDefaultCharacterSetFunction : public SetFontPrefExtensionFunction { |
| 180 public: |
| 181 DECLARE_EXTENSION_FUNCTION_NAME( |
| 182 "experimental.fontSettings.setDefaultCharacterSet") |
| 183 |
| 184 protected: |
| 185 virtual const char* GetPrefName() OVERRIDE; |
| 186 virtual const char* GetKey() OVERRIDE; |
| 141 }; | 187 }; |
| 142 | 188 |
| 143 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FONT_SETTINGS_API_H__ | 189 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FONT_SETTINGS_API_H__ |
| OLD | NEW |