Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: chrome/browser/ui/webui/options/extension_settings_handler.cc

Issue 7794023: Convert chrome://extensions to a settings page within the options pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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("extensionSettingsRequestExtensionsData",
183 NewCallback(this,
184 &ExtensionSettingsHandler::HandleRequestExtensionsData));
185 web_ui_->RegisterMessageCallback("extensionSettingsToggleDeveloperMode",
186 NewCallback(this, &ExtensionSettingsHandler::HandleToggleDeveloperMode));
187 web_ui_->RegisterMessageCallback("extensionSettingsInspect",
188 NewCallback(this, &ExtensionSettingsHandler::HandleInspectMessage));
189 web_ui_->RegisterMessageCallback("extensionSettingsReload",
190 NewCallback(this, &ExtensionSettingsHandler::HandleReloadMessage));
191 web_ui_->RegisterMessageCallback("extensionSettingsEnable",
192 NewCallback(this,
193 &ExtensionSettingsHandler::HandleEnableMessage));
194 web_ui_->RegisterMessageCallback("extensionSettingsEnableIncognito",
195 NewCallback(this,
196 &ExtensionSettingsHandler::HandleEnableIncognitoMessage));
197 web_ui_->RegisterMessageCallback("extensionSettingsAllowFileAccess",
198 NewCallback(this,
199 &ExtensionSettingsHandler::HandleAllowFileAccessMessage));
200 web_ui_->RegisterMessageCallback("extensionSettingsUninstall",
201 NewCallback(this, &ExtensionSettingsHandler::HandleUninstallMessage));
202 web_ui_->RegisterMessageCallback("extensionSettingsOptions",
203 NewCallback(this, &ExtensionSettingsHandler::HandleOptionsMessage));
204 web_ui_->RegisterMessageCallback("extensionSettingsShowButton",
205 NewCallback(this, &ExtensionSettingsHandler::HandleShowButtonMessage));
206 web_ui_->RegisterMessageCallback("extensionSettingsLoad",
207 NewCallback(this, &ExtensionSettingsHandler::HandleLoadMessage));
208 web_ui_->RegisterMessageCallback("extensionSettingsAutoupdate",
209 NewCallback(this, &ExtensionSettingsHandler::HandleAutoUpdateMessage));
210 web_ui_->RegisterMessageCallback("extensionSettingsSelectFilePath",
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 if (!Extension::UserMayDisable(extension->location())) {
374 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable was"
375 << "made. Extension id: " << extension->id();
376 return;
377 }
378
480 if (enable_str == "true") { 379 if (enable_str == "true") {
481 ExtensionPrefs* prefs = extension_service_->extension_prefs(); 380 ExtensionPrefs* prefs = extension_service_->extension_prefs();
482 if (prefs->DidExtensionEscalatePermissions(extension_id)) { 381 if (prefs->DidExtensionEscalatePermissions(extension_id)) {
483 const Extension* extension =
484 extension_service_->GetExtensionById(extension_id, true);
485 ShowExtensionDisabledDialog(extension_service_, 382 ShowExtensionDisabledDialog(extension_service_,
486 web_ui_->GetProfile(), extension); 383 Profile::FromWebUI(web_ui_), extension);
487 } else { 384 } else {
488 extension_service_->EnableExtension(extension_id); 385 extension_service_->EnableExtension(extension_id);
489 } 386 }
490 } else { 387 } else {
491 extension_service_->DisableExtension(extension_id); 388 extension_service_->DisableExtension(extension_id);
492 } 389 }
493 } 390 }
494 391
495 void ExtensionsDOMHandler::HandleEnableIncognitoMessage(const ListValue* args) { 392 void ExtensionSettingsHandler::HandleEnableIncognitoMessage(
496 CHECK(args->GetSize() == 2); 393 const ListValue* args) {
394 CHECK_EQ(2U, args->GetSize());
497 std::string extension_id, enable_str; 395 std::string extension_id, enable_str;
498 CHECK(args->GetString(0, &extension_id)); 396 CHECK(args->GetString(0, &extension_id));
499 CHECK(args->GetString(1, &enable_str)); 397 CHECK(args->GetString(1, &enable_str));
500 const Extension* extension = 398 const Extension* extension =
501 extension_service_->GetExtensionById(extension_id, true); 399 extension_service_->GetExtensionById(extension_id, true);
502 DCHECK(extension); 400 DCHECK(extension);
503 401
504 // Flipping the incognito bit will generate unload/load notifications for the 402 // 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 403 // 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 404 // 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. 405 // text to stay until the user has left the page.
508 // 406 //
509 // TODO(aa): This creates crapiness in some cases. For example, in a main 407 // 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 408 // window, when toggling this, the browser action will flicker because it gets
511 // unloaded, then reloaded. It would be better to have a dedicated 409 // unloaded, then reloaded. It would be better to have a dedicated
512 // notification for this case. 410 // notification for this case.
513 // 411 //
514 // Bug: http://crbug.com/41384 412 // Bug: http://crbug.com/41384
515 ignore_notifications_ = true; 413 ignore_notifications_ = true;
516 extension_service_->SetIsIncognitoEnabled(extension, enable_str == "true"); 414 extension_service_->SetIsIncognitoEnabled(extension->id(),
415 enable_str == "true");
517 ignore_notifications_ = false; 416 ignore_notifications_ = false;
518 } 417 }
519 418
520 void ExtensionsDOMHandler::HandleAllowFileAccessMessage(const ListValue* args) { 419 void ExtensionSettingsHandler::HandleAllowFileAccessMessage(
521 CHECK(args->GetSize() == 2); 420 const ListValue* args) {
421 CHECK_EQ(2U, args->GetSize());
522 std::string extension_id, allow_str; 422 std::string extension_id, allow_str;
523 CHECK(args->GetString(0, &extension_id)); 423 CHECK(args->GetString(0, &extension_id));
524 CHECK(args->GetString(1, &allow_str)); 424 CHECK(args->GetString(1, &allow_str));
525 const Extension* extension = 425 const Extension* extension =
526 extension_service_->GetExtensionById(extension_id, true); 426 extension_service_->GetExtensionById(extension_id, true);
527 DCHECK(extension); 427 DCHECK(extension);
528 428
429 if (!Extension::UserMayDisable(extension->location())) {
430 LOG(ERROR) << "Attempt to change allow file access of an extension that is "
431 << "non-usermanagable was made. Extension id : "
432 << extension->id();
433 return;
434 }
435
529 extension_service_->SetAllowFileAccess(extension, allow_str == "true"); 436 extension_service_->SetAllowFileAccess(extension, allow_str == "true");
530 } 437 }
531 438
532 void ExtensionsDOMHandler::HandleUninstallMessage(const ListValue* args) { 439 void ExtensionSettingsHandler::HandleUninstallMessage(const ListValue* args) {
533 std::string extension_id = WideToASCII(ExtractStringValue(args)); 440 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args));
534 CHECK(!extension_id.empty()); 441 CHECK(!extension_id.empty());
535 const Extension* extension = 442 const Extension* extension =
536 extension_service_->GetExtensionById(extension_id, true); 443 extension_service_->GetExtensionById(extension_id, true);
537 if (!extension) 444 if (!extension)
538 extension = extension_service_->GetTerminatedExtension(extension_id); 445 extension = extension_service_->GetTerminatedExtension(extension_id);
539 if (!extension) 446 if (!extension)
540 return; 447 return;
541 448
449 if (!Extension::UserMayDisable(extension->location())) {
450 LOG(ERROR) << "Attempt to uninstall an extension that is non-usermanagable "
451 << "was made. Extension id : " << extension->id();
452 return;
453 }
454
542 if (!extension_id_prompting_.empty()) 455 if (!extension_id_prompting_.empty())
543 return; // Only one prompt at a time. 456 return; // Only one prompt at a time.
544 457
545 extension_id_prompting_ = extension_id; 458 extension_id_prompting_ = extension_id;
546 459
547 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension); 460 GetExtensionUninstallDialog()->ConfirmUninstall(this, extension);
548 } 461 }
549 462
550 void ExtensionsDOMHandler::ExtensionDialogAccepted() { 463 void ExtensionSettingsHandler::ExtensionDialogAccepted() {
551 DCHECK(!extension_id_prompting_.empty()); 464 DCHECK(!extension_id_prompting_.empty());
552 465
553 bool was_terminated = false; 466 bool was_terminated = false;
554 467
555 // The extension can be uninstalled in another window while the UI was 468 // The extension can be uninstalled in another window while the UI was
556 // showing. Do nothing in that case. 469 // showing. Do nothing in that case.
557 const Extension* extension = 470 const Extension* extension =
558 extension_service_->GetExtensionById(extension_id_prompting_, true); 471 extension_service_->GetExtensionById(extension_id_prompting_, true);
559 if (!extension) { 472 if (!extension) {
560 extension = extension_service_->GetTerminatedExtension( 473 extension = extension_service_->GetTerminatedExtension(
561 extension_id_prompting_); 474 extension_id_prompting_);
562 was_terminated = true; 475 was_terminated = true;
563 } 476 }
564 if (!extension) 477 if (!extension)
565 return; 478 return;
566 479
567 extension_service_->UninstallExtension(extension_id_prompting_, 480 extension_service_->UninstallExtension(extension_id_prompting_,
568 false /* external_uninstall */, NULL); 481 false, // External uninstall.
482 NULL); // Error.
569 extension_id_prompting_ = ""; 483 extension_id_prompting_ = "";
570 484
571 // There will be no EXTENSION_UNLOADED notification for terminated 485 // There will be no EXTENSION_UNLOADED notification for terminated
572 // extensions as they were already unloaded. 486 // extensions as they were already unloaded.
573 if (was_terminated) 487 if (was_terminated)
574 HandleRequestExtensionsData(NULL); 488 HandleRequestExtensionsData(NULL);
575 } 489 }
576 490
577 void ExtensionsDOMHandler::ExtensionDialogCanceled() { 491 void ExtensionSettingsHandler::ExtensionDialogCanceled() {
578 extension_id_prompting_ = ""; 492 extension_id_prompting_ = "";
579 } 493 }
580 494
581 void ExtensionsDOMHandler::HandleOptionsMessage(const ListValue* args) { 495 void ExtensionSettingsHandler::HandleOptionsMessage(const ListValue* args) {
582 const Extension* extension = GetExtension(args); 496 const Extension* extension = GetExtension(args);
583 if (!extension || extension->options_url().is_empty()) 497 if (!extension || extension->options_url().is_empty())
584 return; 498 return;
585 web_ui_->GetProfile()->GetExtensionProcessManager()->OpenOptionsPage( 499 Profile::FromWebUI(web_ui_)->GetExtensionProcessManager()->OpenOptionsPage(
586 extension, NULL); 500 extension, NULL);
587 } 501 }
588 502
589 void ExtensionsDOMHandler::HandleShowButtonMessage(const ListValue* args) { 503 void ExtensionSettingsHandler::HandleShowButtonMessage(const ListValue* args) {
590 const Extension* extension = GetExtension(args); 504 const Extension* extension = GetExtension(args);
591 extension_service_->SetBrowserActionVisibility(extension, true); 505 extension_service_->SetBrowserActionVisibility(extension, true);
592 } 506 }
593 507
594 void ExtensionsDOMHandler::HandleLoadMessage(const ListValue* args) { 508 void ExtensionSettingsHandler::HandleLoadMessage(const ListValue* args) {
595 FilePath::StringType string_path; 509 FilePath::StringType string_path;
596 CHECK(args->GetSize() == 1) << args->GetSize(); 510 CHECK_EQ(1U, args->GetSize()) << args->GetSize();
597 CHECK(args->GetString(0, &string_path)); 511 CHECK(args->GetString(0, &string_path));
598 extension_service_->LoadExtension(FilePath(string_path)); 512 extension_service_->LoadExtension(FilePath(string_path));
599 } 513 }
600 514
601 void ExtensionsDOMHandler::ShowAlert(const std::string& message) { 515 void ExtensionSettingsHandler::ShowAlert(const std::string& message) {
602 ListValue arguments; 516 ListValue arguments;
603 arguments.Append(Value::CreateStringValue(message)); 517 arguments.Append(Value::CreateStringValue(message));
604 web_ui_->CallJavascriptFunction(L"alert", arguments); 518 web_ui_->CallJavascriptFunction("alert", arguments);
605 } 519 }
606 520
607 void ExtensionsDOMHandler::HandlePackMessage(const ListValue* args) { 521 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(); 522 ExtensionUpdater* updater = extension_service_->updater();
655 if (updater) 523 if (updater)
656 updater->CheckNow(); 524 updater->CheckNow();
657 } 525 }
658 526
659 void ExtensionsDOMHandler::HandleSelectFilePathMessage(const ListValue* args) { 527 void ExtensionSettingsHandler::HandleSelectFilePathMessage(
528 const ListValue* args) {
660 std::string select_type; 529 std::string select_type;
661 std::string operation; 530 std::string operation;
662 CHECK(args->GetSize() == 2); 531 CHECK_EQ(2U, args->GetSize());
663 CHECK(args->GetString(0, &select_type)); 532 CHECK(args->GetString(0, &select_type));
664 CHECK(args->GetString(1, &operation)); 533 CHECK(args->GetString(1, &operation));
665 534
666 SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER; 535 SelectFileDialog::Type type = SelectFileDialog::SELECT_FOLDER;
667 SelectFileDialog::FileTypeInfo info; 536 SelectFileDialog::FileTypeInfo info;
668 int file_type_index = 0; 537 int file_type_index = 0;
669 if (select_type == "file") 538 if (select_type == "file")
670 type = SelectFileDialog::SELECT_OPEN_FILE; 539 type = SelectFileDialog::SELECT_OPEN_FILE;
671 540
672 string16 select_title; 541 string16 select_title;
(...skipping 17 matching lines...) Expand all
690 return; 559 return;
691 } 560 }
692 561
693 load_extension_dialog_ = SelectFileDialog::Create(this); 562 load_extension_dialog_ = SelectFileDialog::Create(this);
694 load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info, 563 load_extension_dialog_->SelectFile(type, select_title, FilePath(), &info,
695 file_type_index, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), 564 file_type_index, FILE_PATH_LITERAL(""), web_ui_->tab_contents(),
696 web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); 565 web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL);
697 } 566 }
698 567
699 568
700 void ExtensionsDOMHandler::FileSelected(const FilePath& path, int index, 569 void ExtensionSettingsHandler::FileSelected(const FilePath& path, int index,
701 void* params) { 570 void* params) {
702 // Add the extensions to the results structure. 571 // Add the extensions to the results structure.
703 ListValue results; 572 ListValue results;
704 results.Append(Value::CreateStringValue(path.value())); 573 results.Append(Value::CreateStringValue(path.value()));
705 web_ui_->CallJavascriptFunction(L"window.handleFilePathSelected", results); 574 web_ui_->CallJavascriptFunction("window.handleFilePathSelected", results);
706 } 575 }
707 576
708 void ExtensionsDOMHandler::MultiFilesSelected( 577 void ExtensionSettingsHandler::MultiFilesSelected(
709 const std::vector<FilePath>& files, void* params) { 578 const std::vector<FilePath>& files, void* params) {
710 NOTREACHED(); 579 NOTREACHED();
711 } 580 }
712 581
713 void ExtensionsDOMHandler::Observe(int type, 582 void ExtensionSettingsHandler::GetLocalizedValues(
714 const NotificationSource& source, 583 DictionaryValue* localized_strings) {
715 const NotificationDetails& details) { 584 DCHECK(localized_strings);
585
586 RegisterTitle(localized_strings, "extensionSettings",
587 IDS_OPTIONS_GENERAL_TAB_LABEL);
588
589 localized_strings->SetString("extensionSettingsTitle",
590 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE));
591 localized_strings->SetString("extensionSettingsVisitWebsite",
592 l10n_util::GetStringUTF16(IDS_EXTENSIONS_VISIT_WEBSITE));
593
594 localized_strings->SetString("extensionSettingsDeveloperMode",
595 l10n_util::GetStringUTF16(IDS_EXTENSIONS_DEVELOPER_MODE_LINK));
596 localized_strings->SetString("extensionSettingsNoExtensions",
597 l10n_util::GetStringUTF16(IDS_EXTENSIONS_NONE_INSTALLED));
598 localized_strings->SetString("extensionSettingsSuggestGallery",
599 l10n_util::GetStringFUTF16(IDS_EXTENSIONS_NONE_INSTALLED_SUGGEST_GALLERY,
600 ASCIIToUTF16("<a href='") +
601 ASCIIToUTF16(google_util::AppendGoogleLocaleParam(
602 GURL(extension_urls::GetWebstoreLaunchURL())).spec()) +
603 ASCIIToUTF16("'>"),
604 ASCIIToUTF16("</a>")));
605 localized_strings->SetString("extensionSettingsGetMoreExtensions",
606 ASCIIToUTF16("<a href='") +
607 ASCIIToUTF16(google_util::AppendGoogleLocaleParam(
608 GURL(extension_urls::GetWebstoreLaunchURL())).spec()) +
609 ASCIIToUTF16("'>") +
610 l10n_util::GetStringUTF16(IDS_GET_MORE_EXTENSIONS) +
611 ASCIIToUTF16("</a>"));
612 localized_strings->SetString("extensionSettingsExtensionId",
613 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ID));
614 localized_strings->SetString("extensionSettingsExtensionPath",
615 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PATH));
616 localized_strings->SetString("extensionSettingsInspectViews",
617 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS));
618 localized_strings->SetString("extensionSettingsEnable",
619 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE));
620 localized_strings->SetString("extensionSettingsEnabled",
621 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLED));
622 localized_strings->SetString("extensionSettingsRemove",
623 l10n_util::GetStringUTF16(IDS_EXTENSIONS_REMOVE));
624 localized_strings->SetString("extensionSettingsEnableIncognito",
625 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE_INCOGNITO));
626 localized_strings->SetString("extensionSettingsAllowFileAccess",
627 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ALLOW_FILE_ACCESS));
628 localized_strings->SetString("extensionSettingsIncognitoWarning",
629 l10n_util::GetStringFUTF16(IDS_EXTENSIONS_INCOGNITO_WARNING,
630 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
631 localized_strings->SetString("extensionSettingsReload",
632 l10n_util::GetStringUTF16(IDS_EXTENSIONS_RELOAD));
633 localized_strings->SetString("extensionSettingsOptions",
634 l10n_util::GetStringUTF16(IDS_EXTENSIONS_OPTIONS));
635 localized_strings->SetString("extensionSettingsPolicyControlled",
636 l10n_util::GetStringUTF16(IDS_EXTENSIONS_POLICY_CONTROLLED));
637 localized_strings->SetString("extensionSettingsShowButton",
638 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_BUTTON));
639 localized_strings->SetString("extensionSettingsLoadUnpackedButton",
640 l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOAD_UNPACKED_BUTTON));
641 localized_strings->SetString("extensionSettingsPackButton",
642 l10n_util::GetStringUTF16(IDS_EXTENSIONS_PACK_BUTTON));
643 localized_strings->SetString("extensionSettingsUpdateButton",
644 l10n_util::GetStringUTF16(IDS_EXTENSIONS_UPDATE_BUTTON));
645 }
646
647 void ExtensionSettingsHandler::Initialize() {
648 }
649
650 WebUIMessageHandler* ExtensionSettingsHandler::Attach(WebUI* web_ui) {
651 // Call through to superclass.
652 WebUIMessageHandler* handler = OptionsPageUIHandler::Attach(web_ui);
653
654 extension_service_ = Profile::FromWebUI(web_ui_)
655 ->GetOriginalProfile()->GetExtensionService();
656
657 // Return result from the superclass.
658 return handler;
659 }
660
661 void ExtensionSettingsHandler::Observe(int type,
662 const NotificationSource& source,
663 const NotificationDetails& details) {
716 switch (type) { 664 switch (type) {
717 // We listen for notifications that will result in the page being 665 // We listen for notifications that will result in the page being
718 // repopulated with data twice for the same event in certain cases. 666 // repopulated with data twice for the same event in certain cases.
719 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because 667 // For instance, EXTENSION_LOADED & EXTENSION_PROCESS_CREATED because
720 // we don't know about the views for an extension at EXTENSION_LOADED, but 668 // 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 669 // 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 & 670 // that don't have a process at startup. Similarly, NAV_ENTRY_COMMITTED &
723 // RENDER_VIEW_HOST_CREATED because we want to handle both 671 // 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 672 // 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 673 // a TabContents (which will generate NAV_ENTRY_COMMITTED) as well as
726 // extension content being shown in popups and balloons (which will generate 674 // extension content being shown in popups and balloons (which will generate
727 // RENDER_VIEW_CREATED but no NAV_ENTRY_COMMITTED). 675 // RENDER_VIEW_CREATED but no NAV_ENTRY_COMMITTED).
728 // 676 //
729 // Doing it this way gets everything but causes the page to be rendered 677 // 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. 678 // more than we need. It doesn't seem to result in any noticeable flicker.
731 case chrome::RENDER_VIEW_HOST_DELETED: 679 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED:
732 deleting_rvh_ = Details<RenderViewHost>(details).ptr(); 680 deleting_rvh_ = Source<RenderViewHost>(source).ptr();
733 MaybeUpdateAfterNotification(); 681 MaybeUpdateAfterNotification();
734 break; 682 break;
735 case chrome::BACKGROUND_CONTENTS_DELETED: 683 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED:
736 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host(); 684 deleting_rvh_ = Details<BackgroundContents>(details)->render_view_host();
737 MaybeUpdateAfterNotification(); 685 MaybeUpdateAfterNotification();
738 break; 686 break;
739 case chrome::EXTENSION_LOADED: 687 case chrome::NOTIFICATION_EXTENSION_LOADED:
740 case chrome::EXTENSION_PROCESS_CREATED: 688 case chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED:
741 case chrome::EXTENSION_UNLOADED: 689 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
742 case chrome::EXTENSION_UPDATE_DISABLED: 690 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
743 case chrome::RENDER_VIEW_HOST_CREATED: 691 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED:
744 case chrome::NAV_ENTRY_COMMITTED: 692 case content::NOTIFICATION_NAV_ENTRY_COMMITTED:
745 case chrome::BACKGROUND_CONTENTS_NAVIGATED: 693 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED:
746 case chrome::EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: 694 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED:
747 MaybeUpdateAfterNotification(); 695 MaybeUpdateAfterNotification();
748 break; 696 break;
749 default: 697 default:
750 NOTREACHED(); 698 NOTREACHED();
751 } 699 }
752 } 700 }
753 701
754 const Extension* ExtensionsDOMHandler::GetExtension(const ListValue* args) { 702 const Extension* ExtensionSettingsHandler::GetExtension(const ListValue* args) {
755 std::string extension_id = WideToASCII(ExtractStringValue(args)); 703 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args));
756 CHECK(!extension_id.empty()); 704 CHECK(!extension_id.empty());
757 return extension_service_->GetExtensionById(extension_id, true); 705 return extension_service_->GetExtensionById(extension_id, true);
758 } 706 }
759 707
760 void ExtensionsDOMHandler::MaybeUpdateAfterNotification() { 708 void ExtensionSettingsHandler::MaybeUpdateAfterNotification() {
761 if (!ignore_notifications_ && web_ui_->tab_contents()) 709 if (!ignore_notifications_ && web_ui_->tab_contents())
762 HandleRequestExtensionsData(NULL); 710 HandleRequestExtensionsData(NULL);
763 deleting_rvh_ = NULL; 711 deleting_rvh_ = NULL;
764 } 712 }
765 713
766 // Static 714 // Static
767 DictionaryValue* ExtensionsDOMHandler::CreateExtensionDetailValue( 715 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue(
768 ExtensionService* service, const Extension* extension, 716 ExtensionService* service, const Extension* extension,
769 const std::vector<ExtensionPage>& pages, bool enabled, bool terminated) { 717 const std::vector<ExtensionPage>& pages, bool enabled, bool terminated) {
770 DictionaryValue* extension_data = new DictionaryValue(); 718 DictionaryValue* extension_data = new DictionaryValue();
771 719
772 extension_data->SetString("id", extension->id()); 720 extension_data->SetString("id", extension->id());
773 extension_data->SetString("name", extension->name()); 721 extension_data->SetString("name", extension->name());
774 extension_data->SetString("description", extension->description()); 722 extension_data->SetString("description", extension->description());
723 extension_data->SetString("path", extension->path().value());
775 extension_data->SetString("version", extension->version()->GetString()); 724 extension_data->SetString("version", extension->version()->GetString());
725 extension_data->SetBoolean("isUnpacked",
726 extension->location() == Extension::LOAD);
727 extension_data->SetBoolean("mayDisable",
728 Extension::UserMayDisable(extension->location()));
776 extension_data->SetBoolean("enabled", enabled); 729 extension_data->SetBoolean("enabled", enabled);
777 extension_data->SetBoolean("terminated", terminated); 730 extension_data->SetBoolean("terminated", terminated);
778 extension_data->SetBoolean("enabledIncognito", 731 extension_data->SetBoolean("enabledIncognito",
779 service ? service->IsIncognitoEnabled(extension) : false); 732 service ? service->IsIncognitoEnabled(extension->id()) : false);
780 extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access()); 733 extension_data->SetBoolean("wantsFileAccess", extension->wants_file_access());
781 extension_data->SetBoolean("allowFileAccess", 734 extension_data->SetBoolean("allowFileAccess",
782 service ? service->AllowFileAccess(extension) : false); 735 service ? service->AllowFileAccess(extension) : false);
783 extension_data->SetBoolean("allow_reload", 736 extension_data->SetBoolean("allow_reload",
784 extension->location() == Extension::LOAD); 737 extension->location() == Extension::LOAD);
785 extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app()); 738 extension_data->SetBoolean("is_hosted_app", extension->is_hosted_app());
786 739
787 // Determine the sort order: Extensions loaded through --load-extensions show 740 // Determine the sort order: Extensions loaded through --load-extensions show
788 // up at the top. Disabled extensions show up at the bottom. 741 // up at the top. Disabled extensions show up at the bottom.
789 if (extension->location() == Extension::LOAD) 742 if (extension->location() == Extension::LOAD)
790 extension_data->SetInteger("order", 1); 743 extension_data->SetInteger("order", 1);
791 else 744 else
792 extension_data->SetInteger("order", 2); 745 extension_data->SetInteger("order", 2);
793 746
794 if (!extension->options_url().is_empty()) 747 if (!extension->options_url().is_empty() && enabled)
795 extension_data->SetString("options_url", extension->options_url().spec()); 748 extension_data->SetString("options_url", extension->options_url().spec());
796 749
797 if (service && !service->GetBrowserActionVisibility(extension)) 750 if (service && !service->GetBrowserActionVisibility(extension))
798 extension_data->SetBoolean("enable_show_button", true); 751 extension_data->SetBoolean("enable_show_button", true);
799 752
800 // Add views 753 // Add views
801 ListValue* views = new ListValue; 754 ListValue* views = new ListValue;
802 for (std::vector<ExtensionPage>::const_iterator iter = pages.begin(); 755 for (std::vector<ExtensionPage>::const_iterator iter = pages.begin();
803 iter != pages.end(); ++iter) { 756 iter != pages.end(); ++iter) {
804 DictionaryValue* view_value = new DictionaryValue; 757 DictionaryValue* view_value = new DictionaryValue;
(...skipping 10 matching lines...) Expand all
815 views->Append(view_value); 768 views->Append(view_value);
816 } 769 }
817 extension_data->Set("views", views); 770 extension_data->Set("views", views);
818 extension_data->SetBoolean("hasPopupAction", 771 extension_data->SetBoolean("hasPopupAction",
819 extension->browser_action() || extension->page_action()); 772 extension->browser_action() || extension->page_action());
820 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec()); 773 extension_data->SetString("homepageUrl", extension->GetHomepageURL().spec());
821 774
822 return extension_data; 775 return extension_data;
823 } 776 }
824 777
825 std::vector<ExtensionPage> ExtensionsDOMHandler::GetActivePagesForExtension( 778 std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension(
826 const Extension* extension) { 779 const Extension* extension) {
827 std::vector<ExtensionPage> result; 780 std::vector<ExtensionPage> result;
828 781
829 // Get the extension process's active views. 782 // Get the extension process's active views.
830 ExtensionProcessManager* process_manager = 783 ExtensionProcessManager* process_manager =
831 extension_service_->profile()->GetExtensionProcessManager(); 784 extension_service_->profile()->GetExtensionProcessManager();
832 GetActivePagesForExtensionProcess( 785 GetActivePagesForExtensionProcess(
833 process_manager->GetExtensionProcess(extension->url()), 786 process_manager->GetExtensionProcess(extension->url()),
834 extension, &result); 787 extension, &result);
835 788
836 // Repeat for the incognito process, if applicable. 789 // Repeat for the incognito process, if applicable.
837 if (extension_service_->profile()->HasOffTheRecordProfile() && 790 if (extension_service_->profile()->HasOffTheRecordProfile() &&
838 extension->incognito_split_mode()) { 791 extension->incognito_split_mode()) {
839 ExtensionProcessManager* process_manager = 792 ExtensionProcessManager* process_manager =
840 extension_service_->profile()->GetOffTheRecordProfile()-> 793 extension_service_->profile()->GetOffTheRecordProfile()->
841 GetExtensionProcessManager(); 794 GetExtensionProcessManager();
842 GetActivePagesForExtensionProcess( 795 GetActivePagesForExtensionProcess(
843 process_manager->GetExtensionProcess(extension->url()), 796 process_manager->GetExtensionProcess(extension->url()),
844 extension, &result); 797 extension, &result);
845 } 798 }
846 799
847 return result; 800 return result;
848 } 801 }
849 802
850 void ExtensionsDOMHandler::GetActivePagesForExtensionProcess( 803 void ExtensionSettingsHandler::GetActivePagesForExtensionProcess(
851 RenderProcessHost* process, 804 RenderProcessHost* process,
852 const Extension* extension, 805 const Extension* extension,
853 std::vector<ExtensionPage> *result) { 806 std::vector<ExtensionPage> *result) {
854 if (!process) 807 if (!process)
855 return; 808 return;
856 809
857 RenderProcessHost::listeners_iterator iter = process->ListenersIterator(); 810 RenderProcessHost::listeners_iterator iter = process->ListenersIterator();
858 for (; !iter.IsAtEnd(); iter.Advance()) { 811 for (; !iter.IsAtEnd(); iter.Advance()) {
859 const RenderWidgetHost* widget = 812 const RenderWidgetHost* widget =
860 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue()); 813 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue());
861 DCHECK(widget); 814 DCHECK(widget);
862 if (!widget || !widget->IsRenderView()) 815 if (!widget || !widget->IsRenderView())
863 continue; 816 continue;
864 const RenderViewHost* host = static_cast<const RenderViewHost*>(widget); 817 const RenderViewHost* host = static_cast<const RenderViewHost*>(widget);
865 if (host == deleting_rvh_ || 818 if (host == deleting_rvh_ ||
866 ViewType::EXTENSION_POPUP == host->delegate()->GetRenderViewType() || 819 ViewType::EXTENSION_POPUP == host->delegate()->GetRenderViewType() ||
867 ViewType::EXTENSION_DIALOG == host->delegate()->GetRenderViewType()) 820 ViewType::EXTENSION_DIALOG == host->delegate()->GetRenderViewType())
868 continue; 821 continue;
869 822
870 GURL url = host->delegate()->GetURL(); 823 GURL url = host->delegate()->GetURL();
871 if (url.SchemeIs(chrome::kExtensionScheme)) { 824 if (url.SchemeIs(chrome::kExtensionScheme)) {
872 if (url.host() != extension->id()) 825 if (url.host() != extension->id())
873 continue; 826 continue;
874 } else if (!extension->web_extent().MatchesURL(url)) { 827 } else if (!extension->web_extent().MatchesURL(url)) {
875 continue; 828 continue;
876 } 829 }
877 830
878 result->push_back(ExtensionPage(url, process->id(), host->routing_id(), 831 result->push_back(
879 process->profile()->IsOffTheRecord())); 832 ExtensionPage(url, process->id(), host->routing_id(),
833 process->browser_context()->IsOffTheRecord()));
880 } 834 }
881 } 835 }
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698