OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_EXTENSION_SETTINGS_HANDLER_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_EXTENSION_SETTINGS_HANDLER_H_ | |
7 #pragma once | |
8 | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "chrome/browser/extensions/extension_install_ui.h" | |
14 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | |
15 #include "chrome/browser/extensions/extension_warning_set.h" | |
16 #include "chrome/browser/ui/select_file_dialog.h" | |
17 #include "chrome/browser/ui/webui/options2/options_ui.h" | |
18 #include "chrome/browser/ui/webui/chrome_web_ui.h" | |
19 #include "chrome/common/extensions/extension_resource.h" | |
20 #include "content/public/browser/notification_observer.h" | |
21 #include "content/public/browser/notification_registrar.h" | |
22 #include "googleurl/src/gurl.h" | |
23 | |
24 class Extension; | |
25 class ExtensionService; | |
26 class FilePath; | |
27 class PrefService; | |
28 class UserScript; | |
29 | |
30 namespace base { | |
31 class DictionaryValue; | |
32 class ListValue; | |
33 } | |
34 | |
35 // Information about a page running in an extension, for example a popup bubble, | |
36 // a background page, or a tab contents. | |
37 struct ExtensionPage { | |
38 ExtensionPage(const GURL& url, int render_process_id, int render_view_id, | |
39 bool incognito) | |
40 : url(url), | |
41 render_process_id(render_process_id), | |
42 render_view_id(render_view_id), | |
43 incognito(incognito) {} | |
44 GURL url; | |
45 int render_process_id; | |
46 int render_view_id; | |
47 bool incognito; | |
48 }; | |
49 | |
50 // Extension Settings UI handler. | |
51 class ExtensionSettingsHandler : public OptionsPage2UIHandler, | |
52 public SelectFileDialog::Listener, | |
53 public ExtensionUninstallDialog::Delegate { | |
54 public: | |
55 ExtensionSettingsHandler(); | |
56 virtual ~ExtensionSettingsHandler(); | |
57 | |
58 static void RegisterUserPrefs(PrefService* prefs); | |
59 | |
60 // Extension Detail JSON Struct for page. (static for ease of testing). | |
61 // Note: |service| and |warnings| can be NULL in unit tests. | |
62 static base::DictionaryValue* CreateExtensionDetailValue( | |
63 ExtensionService* service, | |
64 const Extension* extension, | |
65 const std::vector<ExtensionPage>& pages, | |
66 const ExtensionWarningSet* warnings, | |
67 bool enabled, | |
68 bool terminated); | |
69 | |
70 // ContentScript JSON Struct for page. (static for ease of testing). | |
71 static base::DictionaryValue* CreateContentScriptDetailValue( | |
72 const UserScript& script, | |
73 const FilePath& extension_path); | |
74 | |
75 // Callback for "requestExtensionsData" message. | |
76 void HandleRequestExtensionsData(const base::ListValue* args); | |
77 | |
78 // Callback for "toggleDeveloperMode" message. | |
79 void HandleToggleDeveloperMode(const base::ListValue* args); | |
80 | |
81 // Callback for "inspect" message. | |
82 void HandleInspectMessage(const base::ListValue* args); | |
83 | |
84 // Callback for "reload" message. | |
85 void HandleReloadMessage(const base::ListValue* args); | |
86 | |
87 // Callback for "enable" message. | |
88 void HandleEnableMessage(const base::ListValue* args); | |
89 | |
90 // Callback for "enableIncognito" message. | |
91 void HandleEnableIncognitoMessage(const base::ListValue* args); | |
92 | |
93 // Callback for "allowFileAcces" message. | |
94 void HandleAllowFileAccessMessage(const base::ListValue* args); | |
95 | |
96 // Callback for "uninstall" message. | |
97 void HandleUninstallMessage(const base::ListValue* args); | |
98 | |
99 // Callback for "options" message. | |
100 void HandleOptionsMessage(const base::ListValue* args); | |
101 | |
102 // Callback for "showButton" message. | |
103 void HandleShowButtonMessage(const base::ListValue* args); | |
104 | |
105 // Callback for "load" message. | |
106 void HandleLoadMessage(const base::ListValue* args); | |
107 | |
108 // Callback for "pack" message. | |
109 void HandlePackMessage(const base::ListValue* args); | |
110 | |
111 // Callback for "autoupdate" message. | |
112 void HandleAutoUpdateMessage(const base::ListValue* args); | |
113 | |
114 // Utility for calling javascript window.alert in the page. | |
115 void ShowAlert(const std::string& message); | |
116 | |
117 // Callback for "selectFilePath" message. | |
118 void HandleSelectFilePathMessage(const base::ListValue* args); | |
119 | |
120 // Utility for callbacks that get an extension ID as the sole argument. | |
121 const Extension* GetExtension(const base::ListValue* args); | |
122 | |
123 // Forces a UI update if appropriate after a notification is received. | |
124 void MaybeUpdateAfterNotification(); | |
125 | |
126 // Register for notifications that we need to reload the page. | |
127 void MaybeRegisterForNotifications(); | |
128 | |
129 // SelectFileDialog::Listener | |
130 virtual void FileSelected(const FilePath& path, | |
131 int index, void* params) OVERRIDE; | |
132 virtual void MultiFilesSelected( | |
133 const std::vector<FilePath>& files, void* params) OVERRIDE; | |
134 virtual void FileSelectionCanceled(void* params) OVERRIDE {} | |
135 | |
136 // WebUIMessageHandler implementation. | |
137 virtual void RegisterMessages() OVERRIDE; | |
138 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; | |
139 | |
140 // OptionsUIHandler implementation. | |
141 virtual void GetLocalizedValues( | |
142 base::DictionaryValue* localized_strings) OVERRIDE; | |
143 virtual void Initialize() OVERRIDE; | |
144 | |
145 // content::NotificationObserver implementation. | |
146 virtual void Observe(int type, | |
147 const content::NotificationSource& source, | |
148 const content::NotificationDetails& details) OVERRIDE; | |
149 | |
150 // ExtensionUninstallDialog::Delegate implementation, used for receiving | |
151 // notification about uninstall confirmation dialog selections. | |
152 virtual void ExtensionUninstallAccepted() OVERRIDE; | |
153 virtual void ExtensionUninstallCanceled() OVERRIDE; | |
154 | |
155 private: | |
156 // Helper that lists the current active html pages for an extension. | |
157 std::vector<ExtensionPage> GetActivePagesForExtension( | |
158 const Extension* extension); | |
159 void GetActivePagesForExtensionProcess( | |
160 const std::set<RenderViewHost*>& views, | |
161 std::vector<ExtensionPage> *result); | |
162 | |
163 // Returns the ExtensionUninstallDialog object for this class, creating it if | |
164 // needed. | |
165 ExtensionUninstallDialog* GetExtensionUninstallDialog(); | |
166 | |
167 // Our model. Outlives us since it's owned by our containing profile. | |
168 ExtensionService* extension_service_; | |
169 | |
170 // Used to pick the directory when loading an extension. | |
171 scoped_refptr<SelectFileDialog> load_extension_dialog_; | |
172 | |
173 // Used to show confirmation UI for uninstalling extensions in incognito mode. | |
174 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_; | |
175 | |
176 // The id of the extension we are prompting the user about. | |
177 std::string extension_id_prompting_; | |
178 | |
179 // If true, we will ignore notifications in ::Observe(). This is needed | |
180 // to prevent reloading the page when we were the cause of the | |
181 // notification. | |
182 bool ignore_notifications_; | |
183 | |
184 // The page may be refreshed in response to a RENDER_VIEW_HOST_DELETED, | |
185 // but the iteration over RenderViewHosts will include the host because the | |
186 // notification is sent when it is in the process of being deleted (and before | |
187 // it is removed from the process). Keep a pointer to it so we can exclude | |
188 // it from the active views. | |
189 RenderViewHost* deleting_rvh_; | |
190 | |
191 // We want to register for notifications only after we've responded at least | |
192 // once to the page, otherwise we'd be calling javacsript functions on objects | |
193 // that don't exist yet when notifications come in. This variable makes sure | |
194 // we do so only once. | |
195 bool registered_for_notifications_; | |
196 | |
197 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsHandler); | |
198 }; | |
199 | |
200 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_EXTENSION_SETTINGS_HANDLER_H_ | |
OLD | NEW |