| 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 <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/prefs/public/pref_change_registrar.h" | 15 #include "base/prefs/public/pref_change_registrar.h" |
| 16 #include "base/prefs/public/pref_observer.h" | 16 #include "base/prefs/public/pref_observer.h" |
| 17 #include "chrome/browser/extensions/extension_function.h" | 17 #include "chrome/browser/extensions/extension_function.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 // This class observes pref changed events on a profile and dispatches the | 22 // This class observes pref changed events on a profile and dispatches the |
| 23 // corresponding extension API events to extensions. | 23 // corresponding extension API events to extensions. |
| 24 class FontSettingsEventRouter : public PrefObserver { | 24 class FontSettingsEventRouter : public PrefObserver { |
| 25 public: | 25 public: |
| 26 // Constructor for observing pref changed events on |profile|. Stores a | 26 // Constructor for observing pref changed events on |profile|. Stores a |
| 27 // pointer to |profile| but does not take ownership. |profile| must be | 27 // pointer to |profile| but does not take ownership. |profile| must be |
| 28 // non-NULL and remain alive for the lifetime of the instance. Init() must be | 28 // non-NULL and remain alive for the lifetime of the instance. |
| 29 // called to start observing pref changed events. | |
| 30 explicit FontSettingsEventRouter(Profile* profile); | 29 explicit FontSettingsEventRouter(Profile* profile); |
| 31 virtual ~FontSettingsEventRouter(); | 30 virtual ~FontSettingsEventRouter(); |
| 32 | 31 |
| 33 // Starts observing pref changed events on the profile. Must not be called | |
| 34 // more than once. | |
| 35 void Init(); | |
| 36 | |
| 37 private: | 32 private: |
| 38 typedef std::pair<std::string, std::string> EventAndKeyPair; | 33 typedef std::pair<std::string, std::string> EventAndKeyPair; |
| 39 // Map of pref name to a pair of event name and key (defined in the extension | 34 // Map of pref name to a pair of event name and key (defined in the extension |
| 40 // API) for dispatching a pref changed event. For example, | 35 // API) for dispatching a pref changed event. For example, |
| 41 // "webkit.webprefs.default_font_size" to ("onDefaultFontSizedChanged", | 36 // "webkit.webprefs.default_font_size" to ("onDefaultFontSizedChanged", |
| 42 // "pixelSize"). | 37 // "pixelSize"). |
| 43 typedef std::map<std::string, EventAndKeyPair> PrefEventMap; | 38 typedef std::map<std::string, EventAndKeyPair> PrefEventMap; |
| 44 | 39 |
| 45 // Observes browser pref |pref_name|. When a change is observed, dispatches | 40 // Observes browser pref |pref_name|. When a change is observed, dispatches |
| 46 // 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 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 virtual ~SetMinimumFontSizeFunction() {} | 289 virtual ~SetMinimumFontSizeFunction() {} |
| 295 | 290 |
| 296 // SetFontPrefExtensionFunction: | 291 // SetFontPrefExtensionFunction: |
| 297 virtual const char* GetPrefName() OVERRIDE; | 292 virtual const char* GetPrefName() OVERRIDE; |
| 298 virtual const char* GetKey() OVERRIDE; | 293 virtual const char* GetKey() OVERRIDE; |
| 299 }; | 294 }; |
| 300 | 295 |
| 301 } // namespace extensions | 296 } // namespace extensions |
| 302 | 297 |
| 303 #endif // CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H__ | 298 #endif // CHROME_BROWSER_EXTENSIONS_API_FONT_SETTINGS_FONT_SETTINGS_API_H__ |
| OLD | NEW |