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 #include "chrome/browser/extensions/extensions_ui.h" | 5 #include "chrome/browser/ui/webui/options/extension_settings_handler.h" |
6 | |
7 #include <algorithm> | |
8 | 6 |
9 #include "base/base64.h" | 7 #include "base/base64.h" |
10 #include "base/callback.h" | |
11 #include "base/file_util.h" | 8 #include "base/file_util.h" |
12 #include "base/memory/singleton.h" | |
13 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
14 #include "base/string_util.h" | |
15 #include "base/threading/thread.h" | |
16 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | |
17 #include "base/version.h" | 12 #include "base/version.h" |
13 #include "chrome/browser/debugger/devtools_window.h" | |
18 #include "chrome/browser/extensions/crx_installer.h" | 14 #include "chrome/browser/extensions/crx_installer.h" |
19 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" | 15 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
20 #include "chrome/browser/extensions/extension_error_reporter.h" | |
21 #include "chrome/browser/extensions/extension_host.h" | |
22 #include "chrome/browser/extensions/extension_message_service.h" | |
23 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/extensions/extension_updater.h" | 17 #include "chrome/browser/extensions/extension_updater.h" |
25 #include "chrome/browser/google/google_util.h" | 18 #include "chrome/browser/google/google_util.h" |
26 #include "chrome/browser/prefs/pref_service.h" | |
27 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/tab_contents/background_contents.h" | 20 #include "chrome/browser/tab_contents/background_contents.h" |
29 #include "chrome/browser/ui/browser_list.h" | |
30 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
31 #include "chrome/common/extensions/extension_icon_set.h" | |
32 #include "chrome/common/extensions/url_pattern.h" | |
33 #include "chrome/common/extensions/user_script.h" | |
34 #include "chrome/common/jstemplate_builder.h" | |
35 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
36 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
37 #include "content/browser/debugger/devtools_window.h" | |
38 #include "content/browser/renderer_host/render_process_host.h" | 24 #include "content/browser/renderer_host/render_process_host.h" |
39 #include "content/browser/renderer_host/render_view_host.h" | 25 #include "content/browser/renderer_host/render_view_host.h" |
40 #include "content/browser/renderer_host/render_widget_host.h" | |
41 #include "content/browser/tab_contents/tab_contents.h" | 26 #include "content/browser/tab_contents/tab_contents.h" |
42 #include "content/browser/tab_contents/tab_contents_view.h" | 27 #include "content/browser/tab_contents/tab_contents_view.h" |
43 #include "content/common/content_notification_types.h" | 28 #include "content/common/content_notification_types.h" |
44 #include "content/common/notification_service.h" | 29 #include "content/common/notification_service.h" |
45 #include "grit/browser_resources.h" | 30 #include "grit/browser_resources.h" |
46 #include "grit/chromium_strings.h" | 31 #include "grit/chromium_strings.h" |
47 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
48 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
49 #include "net/base/net_util.h" | |
50 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
51 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
52 #include "ui/gfx/codec/png_codec.h" | 36 #include "ui/gfx/codec/png_codec.h" |
53 #include "ui/gfx/color_utils.h" | 37 #include "ui/gfx/color_utils.h" |
54 #include "ui/gfx/skbitmap_operations.h" | 38 #include "ui/gfx/skbitmap_operations.h" |
55 #include "webkit/glue/image_decoder.h" | 39 #include "webkit/glue/image_decoder.h" |
56 | 40 |
57 namespace { | 41 namespace { |
58 | 42 |
59 bool ShouldShowExtension(const Extension* extension) { | 43 bool ShouldShowExtension(const Extension* extension) { |
(...skipping 14 matching lines...) Expand all Loading... | |
74 if (extension->is_hosted_app()) | 58 if (extension->is_hosted_app()) |
75 return false; | 59 return false; |
76 | 60 |
77 return true; | 61 return true; |
78 } | 62 } |
79 | 63 |
80 } // namespace | 64 } // namespace |
81 | 65 |
82 //////////////////////////////////////////////////////////////////////////////// | 66 //////////////////////////////////////////////////////////////////////////////// |
83 // | 67 // |
84 // ExtensionsHTMLSource | 68 // ExtensionSettingsHandler::IconLoader |
85 // | 69 // |
86 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
87 | 71 |
88 ExtensionsUIHTMLSource::ExtensionsUIHTMLSource() | 72 ExtensionSettingsHandler::IconLoader::IconLoader( |
89 : DataSource(chrome::kChromeUIExtensionsHost, MessageLoop::current()) { | 73 ExtensionSettingsHandler* handler) |
90 } | |
91 | |
92 void ExtensionsUIHTMLSource::StartDataRequest(const std::string& path, | |
93 bool is_incognito, | |
94 int request_id) { | |
95 DictionaryValue localized_strings; | |
96 localized_strings.SetString("title", | |
97 l10n_util::GetStringUTF16(IDS_EXTENSIONS_TITLE)); | |
98 localized_strings.SetString("devModeLink", | |
99 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_LINK)); | |
100 localized_strings.SetString("devModePrefix", | |
101 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_PREFIX)); | |
102 localized_strings.SetString("loadUnpackedButton", | |
103 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON)); | |
104 localized_strings.SetString("packButton", | |
105 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON)); | |
106 localized_strings.SetString("updateButton", | |
107 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON)); | |
108 localized_strings.SetString("noExtensions", | |
109 l10n_util::GetStringUTF16(IDS_EXTENSIONS_NONE_INSTALLED)); | |
110 localized_strings.SetString("suggestGallery", | |
111 l10n_util::GetStringFUTF16(IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY, | |
112 ASCIIToUTF16("<a href='") + | |
113 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( | |
114 GURL(Extension::ChromeStoreLaunchURL())).spec()) + | |
115 ASCIIToUTF16("'>"), | |
116 ASCIIToUTF16("</a>"))); | |
117 localized_strings.SetString("getMoreExtensions", | |
118 ASCIIToUTF16("<a href='") + | |
119 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( | |
120 GURL(Extension::ChromeStoreLaunchURL())).spec()) + | |
121 ASCIIToUTF16("'>") + | |
122 l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS) + | |
123 ASCIIToUTF16("</a>")); | |
124 localized_strings.SetString("extensionCrashed", | |
125 l10n_util::GetStringUTF16(IDS_EXTENSIONS_CRASHED_EXTENSION)); | |
126 localized_strings.SetString("extensionDisabled", | |
127 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLED_EXTENSION)); | |
128 localized_strings.SetString("inDevelopment", | |
129 l10n_util::GetStringUTF16(IDS_EXTENSIONS_IN_DEVELOPMENT)); | |
130 localized_strings.SetString("viewIncognito", | |
131 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INCOGNITO)); | |
132 localized_strings.SetString("extensionId", | |
133 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID)); | |
134 localized_strings.SetString("extensionVersion", | |
135 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VERSION)); | |
136 localized_strings.SetString("inspectViews", | |
137 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); | |
138 localized_strings.SetString("inspectPopupsInstructions", | |
139 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_POPUPS_INSTRUCTIONS)); | |
140 localized_strings.SetString("disable", | |
141 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE)); | |
142 localized_strings.SetString("enable", | |
143 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE)); | |
144 localized_strings.SetString("enableIncognito", | |
145 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_INCOGNITO)); | |
146 localized_strings.SetString("allowFileAccess", | |
147 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_FILE_ACCESS)); | |
148 localized_strings.SetString("incognitoWarning", | |
149 l10n_util::GetStringFUTF16(IDS_EXTENSIONS_INCOGNITO_WARNING, | |
150 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
151 localized_strings.SetString("reload", | |
152 l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD)); | |
153 localized_strings.SetString("uninstall", | |
154 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); | |
155 localized_strings.SetString("options", | |
156 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS)); | |
157 localized_strings.SetString("packDialogTitle", | |
158 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_TITLE)); | |
159 localized_strings.SetString("packDialogHeading", | |
160 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_HEADING)); | |
161 localized_strings.SetString("rootDirectoryLabel", | |
162 l10n_util::GetStringUTF16( | |
163 IDS_EXTENSION_PACK_DIALOG_ROOT_DIRECTORY_LABEL)); | |
164 localized_strings.SetString("packDialogBrowse", | |
165 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_BROWSE)); | |
166 localized_strings.SetString("privateKeyLabel", | |
167 l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_PRIVATE_KEY_LABEL)); | |
168 localized_strings.SetString("okButton", | |
169 l10n_util::GetStringUTF16(IDS_OK)); | |
170 localized_strings.SetString("cancelButton", | |
171 l10n_util::GetStringUTF16(IDS_CANCEL)); | |
172 localized_strings.SetString("showButton", | |
173 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); | |
174 | |
175 SetFontAndTextDirection(&localized_strings); | |
176 | |
177 static const base::StringPiece extensions_html( | |
178 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
179 IDR_EXTENSIONS_UI_HTML)); | |
180 std::string full_html(extensions_html.data(), extensions_html.size()); | |
181 jstemplate_builder::AppendJsonHtml(&localized_strings, &full_html); | |
182 jstemplate_builder::AppendI18nTemplateSourceHtml(&full_html); | |
183 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html); | |
184 jstemplate_builder::AppendJsTemplateSourceHtml(&full_html); | |
185 | |
186 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | |
187 html_bytes->data.resize(full_html.size()); | |
188 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); | |
189 | |
190 SendResponse(request_id, html_bytes); | |
191 } | |
192 | |
193 std::string ExtensionsUIHTMLSource::GetMimeType(const std::string&) const { | |
194 return "text/html"; | |
195 } | |
196 | |
197 //////////////////////////////////////////////////////////////////////////////// | |
198 // | |
199 // ExtensionsDOMHandler::IconLoader | |
200 // | |
201 //////////////////////////////////////////////////////////////////////////////// | |
202 | |
203 ExtensionsDOMHandler::IconLoader::IconLoader(ExtensionsDOMHandler* handler) | |
204 : handler_(handler) { | 74 : handler_(handler) { |
205 } | 75 } |
206 | 76 |
207 void ExtensionsDOMHandler::IconLoader::LoadIcons( | 77 void ExtensionSettingsHandler::IconLoader::LoadIcons( |
208 std::vector<ExtensionResource>* icons, DictionaryValue* json) { | 78 std::vector<ExtensionResource>* icons, DictionaryValue* json) { |
209 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
210 BrowserThread::FILE, FROM_HERE, | 80 BrowserThread::FILE, FROM_HERE, |
211 NewRunnableMethod(this, | 81 NewRunnableMethod(this, |
212 &IconLoader::LoadIconsOnFileThread, icons, json)); | 82 &IconLoader::LoadIconsOnFileThread, icons, json)); |
213 } | 83 } |
214 | 84 |
215 void ExtensionsDOMHandler::IconLoader::Cancel() { | 85 void ExtensionSettingsHandler::IconLoader::Cancel() { |
216 handler_ = NULL; | 86 handler_ = NULL; |
217 } | 87 } |
218 | 88 |
219 void ExtensionsDOMHandler::IconLoader::LoadIconsOnFileThread( | 89 void ExtensionSettingsHandler::IconLoader::LoadIconsOnFileThread( |
220 std::vector<ExtensionResource>* icons, DictionaryValue* json) { | 90 std::vector<ExtensionResource>* icons, DictionaryValue* json) { |
221 scoped_ptr<std::vector<ExtensionResource> > icons_deleter(icons); | 91 scoped_ptr<std::vector<ExtensionResource> > icons_deleter(icons); |
222 scoped_ptr<DictionaryValue> json_deleter(json); | 92 scoped_ptr<DictionaryValue> json_deleter(json); |
223 | 93 |
224 ListValue* extensions = NULL; | 94 ListValue* extensions = NULL; |
225 CHECK(json->GetList("extensions", &extensions)); | 95 CHECK(json->GetList("extensions", &extensions)); |
226 | 96 |
227 for (size_t i = 0; i < icons->size(); ++i) { | 97 for (size_t i = 0; i < icons->size(); ++i) { |
228 DictionaryValue* extension = NULL; | 98 DictionaryValue* extension = NULL; |
229 CHECK(extensions->GetDictionary(static_cast<int>(i), &extension)); | 99 CHECK(extensions->GetDictionary(static_cast<int>(i), &extension)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 | 142 |
273 extension->SetString("icon", icon_url.spec()); | 143 extension->SetString("icon", icon_url.spec()); |
274 } | 144 } |
275 | 145 |
276 BrowserThread::PostTask( | 146 BrowserThread::PostTask( |
277 BrowserThread::UI, FROM_HERE, | 147 BrowserThread::UI, FROM_HERE, |
278 NewRunnableMethod(this, &IconLoader::ReportResultOnUIThread, | 148 NewRunnableMethod(this, &IconLoader::ReportResultOnUIThread, |
279 json_deleter.release())); | 149 json_deleter.release())); |
280 } | 150 } |
281 | 151 |
282 void ExtensionsDOMHandler::IconLoader::ReportResultOnUIThread( | 152 void ExtensionSettingsHandler::IconLoader::ReportResultOnUIThread( |
283 DictionaryValue* json) { | 153 DictionaryValue* json) { |
284 if (handler_) | 154 if (handler_) |
285 handler_->OnIconsLoaded(json); | 155 handler_->OnIconsLoaded(json); |
286 } | 156 } |
287 | 157 |
288 | 158 |
289 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
290 // | 160 // |
291 // ExtensionsDOMHandler | 161 // ExtensionSettingsHandler |
292 // | 162 // |
293 /////////////////////////////////////////////////////////////////////////////// | 163 /////////////////////////////////////////////////////////////////////////////// |
294 | 164 |
295 ExtensionsDOMHandler::ExtensionsDOMHandler(ExtensionService* extension_service) | 165 ExtensionSettingsHandler::ExtensionSettingsHandler() |
296 : extension_service_(extension_service), | 166 : extension_service_(NULL), |
297 ignore_notifications_(false), | 167 ignore_notifications_(false), |
298 deleting_rvh_(NULL) { | 168 deleting_rvh_(NULL) { |
299 } | 169 } |
300 | 170 |
301 void ExtensionsDOMHandler::RegisterMessages() { | 171 ExtensionSettingsHandler::~ExtensionSettingsHandler() { |
302 web_ui_->RegisterMessageCallback("requestExtensionsData", | 172 // There may be pending file dialogs, we need to tell them that we've gone |
303 NewCallback(this, &ExtensionsDOMHandler::HandleRequestExtensionsData)); | 173 // away so they don't try and call back to us. |
304 web_ui_->RegisterMessageCallback("toggleDeveloperMode", | 174 if (load_extension_dialog_.get()) |
305 NewCallback(this, &ExtensionsDOMHandler::HandleToggleDeveloperMode)); | 175 load_extension_dialog_->ListenerDestroyed(); |
306 web_ui_->RegisterMessageCallback("inspect", | 176 |
307 NewCallback(this, &ExtensionsDOMHandler::HandleInspectMessage)); | 177 if (icon_loader_.get()) |
308 web_ui_->RegisterMessageCallback("reload", | 178 icon_loader_->Cancel(); |
309 NewCallback(this, &ExtensionsDOMHandler::HandleReloadMessage)); | |
310 web_ui_->RegisterMessageCallback("enable", | |
311 NewCallback(this, &ExtensionsDOMHandler::HandleEnableMessage)); | |
312 web_ui_->RegisterMessageCallback("enableIncognito", | |
313 NewCallback(this, &ExtensionsDOMHandler::HandleEnableIncognitoMessage)); | |
314 web_ui_->RegisterMessageCallback("allowFileAccess", | |
315 NewCallback(this, &ExtensionsDOMHandler::HandleAllowFileAccessMessage)); | |
316 web_ui_->RegisterMessageCallback("uninstall", | |
317 NewCallback(this, &ExtensionsDOMHandler::HandleUninstallMessage)); | |
318 web_ui_->RegisterMessageCallback("options", | |
319 NewCallback(this, &ExtensionsDOMHandler::HandleOptionsMessage)); | |
320 web_ui_->RegisterMessageCallback("showButton", | |
321 NewCallback(this, &ExtensionsDOMHandler::HandleShowButtonMessage)); | |
322 web_ui_->RegisterMessageCallback("load", | |
323 NewCallback(this, &ExtensionsDOMHandler::HandleLoadMessage)); | |
324 web_ui_->RegisterMessageCallback("pack", | |
325 NewCallback(this, &ExtensionsDOMHandler::HandlePackMessage)); | |
326 web_ui_->RegisterMessageCallback("autoupdate", | |
327 NewCallback(this, &ExtensionsDOMHandler::HandleAutoUpdateMessage)); | |
328 web_ui_->RegisterMessageCallback("selectFilePath", | |
329 NewCallback(this, &ExtensionsDOMHandler::HandleSelectFilePathMessage)); | |
330 } | 179 } |
331 | 180 |
332 void ExtensionsDOMHandler::HandleRequestExtensionsData(const ListValue* args) { | 181 void ExtensionSettingsHandler::RegisterMessages() { |
182 web_ui_->RegisterMessageCallback("requestExtensionsData", | |
183 NewCallback(this, | |
184 &ExtensionSettingsHandler::HandleRequestExtensionsData)); | |
185 web_ui_->RegisterMessageCallback("toggleDeveloperMode", | |
186 NewCallback(this, &ExtensionSettingsHandler::HandleToggleDeveloperMode)); | |
187 web_ui_->RegisterMessageCallback("inspect", | |
188 NewCallback(this, &ExtensionSettingsHandler::HandleInspectMessage)); | |
189 web_ui_->RegisterMessageCallback("reload", | |
190 NewCallback(this, &ExtensionSettingsHandler::HandleReloadMessage)); | |
191 web_ui_->RegisterMessageCallback("enable", | |
192 NewCallback(this, | |
193 &ExtensionSettingsHandler::HandleEnableMessage)); | |
194 web_ui_->RegisterMessageCallback("enableIncognito", | |
195 NewCallback(this, | |
196 &ExtensionSettingsHandler::HandleEnableIncognitoMessage)); | |
197 web_ui_->RegisterMessageCallback("allowFileAccess", | |
198 NewCallback(this, | |
199 &ExtensionSettingsHandler::HandleAllowFileAccessMessage)); | |
200 web_ui_->RegisterMessageCallback("uninstall", | |
201 NewCallback(this, &ExtensionSettingsHandler::HandleUninstallMessage)); | |
202 web_ui_->RegisterMessageCallback("options", | |
203 NewCallback(this, &ExtensionSettingsHandler::HandleOptionsMessage)); | |
204 web_ui_->RegisterMessageCallback("showButton", | |
205 NewCallback(this, &ExtensionSettingsHandler::HandleShowButtonMessage)); | |
206 web_ui_->RegisterMessageCallback("load", | |
207 NewCallback(this, &ExtensionSettingsHandler::HandleLoadMessage)); | |
208 web_ui_->RegisterMessageCallback("autoupdate", | |
209 NewCallback(this, &ExtensionSettingsHandler::HandleAutoUpdateMessage)); | |
210 web_ui_->RegisterMessageCallback("selectFilePath", | |
211 NewCallback(this, | |
212 &ExtensionSettingsHandler::HandleSelectFilePathMessage)); | |
213 } | |
214 | |
215 void ExtensionSettingsHandler::HandleRequestExtensionsData( | |
216 const ListValue* args) { | |
333 DictionaryValue* results = new DictionaryValue(); | 217 DictionaryValue* results = new DictionaryValue(); |
334 | 218 |
335 // Add the extensions to the results structure. | 219 // Add the extensions to the results structure. |
336 ListValue *extensions_list = new ListValue(); | 220 ListValue *extensions_list = new ListValue(); |
337 | 221 |
338 // Stores the icon resource for each of the extensions in extensions_list. We | 222 // Stores the icon resource for each of the extensions in extensions_list. We |
339 // build up a list of them here, then load them on the file thread in | 223 // build up a list of them here, then load them on the file thread in |
340 // ::LoadIcons(). | 224 // ::LoadIcons(). |
341 std::vector<ExtensionResource>* extension_icons = | 225 std::vector<ExtensionResource>* extension_icons = |
342 new std::vector<ExtensionResource>(); | 226 new std::vector<ExtensionResource>(); |
343 | 227 |
344 const ExtensionList* extensions = extension_service_->extensions(); | 228 const ExtensionList* extensions = extension_service_->extensions(); |
345 for (ExtensionList::const_iterator extension = extensions->begin(); | 229 for (ExtensionList::const_iterator extension = extensions->begin(); |
346 extension != extensions->end(); ++extension) { | 230 extension != extensions->end(); ++extension) { |
347 if (ShouldShowExtension(*extension)) { | 231 if (ShouldShowExtension(*extension)) { |
348 extensions_list->Append(CreateExtensionDetailValue( | 232 extensions_list->Append(CreateExtensionDetailValue( |
349 extension_service_.get(), | 233 extension_service_, |
350 *extension, | 234 *extension, |
351 GetActivePagesForExtension(*extension), | 235 GetActivePagesForExtension(*extension), |
352 true, false)); // enabled, terminated | 236 true, false)); // enabled, terminated |
353 extension_icons->push_back(PickExtensionIcon(*extension)); | 237 extension_icons->push_back(PickExtensionIcon(*extension)); |
354 } | 238 } |
355 } | 239 } |
356 extensions = extension_service_->disabled_extensions(); | 240 extensions = extension_service_->disabled_extensions(); |
357 for (ExtensionList::const_iterator extension = extensions->begin(); | 241 for (ExtensionList::const_iterator extension = extensions->begin(); |
358 extension != extensions->end(); ++extension) { | 242 extension != extensions->end(); ++extension) { |
359 if (ShouldShowExtension(*extension)) { | 243 if (ShouldShowExtension(*extension)) { |
360 extensions_list->Append(CreateExtensionDetailValue( | 244 extensions_list->Append(CreateExtensionDetailValue( |
361 extension_service_.get(), | 245 extension_service_, |
362 *extension, | 246 *extension, |
363 GetActivePagesForExtension(*extension), | 247 GetActivePagesForExtension(*extension), |
364 false, false)); // enabled, terminated | 248 false, false)); // enabled, terminated |
365 extension_icons->push_back(PickExtensionIcon(*extension)); | 249 extension_icons->push_back(PickExtensionIcon(*extension)); |
366 } | 250 } |
367 } | 251 } |
368 extensions = extension_service_->terminated_extensions(); | 252 extensions = extension_service_->terminated_extensions(); |
369 std::vector<ExtensionPage> empty_pages; | 253 std::vector<ExtensionPage> empty_pages; |
370 for (ExtensionList::const_iterator extension = extensions->begin(); | 254 for (ExtensionList::const_iterator extension = extensions->begin(); |
371 extension != extensions->end(); ++extension) { | 255 extension != extensions->end(); ++extension) { |
372 if (ShouldShowExtension(*extension)) { | 256 if (ShouldShowExtension(*extension)) { |
373 extensions_list->Append(CreateExtensionDetailValue( | 257 extensions_list->Append(CreateExtensionDetailValue( |
374 extension_service_.get(), | 258 extension_service_, |
375 *extension, | 259 *extension, |
376 empty_pages, // Terminated process has no active pages. | 260 empty_pages, // Terminated process has no active pages. |
377 false, true)); // enabled, terminated | 261 false, true)); // enabled, terminated |
378 extension_icons->push_back(PickExtensionIcon(*extension)); | 262 extension_icons->push_back(PickExtensionIcon(*extension)); |
379 } | 263 } |
380 } | 264 } |
381 results->Set("extensions", extensions_list); | 265 results->Set("extensions", extensions_list); |
382 | 266 |
383 bool developer_mode = web_ui_->GetProfile()->GetPrefs() | 267 Profile* profile = Profile::FromWebUI(web_ui_); |
384 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 268 bool developer_mode = |
269 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | |
385 results->SetBoolean("developerMode", developer_mode); | 270 results->SetBoolean("developerMode", developer_mode); |
386 | 271 |
387 if (icon_loader_.get()) | 272 if (icon_loader_.get()) |
388 icon_loader_->Cancel(); | 273 icon_loader_->Cancel(); |
389 | 274 |
390 icon_loader_ = new IconLoader(this); | 275 icon_loader_ = new IconLoader(this); |
391 icon_loader_->LoadIcons(extension_icons, results); | 276 icon_loader_->LoadIcons(extension_icons, results); |
392 } | 277 } |
393 | 278 |
394 void ExtensionsDOMHandler::OnIconsLoaded(DictionaryValue* json) { | 279 void ExtensionSettingsHandler::OnIconsLoaded(DictionaryValue* json) { |
395 web_ui_->CallJavascriptFunction(L"returnExtensionsData", *json); | 280 web_ui_->CallJavascriptFunction("ExtensionSettings.returnExtensionsData", |
281 *json); | |
396 delete json; | 282 delete json; |
397 | 283 |
398 // Register for notifications that we need to reload the page. | 284 // Register for notifications that we need to reload the page. |
399 registrar_.RemoveAll(); | 285 registrar_.RemoveAll(); |
400 registrar_.Add(this, chrome::EXTENSION_LOADED, | 286 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
401 NotificationService::AllSources()); | 287 NotificationService::AllSources()); |
402 registrar_.Add(this, chrome::EXTENSION_PROCESS_CREATED, | 288 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED, |
403 NotificationService::AllSources()); | 289 NotificationService::AllSources()); |
404 registrar_.Add(this, chrome::EXTENSION_UNLOADED, | 290 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
405 NotificationService::AllSources()); | 291 NotificationService::AllSources()); |
406 registrar_.Add(this, chrome::EXTENSION_UPDATE_DISABLED, | 292 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
407 NotificationService::AllSources()); | 293 NotificationService::AllSources()); |
408 registrar_.Add(this, | 294 registrar_.Add(this, |
409 chrome::NAV_ENTRY_COMMITTED, | 295 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
410 NotificationService::AllSources()); | 296 NotificationService::AllSources()); |
411 registrar_.Add(this, | 297 registrar_.Add(this, |
412 chrome::RENDER_VIEW_HOST_CREATED, | 298 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
413 NotificationService::AllSources()); | 299 NotificationService::AllSources()); |
414 registrar_.Add(this, | 300 registrar_.Add(this, |
415 chrome::RENDER_VIEW_HOST_DELETED, | 301 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
416 NotificationService::AllSources()); | 302 NotificationService::AllSources()); |
417 registrar_.Add(this, | 303 registrar_.Add(this, |
418 chrome::BACKGROUND_CONTENTS_NAVIGATED, | 304 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
419 NotificationService::AllSources()); | 305 NotificationService::AllSources()); |
420 registrar_.Add(this, | 306 registrar_.Add(this, |
421 chrome::BACKGROUND_CONTENTS_DELETED, | 307 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
422 NotificationService::AllSources()); | 308 NotificationService::AllSources()); |
423 registrar_.Add(this, | 309 registrar_.Add(this, |
424 chrome::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, | 310 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, |
425 NotificationService::AllSources()); | 311 NotificationService::AllSources()); |
426 } | 312 } |
427 | 313 |
428 ExtensionResource ExtensionsDOMHandler::PickExtensionIcon( | 314 ExtensionResource ExtensionSettingsHandler::PickExtensionIcon( |
429 const Extension* extension) { | 315 const Extension* extension) { |
430 return extension->GetIconResource(Extension::EXTENSION_ICON_MEDIUM, | 316 return extension->GetIconResource(Extension::EXTENSION_ICON_MEDIUM, |
431 ExtensionIconSet::MATCH_BIGGER); | 317 ExtensionIconSet::MATCH_BIGGER); |
432 } | 318 } |
433 | 319 |
434 ExtensionUninstallDialog* ExtensionsDOMHandler::GetExtensionUninstallDialog() { | 320 ExtensionUninstallDialog* |
321 ExtensionSettingsHandler::GetExtensionUninstallDialog() { | |
435 if (!extension_uninstall_dialog_.get()) { | 322 if (!extension_uninstall_dialog_.get()) { |
436 extension_uninstall_dialog_.reset( | 323 extension_uninstall_dialog_.reset( |
437 new ExtensionUninstallDialog(web_ui_->GetProfile())); | 324 new ExtensionUninstallDialog(Profile::FromWebUI(web_ui_))); |
438 } | 325 } |
439 return extension_uninstall_dialog_.get(); | 326 return extension_uninstall_dialog_.get(); |
440 } | 327 } |
441 | 328 |
442 void ExtensionsDOMHandler::HandleToggleDeveloperMode(const ListValue* args) { | 329 void ExtensionSettingsHandler::HandleToggleDeveloperMode( |
443 bool developer_mode = web_ui_->GetProfile()->GetPrefs() | 330 const ListValue* args) { |
444 ->GetBoolean(prefs::kExtensionsUIDeveloperMode); | 331 Profile* profile = Profile::FromWebUI(web_ui_); |
445 web_ui_->GetProfile()->GetPrefs()->SetBoolean( | 332 bool developer_mode = |
333 profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); | |
334 profile->GetPrefs()->SetBoolean( | |
446 prefs::kExtensionsUIDeveloperMode, !developer_mode); | 335 prefs::kExtensionsUIDeveloperMode, !developer_mode); |
336 HandleRequestExtensionsData(NULL); | |
447 } | 337 } |
448 | 338 |
449 void ExtensionsDOMHandler::HandleInspectMessage(const ListValue* args) { | 339 void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { |
450 std::string render_process_id_str; | 340 std::string render_process_id_str; |
451 std::string render_view_id_str; | 341 std::string render_view_id_str; |
452 int render_process_id; | 342 int render_process_id; |
453 int render_view_id; | 343 int render_view_id; |
454 CHECK(args->GetSize() == 2); | 344 CHECK_EQ(2U, args->GetSize()); |
455 CHECK(args->GetString(0, &render_process_id_str)); | 345 CHECK(args->GetString(0, &render_process_id_str)); |
456 CHECK(args->GetString(1, &render_view_id_str)); | 346 CHECK(args->GetString(1, &render_view_id_str)); |
457 CHECK(base::StringToInt(render_process_id_str, &render_process_id)); | 347 CHECK(base::StringToInt(render_process_id_str, &render_process_id)); |
458 CHECK(base::StringToInt(render_view_id_str, &render_view_id)); | 348 CHECK(base::StringToInt(render_view_id_str, &render_view_id)); |
459 RenderViewHost* host = RenderViewHost::FromID(render_process_id, | 349 RenderViewHost* host = RenderViewHost::FromID(render_process_id, |
460 render_view_id); | 350 render_view_id); |
461 if (!host) { | 351 if (!host) { |
462 // This can happen if the host has gone away since the page was displayed. | 352 // This can happen if the host has gone away since the page was displayed. |
463 return; | 353 return; |
464 } | 354 } |
465 | 355 |
466 DevToolsWindow::OpenDevToolsWindow(host); | 356 DevToolsWindow::OpenDevToolsWindow(host); |
467 } | 357 } |
468 | 358 |
469 void ExtensionsDOMHandler::HandleReloadMessage(const ListValue* args) { | 359 void ExtensionSettingsHandler::HandleReloadMessage(const ListValue* args) { |
470 std::string extension_id = WideToASCII(ExtractStringValue(args)); | 360 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
471 CHECK(!extension_id.empty()); | 361 CHECK(!extension_id.empty()); |
472 extension_service_->ReloadExtension(extension_id); | 362 extension_service_->ReloadExtension(extension_id); |
473 } | 363 } |
474 | 364 |
475 void ExtensionsDOMHandler::HandleEnableMessage(const ListValue* args) { | 365 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { |
476 CHECK(args->GetSize() == 2); | 366 CHECK_EQ(2U, args->GetSize()); |
477 std::string extension_id, enable_str; | 367 std::string extension_id, enable_str; |
478 CHECK(args->GetString(0, &extension_id)); | 368 CHECK(args->GetString(0, &extension_id)); |
479 CHECK(args->GetString(1, &enable_str)); | 369 CHECK(args->GetString(1, &enable_str)); |
370 | |
371 const Extension* extension = | |
372 extension_service_->GetExtensionById(extension_id, true); | |
373 DCHECK(extension); | |
Aaron Boodman
2011/08/31 18:22:44
CHECK - you're going to crash on the next line any
Finnur
2011/08/31 20:22:01
Ah, this is from the original extensions_ui.cc cod
| |
374 if (!Extension::UserMayDisable(extension->location())) { | |
375 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was" | |
376 << "made. Extension id: " << extension->id(); | |
377 return; | |
378 } | |
379 | |
480 if (enable_str == "true") { | 380 if (enable_str == "true") { |
481 ExtensionPrefs* prefs = extension_service_->extension_prefs(); | 381 ExtensionPrefs* prefs = extension_service_->extension_prefs(); |
482 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 382 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
483 const Extension* extension = | |
484 extension_service_->GetExtensionById(extension_id, true); | |
485 ShowExtensionDisabledDialog(extension_service_, | 383 ShowExtensionDisabledDialog(extension_service_, |
486 web_ui_->GetProfile(), extension); | 384 Profile::FromWebUI(web_ui_), extension); |
487 } else { | 385 } else { |
488 extension_service_->EnableExtension(extension_id); | 386 extension_service_->EnableExtension(extension_id); |
489 } | 387 } |
490 } else { | 388 } else { |
491 extension_service_->DisableExtension(extension_id); | 389 extension_service_->DisableExtension(extension_id); |
492 } | 390 } |
493 } | 391 } |
494 | 392 |
495 void ExtensionsDOMHandler::HandleEnableIncognitoMessage(const ListValue* args) { | 393 void ExtensionSettingsHandler::HandleEnableIncognitoMessage( |
496 CHECK(args->GetSize() == 2); | 394 const ListValue* args) { |
395 CHECK_EQ(2U, args->GetSize()); | |
497 std::string extension_id, enable_str; | 396 std::string extension_id, enable_str; |
498 CHECK(args->GetString(0, &extension_id)); | 397 CHECK(args->GetString(0, &extension_id)); |
499 CHECK(args->GetString(1, &enable_str)); | 398 CHECK(args->GetString(1, &enable_str)); |
500 const Extension* extension = | 399 const Extension* extension = |
501 extension_service_->GetExtensionById(extension_id, true); | 400 extension_service_->GetExtensionById(extension_id, true); |
502 DCHECK(extension); | 401 DCHECK(extension); |
503 | 402 |
504 // Flipping the incognito bit will generate unload/load notifications for the | 403 // Flipping the incognito bit will generate unload/load notifications for the |
505 // extension, but we don't want to reload the page, because a) we've already | 404 // extension, but we don't want to reload the page, because a) we've already |
506 // updated the UI to reflect the change, and b) we want the yellow warning | 405 // updated the UI to reflect the change, and b) we want the yellow warning |
507 // text to stay until the user has left the page. | 406 // text to stay until the user has left the page. |
508 // | 407 // |
509 // TODO(aa): This creates crapiness in some cases. For example, in a main | 408 // TODO(aa): This creates crapiness in some cases. For example, in a main |
510 // window, when toggling this, the browser action will flicker because it gets | 409 // window, when toggling this, the browser action will flicker because it gets |
511 // unloaded, then reloaded. It would be better to have a dedicated | 410 // unloaded, then reloaded. It would be better to have a dedicated |
512 // notification for this case. | 411 // notification for this case. |
513 // | 412 // |
514 // Bug: http://crbug.com/41384 | 413 // Bug: http://crbug.com/41384 |
515 ignore_notifications_ = true; | 414 ignore_notifications_ = true; |
516 extension_service_->SetIsIncognitoEnabled(extension, enable_str == "true"); | 415 extension_service_->SetIsIncognitoEnabled(extension->id(), |
416 enable_str == "true"); | |
517 ignore_notifications_ = false; | 417 ignore_notifications_ = false; |
518 } | 418 } |
519 | 419 |
520 void ExtensionsDOMHandler::HandleAllowFileAccessMessage(const ListValue* args) { | 420 void ExtensionSettingsHandler::HandleAllowFileAccessMessage( |
521 CHECK(args->GetSize() == 2); | 421 const ListValue* args) { |
422 CHECK_EQ(2U, args->GetSize()); | |
522 std::string extension_id, allow_str; | 423 std::string extension_id, allow_str; |
523 CHECK(args->GetString(0, &extension_id)); | 424 CHECK(args->GetString(0, &extension_id)); |
524 CHECK(args->GetString(1, &allow_str)); | 425 CHECK(args->GetString(1, &allow_str)); |
525 const Extension* extension = | 426 const Extension* extension = |
526 extension_service_->GetExtensionById(extension_id, true); | 427 extension_service_->GetExtensionById(extension_id, true); |
527 DCHECK(extension); | 428 DCHECK(extension); |
528 | 429 |
430 if (!Extension::UserMayDisable(extension->location())) { | |
431 LOG(ERROR) << "Attempt to change allow file access of an extension that is " | |
432 << "non-usermanagable was made. Extension id : " | |
433 << extension->id(); | |
434 return; | |
435 } | |
436 | |
529 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); | 437 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); |
530 } | 438 } |
531 | 439 |
532 void ExtensionsDOMHandler::HandleUninstallMessage(const ListValue* args) { | 440 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) { |
533 std::string extension_id = WideToASCII(ExtractStringValue(args)); | 441 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
534 CHECK(!extension_id.empty()); | 442 CHECK(!extension_id.empty()); |
535 const Extension* extension = | 443 const Extension* extension = |
536 extension_service_->GetExtensionById(extension_id, true); | 444 extension_service_->GetExtensionById(extension_id, true); |
537 if (!extension) | 445 if (!extension) |
538 extension = extension_service_->GetTerminatedExtension(extension_id); | 446 extension = extension_service_->GetTerminatedExtension(extension_id); |
539 if (!extension) | 447 if (!extension) |
540 return; | 448 return; |
541 | 449 |
450 if (!Extension::UserMayDisable(extension->location())) { | |
451 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable " | |
452 << "was made. Extension id : " << extension->id(); | |
453 return; | |
454 } | |
455 | |
542 if (!extension_id_prompting_.empty()) | 456 if (!extension_id_prompting_.empty()) |
543 return; // Only one prompt at a time. | 457 return; // Only one prompt at a time. |
544 | 458 |
545 extension_id_prompting_ = extension_id; | 459 extension_id_prompting_ = extension_id; |
546 | 460 |
547 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension); | 461 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension); |
548 } | 462 } |
549 | 463 |
550 void ExtensionsDOMHandler::ExtensionDialogAccepted() { | 464 void ExtensionSettingsHandler::ExtensionDialogAccepted() { |
551 DCHECK(!extension_id_prompting_.empty()); | 465 DCHECK(!extension_id_prompting_.empty()); |
552 | 466 |
553 bool was_terminated = false; | 467 bool was_terminated = false; |
554 | 468 |
555 // The extension can be uninstalled in another window while the UI was | 469 // The extension can be uninstalled in another window while the UI was |
556 // showing. Do nothing in that case. | 470 // showing. Do nothing in that case. |
557 const Extension* extension = | 471 const Extension* extension = |
558 extension_service_->GetExtensionById(extension_id_prompting_, true); | 472 extension_service_->GetExtensionById(extension_id_prompting_, true); |
559 if (!extension) { | 473 if (!extension) { |
560 extension = extension_service_->GetTerminatedExtension( | 474 extension = extension_service_->GetTerminatedExtension( |
561 extension_id_prompting_); | 475 extension_id_prompting_); |
562 was_terminated = true; | 476 was_terminated = true; |
563 } | 477 } |
564 if (!extension) | 478 if (!extension) |
565 return; | 479 return; |
566 | 480 |
567 extension_service_->UninstallExtension(extension_id_prompting_, | 481 extension_service_->UninstallExtension(extension_id_prompting_, |
568 false /* external_uninstall */, NULL); | 482 false, // External uninstall. |
483 NULL); // Error. | |
569 extension_id_prompting_ = ""; | 484 extension_id_prompting_ = ""; |
570 | 485 |
571 // There will be no EXTENSION_UNLOADED notification for terminated | 486 // There will be no EXTENSION_UNLOADED notification for terminated |
572 // extensions as they were already unloaded. | 487 // extensions as they were already unloaded. |
573 if (was_terminated) | 488 if (was_terminated) |
574 HandleRequestExtensionsData(NULL); | 489 HandleRequestExtensionsData(NULL); |
575 } | 490 } |
576 | 491 |
577 void ExtensionsDOMHandler::ExtensionDialogCanceled() { | 492 void ExtensionSettingsHandler::ExtensionDialogCanceled() { |
578 extension_id_prompting_ = ""; | 493 extension_id_prompting_ = ""; |
579 } | 494 } |
580 | 495 |
581 void ExtensionsDOMHandler::HandleOptionsMessage(const ListValue* args) { | 496 void ExtensionSettingsHandler::HandleOptionsMessage(const ListValue* args) { |
582 const Extension* extension = GetExtension(args); | 497 const Extension* extension = GetExtension(args); |
583 if (!extension || extension->options_url().is_empty()) | 498 if (!extension || extension->options_url().is_empty()) |
584 return; | 499 return; |
585 web_ui_->GetProfile()->GetExtensionProcessManager()->OpenOptionsPage( | 500 Profile::FromWebUI(web_ui_)->GetExtensionProcessManager()->OpenOptionsPage( |
586 extension, NULL); | 501 extension, NULL); |
587 } | 502 } |
588 | 503 |
589 void ExtensionsDOMHandler::HandleShowButtonMessage(const ListValue* args) { | 504 void ExtensionSettingsHandler::HandleShowButtonMessage(const ListValue* args) { |
590 const Extension* extension = GetExtension(args); | 505 const Extension* extension = GetExtension(args); |
591 extension_service_->SetBrowserActionVisibility(extension, true); | 506 extension_service_->SetBrowserActionVisibility(extension, true); |
592 } | 507 } |
593 | 508 |
594 void ExtensionsDOMHandler::HandleLoadMessage(const ListValue* args) { | 509 void ExtensionSettingsHandler::HandleLoadMessage(const ListValue* args) { |
595 FilePath::StringType string_path; | 510 FilePath::StringType string_path; |
596 CHECK(args->GetSize() == 1) << args->GetSize(); | 511 CHECK_EQ(1U, args->GetSize()) << args->GetSize(); |
597 CHECK(args->GetString(0, &string_path)); | 512 CHECK(args->GetString(0, &string_path)); |
598 extension_service_->LoadExtension(FilePath(string_path)); | 513 extension_service_->LoadExtension(FilePath(string_path)); |
599 } | 514 } |
600 | 515 |
601 void ExtensionsDOMHandler::ShowAlert(const std::string& message) { | 516 void ExtensionSettingsHandler::ShowAlert(const std::string& message) { |
602 ListValue arguments; | 517 ListValue arguments; |
603 arguments.Append(Value::CreateStringValue(message)); | 518 arguments.Append(Value::CreateStringValue(message)); |
604 web_ui_->CallJavascriptFunction(L"alert", arguments); | 519 web_ui_->CallJavascriptFunction("alert", arguments); |
605 } | 520 } |
606 | 521 |
607 void ExtensionsDOMHandler::HandlePackMessage(const ListValue* args) { | 522 void ExtensionSettingsHandler::HandleAutoUpdateMessage(const ListValue* args) { |
608 std::string extension_path; | |
609 std::string private_key_path; | |
610 CHECK(args->GetSize() == 2); | |
611 CHECK(args->GetString(0, &extension_path)); | |
612 CHECK(args->GetString(1, &private_key_path)); | |
613 | |
614 FilePath root_directory = | |
615 FilePath::FromWStringHack(UTF8ToWide(extension_path)); | |
616 FilePath key_file = FilePath::FromWStringHack(UTF8ToWide(private_key_path)); | |
617 | |
618 if (root_directory.empty()) { | |
619 if (extension_path.empty()) { | |
620 ShowAlert(l10n_util::GetStringUTF8( | |
621 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED)); | |
622 } else { | |
623 ShowAlert(l10n_util::GetStringUTF8( | |
624 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID)); | |
625 } | |
626 | |
627 return; | |
628 } | |
629 | |
630 if (!private_key_path.empty() && key_file.empty()) { | |
631 ShowAlert(l10n_util::GetStringUTF8( | |
632 IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID)); | |
633 return; | |
634 } | |
635 | |
636 pack_job_ = new PackExtensionJob(this, root_directory, key_file); | |
637 pack_job_->Start(); | |
638 } | |
639 | |
640 void ExtensionsDOMHandler::OnPackSuccess(const FilePath& crx_file, | |
641 const FilePath& pem_file) { | |
642 ShowAlert(UTF16ToUTF8(PackExtensionJob::StandardSuccessMessage(crx_file, | |
643 pem_file))); | |
644 | |
645 ListValue results; | |
646 web_ui_->CallJavascriptFunction(L"hidePackDialog", results); | |
647 } | |
648 | |
649 void ExtensionsDOMHandler::OnPackFailure(const std::string& error) { | |
650 ShowAlert(error); | |
651 } | |
652 | |
653 void ExtensionsDOMHandler::HandleAutoUpdateMessage(const ListValue* args) { | |
654 ExtensionUpdater* updater = extension_service_->updater(); | 523 ExtensionUpdater* updater = extension_service_->updater(); |
655 if (updater) | 524 if (updater) |
656 updater->CheckNow(); | 525 updater->CheckNow(); |
657 } | 526 } |
658 | 527 |
659 void ExtensionsDOMHandler::HandleSelectFilePathMessage(const ListValue* args) { | 528 void ExtensionSettingsHandler::HandleSelectFilePathMessage( |
529 const ListValue* args) { | |
660 std::string select_type; | 530 std::string select_type; |
661 std::string operation; | 531 std::string operation; |
662 CHECK(args->GetSize() == 2); | 532 CHECK_EQ(2U, args->GetSize()); |
663 CHECK(args->GetString(0, &select_type)); | 533 CHECK(args->GetString(0, &select_type)); |
664 CHECK(args->GetString(1, &operation)); | 534 CHECK(args->GetString(1, &operation)); |
665 | 535 |
666 SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER; | 536 SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER; |
667 SelectFileDialog::FileTypeInfo info; | 537 SelectFileDialog::FileTypeInfo info; |
668 int file_type_index = 0; | 538 int file_type_index = 0; |
669 if (select_type == "file") | 539 if (select_type == "file") |
670 type = SelectFileDialog::SELECT_OPEN_FILE; | 540 type = SelectFileDialog::SELECT_OPEN_FILE; |
671 | 541 |
672 string16 select_title; | 542 string16 select_title; |
(...skipping 17 matching lines...) Expand all Loading... | |
690 return; | 560 return; |
691 } | 561 } |
692 | 562 |
693 load_extension_dialog_ = SelectFileDialog::Create(this); | 563 load_extension_dialog_ = SelectFileDialog::Create(this); |
694 load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info, | 564 load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info, |
695 file_type_index, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), | 565 file_type_index, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), |
696 web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); | 566 web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); |
697 } | 567 } |
698 | 568 |
699 | 569 |
700 void ExtensionsDOMHandler::FileSelected(const FilePath& path, int index, | 570 void ExtensionSettingsHandler::FileSelected(const FilePath& path, int index, |
701 void* params) { | 571 void* params) { |
702 // Add the extensions to the results structure. | 572 // Add the extensions to the results structure. |
703 ListValue results; | 573 ListValue results; |
704 results.Append(Value::CreateStringValue(path.value())); | 574 results.Append(Value::CreateStringValue(path.value())); |
705 web_ui_->CallJavascriptFunction(L"window.handleFilePathSelected", results); | 575 web_ui_->CallJavascriptFunction("window.handleFilePathSelected", results); |
706 } | 576 } |
707 | 577 |
708 void ExtensionsDOMHandler::MultiFilesSelected( | 578 void ExtensionSettingsHandler::MultiFilesSelected( |
709 const std::vector<FilePath>& files, void* params) { | 579 const std::vector<FilePath>& files, void* params) { |
710 NOTREACHED(); | 580 NOTREACHED(); |
711 } | 581 } |
712 | 582 |
713 void ExtensionsDOMHandler::Observe(int type, | 583 void ExtensionSettingsHandler::GetLocalizedValues( |
714 const NotificationSource& source, | 584 DictionaryValue* localized_strings) { |
715 const NotificationDetails& details) { | 585 DCHECK(localized_strings); |
586 | |
587 RegisterTitle(localized_strings, "extensionSettings", | |
588 IDS_OPTIONS_GENERAL_TAB_LABEL); | |
589 | |
590 localized_strings->SetString("extensionSettingsTitle", | |
591 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE)); | |
592 localized_strings->SetString("visitWebsite", | |
593 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE)); | |
594 | |
595 localized_strings->SetString("developerMode", | |
596 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_LINK)); | |
597 localized_strings->SetString("noExtensions", | |
598 l10n_util::GetStringUTF16(IDS_EXTENSIONS_NONE_INSTALLED)); | |
599 localized_strings->SetString("suggestGallery", | |
600 l10n_util::GetStringFUTF16(IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY, | |
601 ASCIIToUTF16("<a href='") + | |
602 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( | |
603 GURL(extension_urls::GetWebstoreLaunchURL())).spec()) + | |
604 ASCIIToUTF16("'>"), | |
605 ASCIIToUTF16("</a>"))); | |
606 localized_strings->SetString("getMoreExtensions", | |
607 ASCIIToUTF16("<a href='") + | |
608 ASCIIToUTF16(google_util::AppendGoogleLocaleParam( | |
609 GURL(extension_urls::GetWebstoreLaunchURL())).spec()) + | |
610 ASCIIToUTF16("'>") + | |
611 l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS) + | |
612 ASCIIToUTF16("</a>")); | |
613 localized_strings->SetString("extensionId", | |
614 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID)); | |
615 localized_strings->SetString("extensionPath", | |
616 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PATH)); | |
617 localized_strings->SetString("inspectViews", | |
618 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); | |
619 localized_strings->SetString("enable", | |
620 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE)); | |
621 localized_strings->SetString("enabled", | |
622 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLED)); | |
623 localized_strings->SetString("remove", | |
624 l10n_util::GetStringUTF16(IDS_EXTENSIONS_REMOVE)); | |
625 localized_strings->SetString("enableIncognito", | |
626 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_INCOGNITO)); | |
627 localized_strings->SetString("allowFileAccess", | |
628 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_FILE_ACCESS)); | |
629 localized_strings->SetString("incognitoWarning", | |
630 l10n_util::GetStringFUTF16(IDS_EXTENSIONS_INCOGNITO_WARNING, | |
631 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
632 localized_strings->SetString("reload", | |
633 l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD)); | |
634 localized_strings->SetString("options", | |
635 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS)); | |
636 localized_strings->SetString("policyControlled", | |
637 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED)); | |
638 localized_strings->SetString("showButton", | |
639 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON)); | |
640 } | |
641 | |
642 void ExtensionSettingsHandler::Initialize() { | |
643 } | |
644 | |
645 WebUIMessageHandler* ExtensionSettingsHandler::Attach(WebUI* web_ui) { | |
646 // Call through to superclass. | |
647 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui); | |
648 | |
649 extension_service_ = Profile::FromWebUI(web_ui_) | |
650 ->GetOriginalProfile()->GetExtensionService(); | |
651 | |
652 // Return result from the superclass. | |
653 return handler; | |
654 } | |
655 | |
656 void ExtensionSettingsHandler::Observe(int type, | |
657 const NotificationSource& source, | |
658 const NotificationDetails& details) { | |
716 switch (type) { | 659 switch (type) { |
717 // We listen for notifications that will result in the page being | 660 // We listen for notifications that will result in the page being |
718 // repopulated with data twice for the same event in certain cases. | 661 // repopulated with data twice for the same event in certain cases. |
719 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because | 662 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because |
720 // we don't know about the views for an extension at EXTENSION_LOADED, but | 663 // we don't know about the views for an extension at EXTENSION_LOADED, but |
721 // if we only listen to EXTENSION_PROCESS_CREATED, we'll miss extensions | 664 // if we only listen to EXTENSION_PROCESS_CREATED, we'll miss extensions |
722 // that don't have a process at startup. Similarly, NAV_ENTRY_COMMITTED & | 665 // that don't have a process at startup. Similarly, NAV_ENTRY_COMMITTED & |
723 // RENDER_VIEW_HOST_CREATED because we want to handle both | 666 // RENDER_VIEW_HOST_CREATED because we want to handle both |
724 // the case of navigating from a non-extension page to an extension page in | 667 // the case of navigating from a non-extension page to an extension page in |
725 // a TabContents (which will generate NAV_ENTRY_COMMITTED) as well as | 668 // a TabContents (which will generate NAV_ENTRY_COMMITTED) as well as |
726 // extension content being shown in popups and balloons (which will generate | 669 // extension content being shown in popups and balloons (which will generate |
727 // RENDER_VIEW_CREATED but no NAV_ENTRY_COMMITTED). | 670 // RENDER_VIEW_CREATED but no NAV_ENTRY_COMMITTED). |
728 // | 671 // |
729 // Doing it this way gets everything but causes the page to be rendered | 672 // Doing it this way gets everything but causes the page to be rendered |
730 // more than we need. It doesn't seem to result in any noticeable flicker. | 673 // more than we need. It doesn't seem to result in any noticeable flicker. |
731 case chrome::RENDER_VIEW_HOST_DELETED: | 674 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: |
732 deleting_rvh_ = Details<RenderViewHost>(details).ptr(); | 675 deleting_rvh_ = Source<RenderViewHost>(source).ptr(); |
733 MaybeUpdateAfterNotification(); | 676 MaybeUpdateAfterNotification(); |
734 break; | 677 break; |
735 case chrome::BACKGROUND_CONTENTS_DELETED: | 678 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
736 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host(); | 679 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host(); |
737 MaybeUpdateAfterNotification(); | 680 MaybeUpdateAfterNotification(); |
738 break; | 681 break; |
739 case chrome::EXTENSION_LOADED: | 682 case chrome::NOTIFICATION_EXTENSION_LOADED: |
740 case chrome::EXTENSION_PROCESS_CREATED: | 683 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED: |
741 case chrome::EXTENSION_UNLOADED: | 684 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
742 case chrome::EXTENSION_UPDATE_DISABLED: | 685 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
743 case chrome::RENDER_VIEW_HOST_CREATED: | 686 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: |
744 case chrome::NAV_ENTRY_COMMITTED: | 687 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: |
745 case chrome::BACKGROUND_CONTENTS_NAVIGATED: | 688 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: |
746 case chrome::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: | 689 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
747 MaybeUpdateAfterNotification(); | 690 MaybeUpdateAfterNotification(); |
748 break; | 691 break; |
749 default: | 692 default: |
750 NOTREACHED(); | 693 NOTREACHED(); |
751 } | 694 } |
752 } | 695 } |
753 | 696 |
754 const Extension* ExtensionsDOMHandler::GetExtension(const ListValue* args) { | 697 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) { |
755 std::string extension_id = WideToASCII(ExtractStringValue(args)); | 698 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
756 CHECK(!extension_id.empty()); | 699 CHECK(!extension_id.empty()); |
757 return extension_service_->GetExtensionById(extension_id, true); | 700 return extension_service_->GetExtensionById(extension_id, true); |
758 } | 701 } |
759 | 702 |
760 void ExtensionsDOMHandler::MaybeUpdateAfterNotification() { | 703 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() { |
761 if (!ignore_notifications_ && web_ui_->tab_contents()) | 704 if (!ignore_notifications_ && web_ui_->tab_contents()) |
762 HandleRequestExtensionsData(NULL); | 705 HandleRequestExtensionsData(NULL); |
763 deleting_rvh_ = NULL; | 706 deleting_rvh_ = NULL; |
764 } | 707 } |
765 | 708 |
766 // Static | 709 // Static |
767 DictionaryValue* ExtensionsDOMHandler::CreateExtensionDetailValue( | 710 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
768 ExtensionService* service, const Extension* extension, | 711 ExtensionService* service, const Extension* extension, |
769 const std::vector<ExtensionPage>& pages, bool enabled, bool terminated) { | 712 const std::vector<ExtensionPage>& pages, bool enabled, bool terminated) { |
770 DictionaryValue* extension_data = new DictionaryValue(); | 713 DictionaryValue* extension_data = new DictionaryValue(); |
771 | 714 |
772 extension_data->SetString("id", extension->id()); | 715 extension_data->SetString("id", extension->id()); |
773 extension_data->SetString("name", extension->name()); | 716 extension_data->SetString("name", extension->name()); |
774 extension_data->SetString("description", extension->description()); | 717 extension_data->SetString("description", extension->description()); |
718 extension_data->SetString("path", extension->path().value()); | |
775 extension_data->SetString("version", extension->version()->GetString()); | 719 extension_data->SetString("version", extension->version()->GetString()); |
720 extension_data->SetBoolean("isUnpacked", | |
721 extension->location() == Extension::LOAD); | |
722 extension_data->SetBoolean("mayDisable", | |
723 Extension::UserMayDisable(extension->location())); | |
776 extension_data->SetBoolean("enabled", enabled); | 724 extension_data->SetBoolean("enabled", enabled); |
777 extension_data->SetBoolean("terminated", terminated); | 725 extension_data->SetBoolean("terminated", terminated); |
778 extension_data->SetBoolean("enabledIncognito", | 726 extension_data->SetBoolean("enabledIncognito", |
779 service ? service->IsIncognitoEnabled(extension) : false); | 727 service ? service->IsIncognitoEnabled(extension->id()) : false); |
780 extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); | 728 extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); |
781 extension_data->SetBoolean("allowFileAccess", | 729 extension_data->SetBoolean("allowFileAccess", |
782 service ? service->AllowFileAccess(extension) : false); | 730 service ? service->AllowFileAccess(extension) : false); |
783 extension_data->SetBoolean("allow_reload", | 731 extension_data->SetBoolean("allow_reload", |
784 extension->location() == Extension::LOAD); | 732 extension->location() == Extension::LOAD); |
785 extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); | 733 extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); |
786 | 734 |
787 // Determine the sort order: Extensions loaded through --load-extensions show | 735 // Determine the sort order: Extensions loaded through --load-extensions show |
788 // up at the top. Disabled extensions show up at the bottom. | 736 // up at the top. Disabled extensions show up at the bottom. |
789 if (extension->location() == Extension::LOAD) | 737 if (extension->location() == Extension::LOAD) |
790 extension_data->SetInteger("order", 1); | 738 extension_data->SetInteger("order", 1); |
791 else | 739 else |
792 extension_data->SetInteger("order", 2); | 740 extension_data->SetInteger("order", 2); |
793 | 741 |
794 if (!extension->options_url().is_empty()) | 742 if (!extension->options_url().is_empty() && enabled) |
795 extension_data->SetString("options_url", extension->options_url().spec()); | 743 extension_data->SetString("options_url", extension->options_url().spec()); |
796 | 744 |
797 if (service && !service->GetBrowserActionVisibility(extension)) | 745 if (service && !service->GetBrowserActionVisibility(extension)) |
798 extension_data->SetBoolean("enable_show_button", true); | 746 extension_data->SetBoolean("enable_show_button", true); |
799 | 747 |
800 // Add views | 748 // Add views |
801 ListValue* views = new ListValue; | 749 ListValue* views = new ListValue; |
802 for (std::vector<ExtensionPage>::const_iterator iter = pages.begin(); | 750 for (std::vector<ExtensionPage>::const_iterator iter = pages.begin(); |
803 iter != pages.end(); ++iter) { | 751 iter != pages.end(); ++iter) { |
804 DictionaryValue* view_value = new DictionaryValue; | 752 DictionaryValue* view_value = new DictionaryValue; |
(...skipping 10 matching lines...) Expand all Loading... | |
815 views->Append(view_value); | 763 views->Append(view_value); |
816 } | 764 } |
817 extension_data->Set("views", views); | 765 extension_data->Set("views", views); |
818 extension_data->SetBoolean("hasPopupAction", | 766 extension_data->SetBoolean("hasPopupAction", |
819 extension->browser_action() || extension->page_action()); | 767 extension->browser_action() || extension->page_action()); |
820 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); | 768 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); |
821 | 769 |
822 return extension_data; | 770 return extension_data; |
823 } | 771 } |
824 | 772 |
825 std::vector<ExtensionPage> ExtensionsDOMHandler::GetActivePagesForExtension( | 773 std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension( |
826 const Extension* extension) { | 774 const Extension* extension) { |
827 std::vector<ExtensionPage> result; | 775 std::vector<ExtensionPage> result; |
828 | 776 |
829 // Get the extension process's active views. | 777 // Get the extension process's active views. |
830 ExtensionProcessManager* process_manager = | 778 ExtensionProcessManager* process_manager = |
831 extension_service_->profile()->GetExtensionProcessManager(); | 779 extension_service_->profile()->GetExtensionProcessManager(); |
832 GetActivePagesForExtensionProcess( | 780 GetActivePagesForExtensionProcess( |
833 process_manager->GetExtensionProcess(extension->url()), | 781 process_manager->GetExtensionProcess(extension->url()), |
834 extension, &result); | 782 extension, &result); |
835 | 783 |
836 // Repeat for the incognito process, if applicable. | 784 // Repeat for the incognito process, if applicable. |
837 if (extension_service_->profile()->HasOffTheRecordProfile() && | 785 if (extension_service_->profile()->HasOffTheRecordProfile() && |
838 extension->incognito_split_mode()) { | 786 extension->incognito_split_mode()) { |
839 ExtensionProcessManager* process_manager = | 787 ExtensionProcessManager* process_manager = |
840 extension_service_->profile()->GetOffTheRecordProfile()-> | 788 extension_service_->profile()->GetOffTheRecordProfile()-> |
841 GetExtensionProcessManager(); | 789 GetExtensionProcessManager(); |
842 GetActivePagesForExtensionProcess( | 790 GetActivePagesForExtensionProcess( |
843 process_manager->GetExtensionProcess(extension->url()), | 791 process_manager->GetExtensionProcess(extension->url()), |
844 extension, &result); | 792 extension, &result); |
845 } | 793 } |
846 | 794 |
847 return result; | 795 return result; |
848 } | 796 } |
849 | 797 |
850 void ExtensionsDOMHandler::GetActivePagesForExtensionProcess( | 798 void ExtensionSettingsHandler::GetActivePagesForExtensionProcess( |
851 RenderProcessHost* process, | 799 RenderProcessHost* process, |
852 const Extension* extension, | 800 const Extension* extension, |
853 std::vector<ExtensionPage> *result) { | 801 std::vector<ExtensionPage> *result) { |
854 if (!process) | 802 if (!process) |
855 return; | 803 return; |
856 | 804 |
857 RenderProcessHost::listeners_iterator iter = process->ListenersIterator(); | 805 RenderProcessHost::listeners_iterator iter = process->ListenersIterator(); |
858 for (; !iter.IsAtEnd(); iter.Advance()) { | 806 for (; !iter.IsAtEnd(); iter.Advance()) { |
859 const RenderWidgetHost* widget = | 807 const RenderWidgetHost* widget = |
860 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue()); | 808 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue()); |
861 DCHECK(widget); | 809 DCHECK(widget); |
862 if (!widget || !widget->IsRenderView()) | 810 if (!widget || !widget->IsRenderView()) |
863 continue; | 811 continue; |
864 const RenderViewHost* host = static_cast<const RenderViewHost*>(widget); | 812 const RenderViewHost* host = static_cast<const RenderViewHost*>(widget); |
865 if (host == deleting_rvh_ || | 813 if (host == deleting_rvh_ || |
866 ViewType::EXTENSION_POPUP == host->delegate()->GetRenderViewType() || | 814 ViewType::EXTENSION_POPUP == host->delegate()->GetRenderViewType() || |
867 ViewType::EXTENSION_DIALOG == host->delegate()->GetRenderViewType()) | 815 ViewType::EXTENSION_DIALOG == host->delegate()->GetRenderViewType()) |
868 continue; | 816 continue; |
869 | 817 |
870 GURL url = host->delegate()->GetURL(); | 818 GURL url = host->delegate()->GetURL(); |
871 if (url.SchemeIs(chrome::kExtensionScheme)) { | 819 if (url.SchemeIs(chrome::kExtensionScheme)) { |
872 if (url.host() != extension->id()) | 820 if (url.host() != extension->id()) |
873 continue; | 821 continue; |
874 } else if (!extension->web_extent().MatchesURL(url)) { | 822 } else if (!extension->web_extent().MatchesURL(url)) { |
875 continue; | 823 continue; |
876 } | 824 } |
877 | 825 |
878 result->push_back(ExtensionPage(url, process->id(), host->routing_id(), | 826 result->push_back( |
879 process->profile()->IsOffTheRecord())); | 827 ExtensionPage(url, process->id(), host->routing_id(), |
828 process->browser_context()->IsOffTheRecord())); | |
880 } | 829 } |
881 } | 830 } |
882 | |
883 ExtensionsDOMHandler::~ExtensionsDOMHandler() { | |
884 // There may be pending file dialogs, we need to tell them that we've gone | |
885 // away so they don't try and call back to us. | |
886 if (load_extension_dialog_.get()) | |
887 load_extension_dialog_->ListenerDestroyed(); | |
888 | |
889 if (pack_job_.get()) | |
890 pack_job_->ClearClient(); | |
891 | |
892 if (icon_loader_.get()) | |
893 icon_loader_->Cancel(); | |
894 } | |
895 | |
896 // ExtensionsDOMHandler, public: ----------------------------------------------- | |
897 | |
898 ExtensionsUI::ExtensionsUI(TabContents* contents) : ChromeWebUI(contents) { | |
899 ExtensionService *exstension_service = | |
900 GetProfile()->GetOriginalProfile()->GetExtensionService(); | |
901 | |
902 ExtensionsDOMHandler* handler = new ExtensionsDOMHandler(exstension_service); | |
903 AddMessageHandler(handler); | |
904 handler->Attach(this); | |
905 | |
906 ExtensionsUIHTMLSource* html_source = new ExtensionsUIHTMLSource(); | |
907 | |
908 // Set up the chrome://extensions/ source. | |
909 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | |
910 } | |
911 | |
912 // static | |
913 RefCountedMemory* ExtensionsUI::GetFaviconResourceBytes() { | |
914 return ResourceBundle::GetSharedInstance(). | |
915 LoadDataResourceBytes(IDR_PLUGIN); | |
916 } | |
917 | |
918 // static | |
919 void ExtensionsUI::RegisterUserPrefs(PrefService* prefs) { | |
920 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, | |
921 false, | |
922 PrefService::SYNCABLE_PREF); | |
923 } | |
OLD | NEW |