| 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 // Defines the classes to realize the Font Settings Extension API as specified | 5 // Defines the classes to realize the Font Settings Extension API as specified |
| 6 // in the extension API JSON. | 6 // in the extension API JSON. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_ | 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_ |
| 9 #define CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_ | 9 #define CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_ |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(FontSettingsEventRouter); | 71 DISALLOW_COPY_AND_ASSIGN(FontSettingsEventRouter); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // The profile-keyed service that manages the font_settings extension API. | 74 // The profile-keyed service that manages the font_settings extension API. |
| 75 // This is not an EventRouter::Observer (and does not lazily initialize) because | 75 // This is not an EventRouter::Observer (and does not lazily initialize) because |
| 76 // doing so caused a regression in perf tests. See crbug.com/163466. | 76 // doing so caused a regression in perf tests. See crbug.com/163466. |
| 77 class FontSettingsAPI : public BrowserContextKeyedAPI { | 77 class FontSettingsAPI : public BrowserContextKeyedAPI { |
| 78 public: | 78 public: |
| 79 explicit FontSettingsAPI(content::BrowserContext* context); | 79 explicit FontSettingsAPI(content::BrowserContext* context); |
| 80 virtual ~FontSettingsAPI(); | 80 ~FontSettingsAPI() override; |
| 81 | 81 |
| 82 // BrowserContextKeyedAPI implementation. | 82 // BrowserContextKeyedAPI implementation. |
| 83 static BrowserContextKeyedAPIFactory<FontSettingsAPI>* GetFactoryInstance(); | 83 static BrowserContextKeyedAPIFactory<FontSettingsAPI>* GetFactoryInstance(); |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 friend class BrowserContextKeyedAPIFactory<FontSettingsAPI>; | 86 friend class BrowserContextKeyedAPIFactory<FontSettingsAPI>; |
| 87 | 87 |
| 88 // BrowserContextKeyedAPI implementation. | 88 // BrowserContextKeyedAPI implementation. |
| 89 static const char* service_name() { | 89 static const char* service_name() { |
| 90 return "FontSettingsAPI"; | 90 return "FontSettingsAPI"; |
| 91 } | 91 } |
| 92 static const bool kServiceIsNULLWhileTesting = true; | 92 static const bool kServiceIsNULLWhileTesting = true; |
| 93 | 93 |
| 94 scoped_ptr<FontSettingsEventRouter> font_settings_event_router_; | 94 scoped_ptr<FontSettingsEventRouter> font_settings_event_router_; |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 // fontSettings.clearFont API function. | 97 // fontSettings.clearFont API function. |
| 98 class FontSettingsClearFontFunction : public ChromeSyncExtensionFunction { | 98 class FontSettingsClearFontFunction : public ChromeSyncExtensionFunction { |
| 99 public: | 99 public: |
| 100 DECLARE_EXTENSION_FUNCTION("fontSettings.clearFont", FONTSETTINGS_CLEARFONT) | 100 DECLARE_EXTENSION_FUNCTION("fontSettings.clearFont", FONTSETTINGS_CLEARFONT) |
| 101 | 101 |
| 102 protected: | 102 protected: |
| 103 // RefCounted types have non-public destructors, as with all extension | 103 // RefCounted types have non-public destructors, as with all extension |
| 104 // functions in this file. | 104 // functions in this file. |
| 105 virtual ~FontSettingsClearFontFunction() {} | 105 ~FontSettingsClearFontFunction() override {} |
| 106 | 106 |
| 107 // ExtensionFunction: | 107 // ExtensionFunction: |
| 108 virtual bool RunSync() override; | 108 bool RunSync() override; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 // fontSettings.getFont API function. | 111 // fontSettings.getFont API function. |
| 112 class FontSettingsGetFontFunction : public ChromeSyncExtensionFunction { | 112 class FontSettingsGetFontFunction : public ChromeSyncExtensionFunction { |
| 113 public: | 113 public: |
| 114 DECLARE_EXTENSION_FUNCTION("fontSettings.getFont", FONTSETTINGS_GETFONT) | 114 DECLARE_EXTENSION_FUNCTION("fontSettings.getFont", FONTSETTINGS_GETFONT) |
| 115 | 115 |
| 116 protected: | 116 protected: |
| 117 virtual ~FontSettingsGetFontFunction() {} | 117 ~FontSettingsGetFontFunction() override {} |
| 118 | 118 |
| 119 // ExtensionFunction: | 119 // ExtensionFunction: |
| 120 virtual bool RunSync() override; | 120 bool RunSync() override; |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 // fontSettings.setFont API function. | 123 // fontSettings.setFont API function. |
| 124 class FontSettingsSetFontFunction : public ChromeSyncExtensionFunction { | 124 class FontSettingsSetFontFunction : public ChromeSyncExtensionFunction { |
| 125 public: | 125 public: |
| 126 DECLARE_EXTENSION_FUNCTION("fontSettings.setFont", FONTSETTINGS_SETFONT) | 126 DECLARE_EXTENSION_FUNCTION("fontSettings.setFont", FONTSETTINGS_SETFONT) |
| 127 | 127 |
| 128 protected: | 128 protected: |
| 129 virtual ~FontSettingsSetFontFunction() {} | 129 ~FontSettingsSetFontFunction() override {} |
| 130 | 130 |
| 131 // ExtensionFunction: | 131 // ExtensionFunction: |
| 132 virtual bool RunSync() override; | 132 bool RunSync() override; |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 // fontSettings.getFontList API function. | 135 // fontSettings.getFontList API function. |
| 136 class FontSettingsGetFontListFunction : public ChromeAsyncExtensionFunction { | 136 class FontSettingsGetFontListFunction : public ChromeAsyncExtensionFunction { |
| 137 public: | 137 public: |
| 138 DECLARE_EXTENSION_FUNCTION("fontSettings.getFontList", | 138 DECLARE_EXTENSION_FUNCTION("fontSettings.getFontList", |
| 139 FONTSETTINGS_GETFONTLIST) | 139 FONTSETTINGS_GETFONTLIST) |
| 140 | 140 |
| 141 protected: | 141 protected: |
| 142 virtual ~FontSettingsGetFontListFunction() {} | 142 ~FontSettingsGetFontListFunction() override {} |
| 143 | 143 |
| 144 // ExtensionFunction: | 144 // ExtensionFunction: |
| 145 virtual bool RunAsync() override; | 145 bool RunAsync() override; |
| 146 | 146 |
| 147 private: | 147 private: |
| 148 void FontListHasLoaded(scoped_ptr<base::ListValue> list); | 148 void FontListHasLoaded(scoped_ptr<base::ListValue> list); |
| 149 bool CopyFontsToResult(base::ListValue* fonts); | 149 bool CopyFontsToResult(base::ListValue* fonts); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 // Base class for extension API functions that clear a browser font pref. | 152 // Base class for extension API functions that clear a browser font pref. |
| 153 class ClearFontPrefExtensionFunction : public ChromeSyncExtensionFunction { | 153 class ClearFontPrefExtensionFunction : public ChromeSyncExtensionFunction { |
| 154 protected: | 154 protected: |
| 155 virtual ~ClearFontPrefExtensionFunction() {} | 155 ~ClearFontPrefExtensionFunction() override {} |
| 156 | 156 |
| 157 // ExtensionFunction: | 157 // ExtensionFunction: |
| 158 virtual bool RunSync() override; | 158 bool RunSync() override; |
| 159 | 159 |
| 160 // Implementations should return the name of the preference to clear, like | 160 // Implementations should return the name of the preference to clear, like |
| 161 // "webkit.webprefs.default_font_size". | 161 // "webkit.webprefs.default_font_size". |
| 162 virtual const char* GetPrefName() = 0; | 162 virtual const char* GetPrefName() = 0; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 // Base class for extension API functions that get a browser font pref. | 165 // Base class for extension API functions that get a browser font pref. |
| 166 class GetFontPrefExtensionFunction : public ChromeSyncExtensionFunction { | 166 class GetFontPrefExtensionFunction : public ChromeSyncExtensionFunction { |
| 167 protected: | 167 protected: |
| 168 virtual ~GetFontPrefExtensionFunction() {} | 168 ~GetFontPrefExtensionFunction() override {} |
| 169 | 169 |
| 170 // ExtensionFunction: | 170 // ExtensionFunction: |
| 171 virtual bool RunSync() override; | 171 bool RunSync() override; |
| 172 | 172 |
| 173 // Implementations should return the name of the preference to get, like | 173 // Implementations should return the name of the preference to get, like |
| 174 // "webkit.webprefs.default_font_size". | 174 // "webkit.webprefs.default_font_size". |
| 175 virtual const char* GetPrefName() = 0; | 175 virtual const char* GetPrefName() = 0; |
| 176 | 176 |
| 177 // Implementations should return the key for the value in the extension API, | 177 // Implementations should return the key for the value in the extension API, |
| 178 // like "pixelSize". | 178 // like "pixelSize". |
| 179 virtual const char* GetKey() = 0; | 179 virtual const char* GetKey() = 0; |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 // Base class for extension API functions that set a browser font pref. | 182 // Base class for extension API functions that set a browser font pref. |
| 183 class SetFontPrefExtensionFunction : public ChromeSyncExtensionFunction { | 183 class SetFontPrefExtensionFunction : public ChromeSyncExtensionFunction { |
| 184 protected: | 184 protected: |
| 185 virtual ~SetFontPrefExtensionFunction() {} | 185 ~SetFontPrefExtensionFunction() override {} |
| 186 | 186 |
| 187 // ExtensionFunction: | 187 // ExtensionFunction: |
| 188 virtual bool RunSync() override; | 188 bool RunSync() override; |
| 189 | 189 |
| 190 // Implementations should return the name of the preference to set, like | 190 // Implementations should return the name of the preference to set, like |
| 191 // "webkit.webprefs.default_font_size". | 191 // "webkit.webprefs.default_font_size". |
| 192 virtual const char* GetPrefName() = 0; | 192 virtual const char* GetPrefName() = 0; |
| 193 | 193 |
| 194 // Implementations should return the key for the value in the extension API, | 194 // Implementations should return the key for the value in the extension API, |
| 195 // like "pixelSize". | 195 // like "pixelSize". |
| 196 virtual const char* GetKey() = 0; | 196 virtual const char* GetKey() = 0; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 // The following are get/set/clear API functions that act on a browser font | 199 // The following are get/set/clear API functions that act on a browser font |
| 200 // pref. | 200 // pref. |
| 201 | 201 |
| 202 class FontSettingsClearDefaultFontSizeFunction | 202 class FontSettingsClearDefaultFontSizeFunction |
| 203 : public ClearFontPrefExtensionFunction { | 203 : public ClearFontPrefExtensionFunction { |
| 204 public: | 204 public: |
| 205 DECLARE_EXTENSION_FUNCTION("fontSettings.clearDefaultFontSize", | 205 DECLARE_EXTENSION_FUNCTION("fontSettings.clearDefaultFontSize", |
| 206 FONTSETTINGS_CLEARDEFAULTFONTSIZE) | 206 FONTSETTINGS_CLEARDEFAULTFONTSIZE) |
| 207 | 207 |
| 208 protected: | 208 protected: |
| 209 virtual ~FontSettingsClearDefaultFontSizeFunction() {} | 209 ~FontSettingsClearDefaultFontSizeFunction() override {} |
| 210 | 210 |
| 211 // ClearFontPrefExtensionFunction: | 211 // ClearFontPrefExtensionFunction: |
| 212 virtual const char* GetPrefName() override; | 212 const char* GetPrefName() override; |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 class FontSettingsGetDefaultFontSizeFunction | 215 class FontSettingsGetDefaultFontSizeFunction |
| 216 : public GetFontPrefExtensionFunction { | 216 : public GetFontPrefExtensionFunction { |
| 217 public: | 217 public: |
| 218 DECLARE_EXTENSION_FUNCTION("fontSettings.getDefaultFontSize", | 218 DECLARE_EXTENSION_FUNCTION("fontSettings.getDefaultFontSize", |
| 219 FONTSETTINGS_GETDEFAULTFONTSIZE) | 219 FONTSETTINGS_GETDEFAULTFONTSIZE) |
| 220 | 220 |
| 221 protected: | 221 protected: |
| 222 virtual ~FontSettingsGetDefaultFontSizeFunction() {} | 222 ~FontSettingsGetDefaultFontSizeFunction() override {} |
| 223 | 223 |
| 224 // GetFontPrefExtensionFunction: | 224 // GetFontPrefExtensionFunction: |
| 225 virtual const char* GetPrefName() override; | 225 const char* GetPrefName() override; |
| 226 virtual const char* GetKey() override; | 226 const char* GetKey() override; |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 class FontSettingsSetDefaultFontSizeFunction | 229 class FontSettingsSetDefaultFontSizeFunction |
| 230 : public SetFontPrefExtensionFunction { | 230 : public SetFontPrefExtensionFunction { |
| 231 public: | 231 public: |
| 232 DECLARE_EXTENSION_FUNCTION("fontSettings.setDefaultFontSize", | 232 DECLARE_EXTENSION_FUNCTION("fontSettings.setDefaultFontSize", |
| 233 FONTSETTINGS_SETDEFAULTFONTSIZE) | 233 FONTSETTINGS_SETDEFAULTFONTSIZE) |
| 234 | 234 |
| 235 protected: | 235 protected: |
| 236 virtual ~FontSettingsSetDefaultFontSizeFunction() {} | 236 ~FontSettingsSetDefaultFontSizeFunction() override {} |
| 237 | 237 |
| 238 // SetFontPrefExtensionFunction: | 238 // SetFontPrefExtensionFunction: |
| 239 virtual const char* GetPrefName() override; | 239 const char* GetPrefName() override; |
| 240 virtual const char* GetKey() override; | 240 const char* GetKey() override; |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 class FontSettingsClearDefaultFixedFontSizeFunction | 243 class FontSettingsClearDefaultFixedFontSizeFunction |
| 244 : public ClearFontPrefExtensionFunction { | 244 : public ClearFontPrefExtensionFunction { |
| 245 public: | 245 public: |
| 246 DECLARE_EXTENSION_FUNCTION("fontSettings.clearDefaultFixedFontSize", | 246 DECLARE_EXTENSION_FUNCTION("fontSettings.clearDefaultFixedFontSize", |
| 247 FONTSETTINGS_CLEARDEFAULTFIXEDFONTSIZE) | 247 FONTSETTINGS_CLEARDEFAULTFIXEDFONTSIZE) |
| 248 | 248 |
| 249 protected: | 249 protected: |
| 250 virtual ~FontSettingsClearDefaultFixedFontSizeFunction() {} | 250 ~FontSettingsClearDefaultFixedFontSizeFunction() override {} |
| 251 | 251 |
| 252 // ClearFontPrefExtensionFunction: | 252 // ClearFontPrefExtensionFunction: |
| 253 virtual const char* GetPrefName() override; | 253 const char* GetPrefName() override; |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 class FontSettingsGetDefaultFixedFontSizeFunction | 256 class FontSettingsGetDefaultFixedFontSizeFunction |
| 257 : public GetFontPrefExtensionFunction { | 257 : public GetFontPrefExtensionFunction { |
| 258 public: | 258 public: |
| 259 DECLARE_EXTENSION_FUNCTION("fontSettings.getDefaultFixedFontSize", | 259 DECLARE_EXTENSION_FUNCTION("fontSettings.getDefaultFixedFontSize", |
| 260 FONTSETTINGS_GETDEFAULTFIXEDFONTSIZE) | 260 FONTSETTINGS_GETDEFAULTFIXEDFONTSIZE) |
| 261 | 261 |
| 262 protected: | 262 protected: |
| 263 virtual ~FontSettingsGetDefaultFixedFontSizeFunction() {} | 263 ~FontSettingsGetDefaultFixedFontSizeFunction() override {} |
| 264 | 264 |
| 265 // GetFontPrefExtensionFunction: | 265 // GetFontPrefExtensionFunction: |
| 266 virtual const char* GetPrefName() override; | 266 const char* GetPrefName() override; |
| 267 virtual const char* GetKey() override; | 267 const char* GetKey() override; |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 class FontSettingsSetDefaultFixedFontSizeFunction | 270 class FontSettingsSetDefaultFixedFontSizeFunction |
| 271 : public SetFontPrefExtensionFunction { | 271 : public SetFontPrefExtensionFunction { |
| 272 public: | 272 public: |
| 273 DECLARE_EXTENSION_FUNCTION("fontSettings.setDefaultFixedFontSize", | 273 DECLARE_EXTENSION_FUNCTION("fontSettings.setDefaultFixedFontSize", |
| 274 FONTSETTINGS_SETDEFAULTFIXEDFONTSIZE) | 274 FONTSETTINGS_SETDEFAULTFIXEDFONTSIZE) |
| 275 | 275 |
| 276 protected: | 276 protected: |
| 277 virtual ~FontSettingsSetDefaultFixedFontSizeFunction() {} | 277 ~FontSettingsSetDefaultFixedFontSizeFunction() override {} |
| 278 | 278 |
| 279 // SetFontPrefExtensionFunction: | 279 // SetFontPrefExtensionFunction: |
| 280 virtual const char* GetPrefName() override; | 280 const char* GetPrefName() override; |
| 281 virtual const char* GetKey() override; | 281 const char* GetKey() override; |
| 282 }; | 282 }; |
| 283 | 283 |
| 284 class FontSettingsClearMinimumFontSizeFunction | 284 class FontSettingsClearMinimumFontSizeFunction |
| 285 : public ClearFontPrefExtensionFunction { | 285 : public ClearFontPrefExtensionFunction { |
| 286 public: | 286 public: |
| 287 DECLARE_EXTENSION_FUNCTION("fontSettings.clearMinimumFontSize", | 287 DECLARE_EXTENSION_FUNCTION("fontSettings.clearMinimumFontSize", |
| 288 FONTSETTINGS_CLEARMINIMUMFONTSIZE) | 288 FONTSETTINGS_CLEARMINIMUMFONTSIZE) |
| 289 | 289 |
| 290 protected: | 290 protected: |
| 291 virtual ~FontSettingsClearMinimumFontSizeFunction() {} | 291 ~FontSettingsClearMinimumFontSizeFunction() override {} |
| 292 | 292 |
| 293 // ClearFontPrefExtensionFunction: | 293 // ClearFontPrefExtensionFunction: |
| 294 virtual const char* GetPrefName() override; | 294 const char* GetPrefName() override; |
| 295 }; | 295 }; |
| 296 | 296 |
| 297 class FontSettingsGetMinimumFontSizeFunction | 297 class FontSettingsGetMinimumFontSizeFunction |
| 298 : public GetFontPrefExtensionFunction { | 298 : public GetFontPrefExtensionFunction { |
| 299 public: | 299 public: |
| 300 DECLARE_EXTENSION_FUNCTION("fontSettings.getMinimumFontSize", | 300 DECLARE_EXTENSION_FUNCTION("fontSettings.getMinimumFontSize", |
| 301 FONTSETTINGS_GETMINIMUMFONTSIZE) | 301 FONTSETTINGS_GETMINIMUMFONTSIZE) |
| 302 | 302 |
| 303 protected: | 303 protected: |
| 304 virtual ~FontSettingsGetMinimumFontSizeFunction() {} | 304 ~FontSettingsGetMinimumFontSizeFunction() override {} |
| 305 | 305 |
| 306 // GetFontPrefExtensionFunction: | 306 // GetFontPrefExtensionFunction: |
| 307 virtual const char* GetPrefName() override; | 307 const char* GetPrefName() override; |
| 308 virtual const char* GetKey() override; | 308 const char* GetKey() override; |
| 309 }; | 309 }; |
| 310 | 310 |
| 311 class FontSettingsSetMinimumFontSizeFunction | 311 class FontSettingsSetMinimumFontSizeFunction |
| 312 : public SetFontPrefExtensionFunction { | 312 : public SetFontPrefExtensionFunction { |
| 313 public: | 313 public: |
| 314 DECLARE_EXTENSION_FUNCTION("fontSettings.setMinimumFontSize", | 314 DECLARE_EXTENSION_FUNCTION("fontSettings.setMinimumFontSize", |
| 315 FONTSETTINGS_SETMINIMUMFONTSIZE) | 315 FONTSETTINGS_SETMINIMUMFONTSIZE) |
| 316 | 316 |
| 317 protected: | 317 protected: |
| 318 virtual ~FontSettingsSetMinimumFontSizeFunction() {} | 318 ~FontSettingsSetMinimumFontSizeFunction() override {} |
| 319 | 319 |
| 320 // SetFontPrefExtensionFunction: | 320 // SetFontPrefExtensionFunction: |
| 321 virtual const char* GetPrefName() override; | 321 const char* GetPrefName() override; |
| 322 virtual const char* GetKey() override; | 322 const char* GetKey() override; |
| 323 }; | 323 }; |
| 324 | 324 |
| 325 } // namespace extensions | 325 } // namespace extensions |
| 326 | 326 |
| 327 #endif // CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_ | 327 #endif // CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_ |
| OLD | NEW |