| 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 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/prefs/pref_change_registrar.h" | 14 #include "base/prefs/pref_change_registrar.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "chrome/browser/extensions/chrome_extension_function.h" | 16 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 17 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 19 #include "extensions/browser/extension_event_histogram_value.h" |
| 19 | 20 |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 class BrowserContext; | 24 class BrowserContext; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace extensions { | 27 namespace extensions { |
| 27 | 28 |
| 28 // This class observes pref changed events on a profile and dispatches the | 29 // This class observes pref changed events on a profile and dispatches the |
| 29 // corresponding extension API events to extensions. | 30 // corresponding extension API events to extensions. |
| 30 class FontSettingsEventRouter { | 31 class FontSettingsEventRouter { |
| 31 public: | 32 public: |
| 32 // Constructor for observing pref changed events on |profile|. Stores a | 33 // Constructor for observing pref changed events on |profile|. Stores a |
| 33 // pointer to |profile| but does not take ownership. |profile| must be | 34 // pointer to |profile| but does not take ownership. |profile| must be |
| 34 // non-NULL and remain alive for the lifetime of the instance. | 35 // non-NULL and remain alive for the lifetime of the instance. |
| 35 explicit FontSettingsEventRouter(Profile* profile); | 36 explicit FontSettingsEventRouter(Profile* profile); |
| 36 virtual ~FontSettingsEventRouter(); | 37 virtual ~FontSettingsEventRouter(); |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 // Observes browser pref |pref_name|. When a change is observed, dispatches | 40 // Observes browser pref |pref_name|. When a change is observed, dispatches |
| 40 // event |event_name| to extensions. A JavaScript object is passed to the | 41 // event |event_name| to extensions. A JavaScript object is passed to the |
| 41 // extension event function with the new value of the pref in property |key|. | 42 // extension event function with the new value of the pref in property |key|. |
| 42 void AddPrefToObserve(const char* pref_name, | 43 void AddPrefToObserve(const char* pref_name, |
| 44 events::HistogramValue histogram_value, |
| 43 const char* event_name, | 45 const char* event_name, |
| 44 const char* key); | 46 const char* key); |
| 45 | 47 |
| 46 // Decodes a preference change for a font family map and invokes | 48 // Decodes a preference change for a font family map and invokes |
| 47 // OnFontNamePrefChange with the right parameters. | 49 // OnFontNamePrefChange with the right parameters. |
| 48 void OnFontFamilyMapPrefChanged(const std::string& pref_name); | 50 void OnFontFamilyMapPrefChanged(const std::string& pref_name); |
| 49 | 51 |
| 50 // Dispatches a changed event for the font setting for |generic_family| and | 52 // Dispatches a changed event for the font setting for |generic_family| and |
| 51 // |script| to extensions. The new value of the setting is the value of | 53 // |script| to extensions. The new value of the setting is the value of |
| 52 // browser pref |pref_name|. | 54 // browser pref |pref_name|. |
| 53 void OnFontNamePrefChanged(const std::string& pref_name, | 55 void OnFontNamePrefChanged(const std::string& pref_name, |
| 54 const std::string& generic_family, | 56 const std::string& generic_family, |
| 55 const std::string& script); | 57 const std::string& script); |
| 56 | 58 |
| 57 // Dispatches the setting changed event |event_name| to extensions. The new | 59 // Dispatches the setting changed event |event_name| to extensions. The new |
| 58 // value of the setting is the value of browser pref |pref_name|. This value | 60 // value of the setting is the value of browser pref |pref_name|. This value |
| 59 // is passed in the JavaScript object argument to the extension event function | 61 // is passed in the JavaScript object argument to the extension event function |
| 60 // under the key |key|. | 62 // under the key |key|. |
| 61 void OnFontPrefChanged(const std::string& event_name, | 63 void OnFontPrefChanged(events::HistogramValue histogram_value, |
| 64 const std::string& event_name, |
| 62 const std::string& key, | 65 const std::string& key, |
| 63 const std::string& pref_name); | 66 const std::string& pref_name); |
| 64 | 67 |
| 65 // Manages pref observation registration. | 68 // Manages pref observation registration. |
| 66 PrefChangeRegistrar registrar_; | 69 PrefChangeRegistrar registrar_; |
| 67 | 70 |
| 68 // Weak, owns us (transitively via ExtensionService). | 71 // Weak, owns us (transitively via ExtensionService). |
| 69 Profile* profile_; | 72 Profile* profile_; |
| 70 | 73 |
| 71 DISALLOW_COPY_AND_ASSIGN(FontSettingsEventRouter); | 74 DISALLOW_COPY_AND_ASSIGN(FontSettingsEventRouter); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 ~FontSettingsSetMinimumFontSizeFunction() override {} | 321 ~FontSettingsSetMinimumFontSizeFunction() override {} |
| 319 | 322 |
| 320 // SetFontPrefExtensionFunction: | 323 // SetFontPrefExtensionFunction: |
| 321 const char* GetPrefName() override; | 324 const char* GetPrefName() override; |
| 322 const char* GetKey() override; | 325 const char* GetKey() override; |
| 323 }; | 326 }; |
| 324 | 327 |
| 325 } // namespace extensions | 328 } // namespace extensions |
| 326 | 329 |
| 327 #endif // CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_ | 330 #endif // CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H_ |
| OLD | NEW |