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