OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_UI_WEBUI_OPTIONS_EXTENSION_SETTINGS_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_EXTENSION_SETTINGS_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_EXTENSION_SETTINGS_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_EXTENSION_SETTINGS_HANDLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "chrome/browser/extensions/extension_install_ui.h" |
13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
14 #include "chrome/browser/extensions/pack_extension_job.h" | |
15 #include "chrome/browser/ui/shell_dialogs.h" | 14 #include "chrome/browser/ui/shell_dialogs.h" |
16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 15 #include "chrome/browser/ui/webui/options/options_ui.h" |
17 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 16 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
18 #include "chrome/common/extensions/extension_resource.h" | 17 #include "chrome/common/extensions/extension_resource.h" |
19 #include "content/common/notification_observer.h" | 18 #include "content/common/notification_observer.h" |
20 #include "content/common/notification_registrar.h" | 19 #include "content/common/notification_registrar.h" |
21 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
22 | 21 |
23 class Extension; | 22 class Extension; |
24 class ExtensionService; | 23 class ExtensionService; |
25 class FilePath; | 24 class FilePath; |
26 class PrefService; | 25 class PrefService; |
(...skipping 13 matching lines...) Expand all Loading... | |
40 : url(url), | 39 : url(url), |
41 render_process_id(render_process_id), | 40 render_process_id(render_process_id), |
42 render_view_id(render_view_id), | 41 render_view_id(render_view_id), |
43 incognito(incognito) {} | 42 incognito(incognito) {} |
44 GURL url; | 43 GURL url; |
45 int render_process_id; | 44 int render_process_id; |
46 int render_view_id; | 45 int render_view_id; |
47 bool incognito; | 46 bool incognito; |
48 }; | 47 }; |
49 | 48 |
50 class ExtensionsUIHTMLSource : public ChromeURLDataManager::DataSource { | 49 // Extension Settings UI handler. |
50 class ExtensionSettingsHandler : public OptionsPageUIHandler, | |
51 public SelectFileDialog::Listener, | |
52 public ExtensionUninstallDialog::Delegate { | |
51 public: | 53 public: |
52 ExtensionsUIHTMLSource(); | |
53 | |
54 // Called when the network layer has requested a resource underneath | |
55 // the path we registered. | |
56 virtual void StartDataRequest(const std::string& path, | |
57 bool is_incognito, | |
58 int request_id); | |
59 virtual std::string GetMimeType(const std::string&) const; | |
60 | |
61 private: | |
62 ~ExtensionsUIHTMLSource() {} | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(ExtensionsUIHTMLSource); | |
65 }; | |
66 | |
67 // The handler for JavaScript messages related to the "extensions" view. | |
68 class ExtensionsDOMHandler : public WebUIMessageHandler, | |
69 public NotificationObserver, | |
70 public PackExtensionJob::Client, | |
71 public SelectFileDialog::Listener, | |
72 public ExtensionUninstallDialog::Delegate { | |
73 public: | |
74 | |
75 // Helper class that loads the icons for the extensions in the management UI. | 54 // Helper class that loads the icons for the extensions in the management UI. |
76 // We do this with native code instead of just using chrome-extension:// URLs | 55 // We do this with native code instead of just using chrome-extension:// URLs |
77 // for two reasons: | 56 // for two reasons: |
78 // | 57 // |
79 // 1. We need to support the disabled extensions, too, and using URLs won't | 58 // 1. We need to support the disabled extensions, too, and using URLs won't |
80 // work for them. | 59 // work for them. |
81 // 2. We want to desaturate the icons of the disabled extensions to make them | 60 // 2. We want to desaturate the icons of the disabled extensions to make them |
82 // look disabled. | 61 // look disabled. |
83 class IconLoader : public base::RefCountedThreadSafe<IconLoader> { | 62 class IconLoader : public base::RefCountedThreadSafe<IconLoader> { |
84 public: | 63 public: |
85 explicit IconLoader(ExtensionsDOMHandler* handler); | 64 explicit IconLoader(ExtensionSettingsHandler* handler); |
86 | 65 |
87 // Load |icons|. Will call handler->OnIconsLoaded when complete. IconLoader | 66 // Load |icons|. Will call handler->OnIconsLoaded when complete. IconLoader |
88 // takes ownership of both arguments. | 67 // takes ownership of both arguments. |
89 void LoadIcons(std::vector<ExtensionResource>* icons, | 68 void LoadIcons(std::vector<ExtensionResource>* icons, |
90 base::DictionaryValue* json); | 69 base::DictionaryValue* json); |
91 | 70 |
92 // Cancel the load. IconLoader won't try to call back to the handler after | 71 // Cancel the load. IconLoader won't try to call back to the handler after |
93 // this. | 72 // this. |
94 void Cancel(); | 73 void Cancel(); |
95 | 74 |
96 private: | 75 private: |
97 // Load the icons and call ReportResultOnUIThread when done. This method | 76 // Load the icons and call ReportResultOnUIThread when done. This method |
98 // takes ownership of both arguments. | 77 // takes ownership of both arguments. |
99 void LoadIconsOnFileThread(std::vector<ExtensionResource>* icons, | 78 void LoadIconsOnFileThread(std::vector<ExtensionResource>* icons, |
100 base::DictionaryValue* json); | 79 base::DictionaryValue* json); |
101 | 80 |
102 // Report back to the handler. This method takes ownership of |json|. | 81 // Report back to the handler. This method takes ownership of |json|. |
103 void ReportResultOnUIThread(base::DictionaryValue* json); | 82 void ReportResultOnUIThread(base::DictionaryValue* json); |
104 | 83 |
105 // The handler we will report back to. | 84 // The handler we will report back to. |
106 ExtensionsDOMHandler* handler_; | 85 ExtensionSettingsHandler* handler_; |
107 }; | 86 }; |
108 | 87 |
109 explicit ExtensionsDOMHandler(ExtensionService* extension_service); | 88 ExtensionSettingsHandler(); |
110 virtual ~ExtensionsDOMHandler(); | 89 virtual ~ExtensionSettingsHandler(); |
111 | |
112 // WebUIMessageHandler implementation. | |
113 virtual void RegisterMessages(); | |
114 | 90 |
115 // Extension Detail JSON Struct for page. (static for ease of testing). | 91 // Extension Detail JSON Struct for page. (static for ease of testing). |
116 // Note: service can be NULL in unit tests. | 92 // Note: service can be NULL in unit tests. |
117 static base::DictionaryValue* CreateExtensionDetailValue( | 93 static base::DictionaryValue* CreateExtensionDetailValue( |
118 ExtensionService* service, | 94 ExtensionService* service, |
119 const Extension* extension, | 95 const Extension* extension, |
120 const std::vector<ExtensionPage>& pages, | 96 const std::vector<ExtensionPage>& pages, |
121 bool enabled, | 97 bool enabled, |
122 bool terminated); | 98 bool terminated); |
123 | 99 |
124 // ContentScript JSON Struct for page. (static for ease of testing). | 100 // ContentScript JSON Struct for page. (static for ease of testing). |
125 static base::DictionaryValue* CreateContentScriptDetailValue( | 101 static base::DictionaryValue* CreateContentScriptDetailValue( |
126 const UserScript& script, | 102 const UserScript& script, |
127 const FilePath& extension_path); | 103 const FilePath& extension_path); |
128 | 104 |
129 // ExtensionPackJob::Client | |
130 virtual void OnPackSuccess(const FilePath& crx_file, | |
131 const FilePath& key_file); | |
132 | |
133 virtual void OnPackFailure(const std::string& error); | |
134 | |
135 // ExtensionUninstallDialog::Delegate: | |
136 virtual void ExtensionDialogAccepted(); | |
137 virtual void ExtensionDialogCanceled(); | |
138 | |
139 private: | |
140 // Callback for "requestExtensionsData" message. | 105 // Callback for "requestExtensionsData" message. |
141 void HandleRequestExtensionsData(const base::ListValue* args); | 106 void HandleRequestExtensionsData(const base::ListValue* args); |
142 | 107 |
143 // Callback for "toggleDeveloperMode" message. | 108 // Callback for "toggleDeveloperMode" message. |
144 void HandleToggleDeveloperMode(const base::ListValue* args); | 109 void HandleToggleDeveloperMode(const base::ListValue* args); |
145 | 110 |
146 // Callback for "inspect" message. | 111 // Callback for "inspect" message. |
147 void HandleInspectMessage(const base::ListValue* args); | 112 void HandleInspectMessage(const base::ListValue* args); |
148 | 113 |
149 // Callback for "reload" message. | 114 // Callback for "reload" message. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 void HandleSelectFilePathMessage(const base::ListValue* args); | 148 void HandleSelectFilePathMessage(const base::ListValue* args); |
184 | 149 |
185 // Utility for callbacks that get an extension ID as the sole argument. | 150 // Utility for callbacks that get an extension ID as the sole argument. |
186 const Extension* GetExtension(const base::ListValue* args); | 151 const Extension* GetExtension(const base::ListValue* args); |
187 | 152 |
188 // Forces a UI update if appropriate after a notification is received. | 153 // Forces a UI update if appropriate after a notification is received. |
189 void MaybeUpdateAfterNotification(); | 154 void MaybeUpdateAfterNotification(); |
190 | 155 |
191 // SelectFileDialog::Listener | 156 // SelectFileDialog::Listener |
192 virtual void FileSelected(const FilePath& path, | 157 virtual void FileSelected(const FilePath& path, |
193 int index, void* params); | 158 int index, void* params) OVERRIDE; |
194 virtual void MultiFilesSelected( | 159 virtual void MultiFilesSelected( |
195 const std::vector<FilePath>& files, void* params); | 160 const std::vector<FilePath>& files, void* params) OVERRIDE; |
196 virtual void FileSelectionCanceled(void* params) {} | 161 virtual void FileSelectionCanceled(void* params) OVERRIDE {} |
197 | 162 |
198 // NotificationObserver | 163 // WebUIMessageHandler implementation. |
164 virtual void RegisterMessages() OVERRIDE; | |
165 | |
166 // OptionsUIHandler implementation. | |
167 virtual void GetLocalizedValues( | |
168 base::DictionaryValue* localized_strings) OVERRIDE; | |
169 virtual void Initialize() OVERRIDE; | |
170 | |
171 // DOMMessageHandler implementation. | |
172 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; | |
173 | |
174 // NotificationObserver implementation. | |
199 virtual void Observe(int type, | 175 virtual void Observe(int type, |
200 const NotificationSource& source, | 176 const NotificationSource& source, |
201 const NotificationDetails& details); | 177 const NotificationDetails& details) OVERRIDE; |
202 | 178 |
179 // ExtensionUninstallDialog::Delegate implementation, used for receiving | |
180 // notification about uninstall confirmation dialog selections. | |
181 virtual void ExtensionDialogAccepted() OVERRIDE; | |
182 virtual void ExtensionDialogCanceled() OVERRIDE; | |
183 | |
184 private: | |
203 // Helper that lists the current active html pages for an extension. | 185 // Helper that lists the current active html pages for an extension. |
204 std::vector<ExtensionPage> GetActivePagesForExtension( | 186 std::vector<ExtensionPage> GetActivePagesForExtension( |
205 const Extension* extension); | 187 const Extension* extension); |
206 void GetActivePagesForExtensionProcess( | 188 void GetActivePagesForExtensionProcess( |
207 RenderProcessHost* process, | 189 RenderProcessHost* process, |
208 const Extension* extension, | 190 const Extension* extension, |
209 std::vector<ExtensionPage> *result); | 191 std::vector<ExtensionPage> *result); |
210 | 192 |
211 // Returns the best icon to display in the UI for an extension, or an empty | 193 // Returns the best icon to display in the UI for an extension, or an empty |
212 // ExtensionResource if no good icon exists. | 194 // ExtensionResource if no good icon exists. |
213 ExtensionResource PickExtensionIcon(const Extension* extension); | 195 ExtensionResource PickExtensionIcon(const Extension* extension); |
214 | 196 |
215 // Loads the extension resources into the json data, then calls OnIconsLoaded. | 197 // Loads the extension resources into the json data, then calls OnIconsLoaded. |
216 // Takes ownership of |icons|. | 198 // Takes ownership of |icons|. |
217 // Called on the file thread. | 199 // Called on the file thread. |
218 void LoadExtensionIcons(std::vector<ExtensionResource>* icons, | 200 void LoadExtensionIcons(std::vector<ExtensionResource>* icons, |
219 base::DictionaryValue* json_data); | 201 base::DictionaryValue* json_data); |
220 | 202 |
221 // Takes ownership of |json_data| and tells HTML about it. | 203 // Takes ownership of |json_data| and tells HTML about it. |
222 // Called on the UI thread. | 204 // Called on the UI thread. |
223 void OnIconsLoaded(base::DictionaryValue* json_data); | 205 void OnIconsLoaded(base::DictionaryValue* json_data); |
224 | 206 |
225 // Returns the ExtensionUninstallDialog object for this class, creating it if | 207 // Returns the ExtensionUninstallDialog object for this class, creating it if |
226 // needed. | 208 // needed. |
227 ExtensionUninstallDialog* GetExtensionUninstallDialog(); | 209 ExtensionUninstallDialog* GetExtensionUninstallDialog(); |
228 | 210 |
229 // Our model. Outlives us since it's owned by our containing profile. | 211 // Our model. Outlives us since it's owned by our containing profile. |
230 ExtensionService* const extension_service_; | 212 ExtensionService* /*const*/ extension_service_; |
Aaron Boodman
2011/08/31 18:22:44
remove dead code
Finnur
2011/08/31 20:22:01
Done.
| |
231 | 213 |
232 // Used to pick the directory when loading an extension. | 214 // Used to pick the directory when loading an extension. |
233 scoped_refptr<SelectFileDialog> load_extension_dialog_; | 215 scoped_refptr<SelectFileDialog> load_extension_dialog_; |
234 | 216 |
235 // Used to package the extension. | |
236 scoped_refptr<PackExtensionJob> pack_job_; | |
237 | |
238 // Used to load icons asynchronously on the file thread. | 217 // Used to load icons asynchronously on the file thread. |
239 scoped_refptr<IconLoader> icon_loader_; | 218 scoped_refptr<IconLoader> icon_loader_; |
240 | 219 |
241 // Used to show confirmation UI for uninstalling extensions in incognito mode. | 220 // Used to show confirmation UI for uninstalling extensions in incognito mode. |
242 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; | 221 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; |
243 | 222 |
244 // The id of the extension we are prompting the user about. | 223 // The id of the extension we are prompting the user about. |
245 std::string extension_id_prompting_; | 224 std::string extension_id_prompting_; |
246 | 225 |
247 // We monitor changes to the extension system so that we can reload when | |
248 // necessary. | |
249 NotificationRegistrar registrar_; | |
250 | |
251 // If true, we will ignore notifications in ::Observe(). This is needed | 226 // If true, we will ignore notifications in ::Observe(). This is needed |
252 // to prevent reloading the page when we were the cause of the | 227 // to prevent reloading the page when we were the cause of the |
253 // notification. | 228 // notification. |
254 bool ignore_notifications_; | 229 bool ignore_notifications_; |
255 | 230 |
256 // The page may be refreshed in response to a RENDER_VIEW_HOST_DELETED, | 231 // The page may be refreshed in response to a RENDER_VIEW_HOST_DELETED, |
257 // but the iteration over RenderViewHosts will include the host because the | 232 // but the iteration over RenderViewHosts will include the host because the |
258 // notification is sent when it is in the process of being deleted (and before | 233 // notification is sent when it is in the process of being deleted (and before |
259 // it is removed from the process). Keep a pointer to it so we can exclude | 234 // it is removed from the process). Keep a pointer to it so we can exclude |
260 // it from the active views. | 235 // it from the active views. |
261 RenderViewHost* deleting_rvh_; | 236 RenderViewHost* deleting_rvh_; |
262 | 237 |
263 DISALLOW_COPY_AND_ASSIGN(ExtensionsDOMHandler); | 238 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsHandler); |
264 }; | |
265 | |
266 class ExtensionsUI : public ChromeWebUI { | |
267 public: | |
268 explicit ExtensionsUI(TabContents* contents); | |
269 | |
270 static RefCountedMemory* GetFaviconResourceBytes(); | |
271 | |
272 static void RegisterUserPrefs(PrefService* prefs); | |
273 | |
274 private: | |
275 DISALLOW_COPY_AND_ASSIGN(ExtensionsUI); | |
276 }; | 239 }; |
277 | 240 |
278 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_EXTENSION_SETTINGS_HANDLER_H_ | 241 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_EXTENSION_SETTINGS_HANDLER_H_ |
OLD | NEW |