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

Side by Side Diff: chrome/browser/extensions/extensions_service.cc

Issue 174277: override chrome:// URLs via extensions. (Closed)
Patch Set: fix linux errors Created 11 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_service.h" 5 #include "chrome/browser/extensions/extensions_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/chrome_thread.h" 11 #include "chrome/browser/chrome_thread.h"
12 #include "chrome/browser/extensions/crx_installer.h" 12 #include "chrome/browser/extensions/crx_installer.h"
13 #include "chrome/browser/extensions/extension_browser_event_router.h" 13 #include "chrome/browser/extensions/extension_browser_event_router.h"
14 #include "chrome/browser/extensions/extension_dom_ui.h"
14 #include "chrome/browser/extensions/extension_file_util.h" 15 #include "chrome/browser/extensions/extension_file_util.h"
15 #include "chrome/browser/extensions/extension_updater.h" 16 #include "chrome/browser/extensions/extension_updater.h"
16 #include "chrome/browser/extensions/external_extension_provider.h" 17 #include "chrome/browser/extensions/external_extension_provider.h"
17 #include "chrome/browser/extensions/external_pref_extension_provider.h" 18 #include "chrome/browser/extensions/external_pref_extension_provider.h"
18 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
21 #include "chrome/common/extensions/extension_error_reporter.h" 22 #include "chrome/common/extensions/extension_error_reporter.h"
22 #include "chrome/common/notification_service.h" 23 #include "chrome/common/notification_service.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 187
187 extension_prefs_->OnExtensionUninstalled(extension, external_uninstall); 188 extension_prefs_->OnExtensionUninstalled(extension, external_uninstall);
188 189
189 // Tell the backend to start deleting installed extensions on the file thread. 190 // Tell the backend to start deleting installed extensions on the file thread.
190 if (Extension::LOAD != extension->location()) { 191 if (Extension::LOAD != extension->location()) {
191 backend_loop_->PostTask(FROM_HERE, NewRunnableFunction( 192 backend_loop_->PostTask(FROM_HERE, NewRunnableFunction(
192 &extension_file_util::UninstallExtension, extension_id, 193 &extension_file_util::UninstallExtension, extension_id,
193 install_directory_)); 194 install_directory_));
194 } 195 }
195 196
197 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_,
198 extension->GetChromeURLOverrides());
199
196 UnloadExtension(extension_id); 200 UnloadExtension(extension_id);
197 } 201 }
198 202
199 void ExtensionsService::EnableExtension(const std::string& extension_id) { 203 void ExtensionsService::EnableExtension(const std::string& extension_id) {
200 Extension* extension = GetExtensionByIdInternal(extension_id, false, true); 204 Extension* extension = GetExtensionByIdInternal(extension_id, false, true);
201 if (!extension) { 205 if (!extension) {
202 NOTREACHED() << "Trying to enable an extension that isn't disabled."; 206 NOTREACHED() << "Trying to enable an extension that isn't disabled.";
203 return; 207 return;
204 } 208 }
205 209
206 // Move it over to the enabled list. 210 // Move it over to the enabled list.
207 extension_prefs_->SetExtensionState(extension, Extension::ENABLED); 211 extension_prefs_->SetExtensionState(extension, Extension::ENABLED);
208 extensions_.push_back(extension); 212 extensions_.push_back(extension);
209 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), 213 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
210 disabled_extensions_.end(), 214 disabled_extensions_.end(),
211 extension); 215 extension);
212 disabled_extensions_.erase(iter); 216 disabled_extensions_.erase(iter);
213 217
218 ExtensionDOMUI::RegisterChromeURLOverrides(profile_,
219 extension->GetChromeURLOverrides());
220
214 NotificationService::current()->Notify( 221 NotificationService::current()->Notify(
215 NotificationType::EXTENSION_LOADED, 222 NotificationType::EXTENSION_LOADED,
216 Source<ExtensionsService>(this), 223 Source<ExtensionsService>(this),
217 Details<Extension>(extension)); 224 Details<Extension>(extension));
218 } 225 }
219 226
220 void ExtensionsService::LoadExtension(const FilePath& extension_path) { 227 void ExtensionsService::LoadExtension(const FilePath& extension_path) {
221 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), 228 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(),
222 &ExtensionsServiceBackend::LoadSingleExtension, 229 &ExtensionsServiceBackend::LoadSingleExtension,
223 extension_path, scoped_refptr<ExtensionsService>(this))); 230 extension_path, scoped_refptr<ExtensionsService>(this)));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 scoped_refptr<ExtensionsService>(this))); 312 scoped_refptr<ExtensionsService>(this)));
306 } 313 }
307 314
308 void ExtensionsService::UnloadExtension(const std::string& extension_id) { 315 void ExtensionsService::UnloadExtension(const std::string& extension_id) {
309 scoped_ptr<Extension> extension( 316 scoped_ptr<Extension> extension(
310 GetExtensionByIdInternal(extension_id, true, true)); 317 GetExtensionByIdInternal(extension_id, true, true));
311 318
312 // Callers should not send us nonexistant extensions. 319 // Callers should not send us nonexistant extensions.
313 CHECK(extension.get()); 320 CHECK(extension.get());
314 321
322 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_,
323 extension->GetChromeURLOverrides());
324
315 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), 325 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
316 disabled_extensions_.end(), 326 disabled_extensions_.end(),
317 extension.get()); 327 extension.get());
318 if (iter != disabled_extensions_.end()) { 328 if (iter != disabled_extensions_.end()) {
319 disabled_extensions_.erase(iter); 329 disabled_extensions_.erase(iter);
320 NotificationService::current()->Notify( 330 NotificationService::current()->Notify(
321 NotificationType::EXTENSION_UNLOADED_DISABLED, 331 NotificationType::EXTENSION_UNLOADED_DISABLED,
322 Source<ExtensionsService>(this), 332 Source<ExtensionsService>(this),
323 Details<Extension>(extension.get())); 333 Details<Extension>(extension.get()));
324 return; 334 return;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 NotificationService::current()->Notify( 425 NotificationService::current()->Notify(
416 NotificationType::EXTENSION_LOADED, 426 NotificationType::EXTENSION_LOADED,
417 Source<ExtensionsService>(this), 427 Source<ExtensionsService>(this),
418 Details<Extension>(extension)); 428 Details<Extension>(extension));
419 429
420 if (extension->IsTheme() && extension->location() == Extension::LOAD) { 430 if (extension->IsTheme() && extension->location() == Extension::LOAD) {
421 NotificationService::current()->Notify( 431 NotificationService::current()->Notify(
422 NotificationType::THEME_INSTALLED, 432 NotificationType::THEME_INSTALLED,
423 Source<ExtensionsService>(this), 433 Source<ExtensionsService>(this),
424 Details<Extension>(extension)); 434 Details<Extension>(extension));
435 } else {
436 ExtensionDOMUI::RegisterChromeURLOverrides(profile_,
437 extension->GetChromeURLOverrides());
425 } 438 }
426 break; 439 break;
427 case Extension::DISABLED: 440 case Extension::DISABLED:
428 disabled_extensions_.push_back(scoped_extension.release()); 441 disabled_extensions_.push_back(scoped_extension.release());
429 break; 442 break;
430 default: 443 default:
431 break; 444 break;
432 } 445 }
433 } 446 }
434 } 447 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 linked_ptr<ExternalExtensionProvider>(test_provider); 684 linked_ptr<ExternalExtensionProvider>(test_provider);
672 } 685 }
673 686
674 void ExtensionsServiceBackend::OnExternalExtensionFound( 687 void ExtensionsServiceBackend::OnExternalExtensionFound(
675 const std::string& id, const Version* version, const FilePath& path, 688 const std::string& id, const Version* version, const FilePath& path,
676 Extension::Location location) { 689 Extension::Location location) {
677 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_, 690 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_,
678 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(), 691 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(),
679 path, location)); 692 path, location));
680 } 693 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_override_apitest.cc ('k') | chrome/browser/tab_contents/navigation_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698