diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_disabled_infobar_delegate.cc | 11 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_process_manager.cc | 19 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_shelf_model.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 285 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 43 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 11 | ||||
-rw-r--r-- | chrome/browser/extensions/user_script_master.cc | 18 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 15 | ||||
-rw-r--r-- | chrome/browser/plugin_service.cc | 22 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 4 |
11 files changed, 190 insertions, 250 deletions
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index d9f488c..4fead1c 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -50,7 +50,7 @@ bool ExtensionBrowserTest::LoadExtension(const FilePath& path) { size_t num_before = service->extensions()->size(); { NotificationRegistrar registrar; - registrar.Add(this, NotificationType::EXTENSIONS_LOADED, + registrar.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); service->LoadExtension(path); MessageLoop::current()->PostDelayedTask( @@ -72,7 +72,7 @@ bool ExtensionBrowserTest::InstallExtension(const FilePath& path, { NotificationRegistrar registrar; - registrar.Add(this, NotificationType::EXTENSIONS_LOADED, + registrar.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); registrar.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, NotificationService::AllSources()); @@ -162,7 +162,7 @@ void ExtensionBrowserTest::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { switch (type.value) { - case NotificationType::EXTENSIONS_LOADED: + case NotificationType::EXTENSION_LOADED: std::cout << "Got EXTENSION_LOADED notification.\n"; MessageLoopForUI::current()->Quit(); break; diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc index 8dc323a..e3b0ca8 100644 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc @@ -81,7 +81,7 @@ class ExtensionDisabledInfobarDelegate service_(service), extension_(extension) { // The user might re-enable the extension in other ways, so watch for that. - registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + registrar_.Add(this, NotificationType::EXTENSION_LOADED, Source<ExtensionsService>(service)); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, Source<ExtensionsService>(service)); @@ -116,14 +116,7 @@ class ExtensionDisabledInfobarDelegate // TODO(mpcomplete): RemoveInfoBar doesn't seem to always result in us // getting deleted. switch (type.value) { - case NotificationType::EXTENSIONS_LOADED: { - ExtensionList* extensions = Details<ExtensionList>(details).ptr(); - ExtensionList::iterator iter = std::find(extensions->begin(), - extensions->end(), extension_); - if (iter != extensions->end()) - tab_contents_->RemoveInfoBar(this); - break; - } + case NotificationType::EXTENSION_LOADED: case NotificationType::EXTENSION_UNLOADED_DISABLED: { Extension* extension = Details<Extension>(details).ptr(); if (extension == extension_) diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc index acf43af..05a61a1 100644 --- a/chrome/browser/extensions/extension_process_manager.cc +++ b/chrome/browser/extensions/extension_process_manager.cc @@ -15,13 +15,18 @@ #include "chrome/common/notification_type.h" #include "chrome/common/render_messages.h" +static void CreateBackgroundHost( + ExtensionProcessManager* manager, Extension* extension) { + // Start the process for the master page, if it exists. + if (extension->background_url().is_valid()) + manager->CreateBackgroundHost(extension, extension->background_url()); +} + static void CreateBackgroundHosts( ExtensionProcessManager* manager, const ExtensionList* extensions) { for (ExtensionList::const_iterator extension = extensions->begin(); extension != extensions->end(); ++extension) { - // Start the process for the master page, if it exists. - if ((*extension)->background_url().is_valid()) - manager->CreateBackgroundHost(*extension, (*extension)->background_url()); + CreateBackgroundHost(manager, *extension); } } @@ -29,7 +34,7 @@ ExtensionProcessManager::ExtensionProcessManager(Profile* profile) : browsing_instance_(new BrowsingInstance(profile)) { registrar_.Add(this, NotificationType::EXTENSIONS_READY, NotificationService::AllSources()); - registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + registrar_.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, NotificationService::AllSources()); @@ -146,11 +151,11 @@ void ExtensionProcessManager::Observe(NotificationType type, Source<ExtensionsService>(source).ptr()->extensions()); break; - case NotificationType::EXTENSIONS_LOADED: { + case NotificationType::EXTENSION_LOADED: { ExtensionsService* service = Source<ExtensionsService>(source).ptr(); if (service->is_ready()) { - const ExtensionList* extensions = Details<ExtensionList>(details).ptr(); - CreateBackgroundHosts(this, extensions); + Extension* extension = Details<Extension>(details).ptr(); + ::CreateBackgroundHost(this, extension); } break; } diff --git a/chrome/browser/extensions/extension_shelf_model.cc b/chrome/browser/extensions/extension_shelf_model.cc index 6b7bd0c..b2dbb9b 100644 --- a/chrome/browser/extensions/extension_shelf_model.cc +++ b/chrome/browser/extensions/extension_shelf_model.cc @@ -18,7 +18,7 @@ ExtensionShelfModel::ExtensionShelfModel(Browser* browser) // Watch extensions loaded and unloaded notifications. registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, NotificationService::AllSources()); - registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + registrar_.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSIONS_READY, NotificationService::AllSources()); @@ -148,9 +148,9 @@ void ExtensionShelfModel::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { switch (type.value) { - case NotificationType::EXTENSIONS_LOADED: + case NotificationType::EXTENSION_LOADED: if (ready_) - AddExtensions(Details<ExtensionList>(details).ptr()); + AddExtension(Details<Extension>(details).ptr()); break; case NotificationType::EXTENSION_UNLOADED: RemoveExtension(Details<Extension>(details).ptr()); diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 6dcc015..0331366 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -51,6 +51,15 @@ class InstalledExtensionSet { std::set<std::string> extensions_; }; +static void ReportExtensionLoadError( + const FilePath& extension_path, const std::string &error, bool be_noisy) { + // TODO(port): note that this isn't guaranteed to work properly on Linux. + std::string path_str = WideToASCII(extension_path.ToWStringHack()); + std::string message = StringPrintf("Could not load extension from '%s'. %s", + path_str.c_str(), error.c_str()); + ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); +} + } // namespace // ExtensionsService. @@ -200,12 +209,10 @@ void ExtensionsService::EnableExtension(const std::string& extension_id) { extension); disabled_extensions_.erase(iter); - ExtensionList extensions; - extensions.push_back(extension); NotificationService::current()->Notify( - NotificationType::EXTENSIONS_LOADED, + NotificationType::EXTENSION_LOADED, Source<ExtensionsService>(this), - Details<ExtensionList>(&extensions)); + Details<Extension>(extension)); } void ExtensionsService::LoadExtension(const FilePath& extension_path) { @@ -216,10 +223,45 @@ void ExtensionsService::LoadExtension(const FilePath& extension_path) { void ExtensionsService::LoadAllExtensions() { // Load the previously installed extensions. - backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), - &ExtensionsServiceBackend::LoadInstalledExtensions, - scoped_refptr<ExtensionsService>(this), - new InstalledExtensions(extension_prefs_.get()))); + scoped_ptr<InstalledExtensions> installed( + new InstalledExtensions(extension_prefs_.get())); + installed->VisitInstalledExtensions( + NewCallback(this, &ExtensionsService::LoadInstalledExtension)); + OnLoadedInstalledExtensions(); +} + +void ExtensionsService::LoadInstalledExtension( + DictionaryValue* manifest, const std::string& id, + const FilePath& path, Extension::Location location) { + std::string error; + Extension* extension = NULL; + if (manifest) { + scoped_ptr<Extension> tmp(new Extension(path)); + if (tmp->InitFromValue(*manifest, true, &error)) { + extension = tmp.release(); + } + } else { + // TODO(mpcomplete): obsolete. remove after migration period. + // http://code.google.com/p/chromium/issues/detail?id=19733 + extension = extension_file_util::LoadExtension(path, + true, // Require id + &error); + } + + if (!extension) { + ReportExtensionLoadError(path, error, false); + return; + } + + extension->set_location(location); + OnExtensionLoaded(extension); + + if (location == Extension::EXTERNAL_PREF || + location == Extension::EXTERNAL_REGISTRY) { + backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), + &ExtensionsServiceBackend::CheckExternalUninstall, + scoped_refptr<ExtensionsService>(this), id, location)); + } } void ExtensionsService::UpdateExtensionBlacklist( @@ -326,83 +368,65 @@ void ExtensionsService::OnLoadedInstalledExtensions() { NotificationService::NoDetails()); } -void ExtensionsService::OnExtensionsLoaded(ExtensionList* new_extensions) { - scoped_ptr<ExtensionList> cleanup(new_extensions); - - // Filter out any extensions that shouldn't be loaded. If extensions are - // enabled, load everything. Otherwise load only: - // - themes - // - --load-extension - // - externally installed extensions - ExtensionList enabled_extensions; - ExtensionList disabled_extensions; - for (ExtensionList::iterator iter = new_extensions->begin(); - iter != new_extensions->end(); ++iter) { - // Extensions that get enabled get added to extensions_ and deleted later. - // Anything skipped must be deleted now so we don't leak. - scoped_ptr<Extension> extension(*iter); - if (extensions_enabled() || - extension->IsTheme() || - extension->location() == Extension::LOAD || - Extension::IsExternalLocation(extension->location())) { - Extension* old = GetExtensionByIdInternal(extension->id(), true, true); - if (old) { - if (extension->version()->CompareTo(*(old->version())) > 0) { - bool higher_permissions = - (extension->GetPermissionClass() > old->GetPermissionClass()); - - // To upgrade an extension in place, unload the old one and - // then load the new one. - UnloadExtension(old->id()); - old = NULL; - - if (higher_permissions) { - // Extension was upgraded to a high permission class. Disable it and - // notify the user. - extension_prefs_->SetExtensionState(extension.get(), - Extension::DISABLED); - NotificationService::current()->Notify( - NotificationType::EXTENSION_UPDATE_DISABLED, - Source<ExtensionsService>(this), - Details<Extension>(extension.get())); - } - } else { - // We already have the extension of the same or older version. - LOG(WARNING) << "Duplicate extension load attempt: " << (*iter)->id(); - continue; +void ExtensionsService::OnExtensionLoaded(Extension* extension) { + // Ensure extension is deleted unless we transfer ownership. + scoped_ptr<Extension> scoped_extension(extension); + + if (extensions_enabled() || + extension->IsTheme() || + extension->location() == Extension::LOAD || + Extension::IsExternalLocation(extension->location())) { + Extension* old = GetExtensionByIdInternal(extension->id(), true, true); + if (old) { + if (extension->version()->CompareTo(*(old->version())) > 0) { + bool higher_permissions = + (extension->GetPermissionClass() > old->GetPermissionClass()); + + // To upgrade an extension in place, unload the old one and + // then load the new one. + UnloadExtension(old->id()); + old = NULL; + + if (higher_permissions) { + // Extension was upgraded to a high permission class. Disable it and + // notify the user. + extension_prefs_->SetExtensionState(extension, Extension::DISABLED); + NotificationService::current()->Notify( + NotificationType::EXTENSION_UPDATE_DISABLED, + Source<ExtensionsService>(this), + Details<Extension>(extension)); } - } - - switch (extension_prefs_->GetExtensionState(extension->id())) { - case Extension::ENABLED: - if (extension->location() != Extension::LOAD) - extension_prefs_->MigrateToPrefs(extension.get()); - enabled_extensions.push_back(extension.get()); - extensions_.push_back(extension.release()); - break; - case Extension::DISABLED: - disabled_extensions.push_back(extension.get()); - disabled_extensions_.push_back(extension.release()); - break; - default: - break; + } else { + // We already have the extension of the same or older version. + LOG(WARNING) << "Duplicate extension load attempt: " << extension->id(); + return; } } - } - if (enabled_extensions.size()) { - NotificationService::current()->Notify( - NotificationType::EXTENSIONS_LOADED, - Source<ExtensionsService>(this), - Details<ExtensionList>(&enabled_extensions)); - for (ExtensionList::iterator iter = enabled_extensions.begin(); - iter != enabled_extensions.end(); ++iter) { - if ((*iter)->IsTheme() && (*iter)->location() == Extension::LOAD) { + switch (extension_prefs_->GetExtensionState(extension->id())) { + case Extension::ENABLED: + extensions_.push_back(scoped_extension.release()); + + if (extension->location() != Extension::LOAD) + extension_prefs_->MigrateToPrefs(extension); + NotificationService::current()->Notify( - NotificationType::THEME_INSTALLED, + NotificationType::EXTENSION_LOADED, Source<ExtensionsService>(this), - Details<Extension>(*iter)); - } + Details<Extension>(extension)); + + if (extension->IsTheme() && extension->location() == Extension::LOAD) { + NotificationService::current()->Notify( + NotificationType::THEME_INSTALLED, + Source<ExtensionsService>(this), + Details<Extension>(extension)); + } + break; + case Extension::DISABLED: + disabled_extensions_.push_back(scoped_extension.release()); + break; + default: + break; } } } @@ -425,9 +449,7 @@ void ExtensionsService::OnExtensionInstalled(Extension* extension) { } // Also load the extension. - ExtensionList* list = new ExtensionList; - list->push_back(extension); - OnExtensionsLoaded(list); + OnExtensionLoaded(extension); } void ExtensionsService::OnExtensionOverinstallAttempted(const std::string& id) { @@ -534,21 +556,6 @@ ExtensionsServiceBackend::ExtensionsServiceBackend( ExtensionsServiceBackend::~ExtensionsServiceBackend() { } -void ExtensionsServiceBackend::LoadInstalledExtensions( - scoped_refptr<ExtensionsService> frontend, - InstalledExtensions* installed) { - scoped_ptr<InstalledExtensions> cleanup(installed); - frontend_ = frontend; - alert_on_error_ = false; - - // Call LoadInstalledExtension for each extension |installed| knows about. - installed->VisitInstalledExtensions( - NewCallback(this, &ExtensionsServiceBackend::LoadInstalledExtension)); - - frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod( - frontend_, &ExtensionsService::OnLoadedInstalledExtensions)); -} - void ExtensionsServiceBackend::LoadSingleExtension( const FilePath& path_in, scoped_refptr<ExtensionsService> frontend) { frontend_ = frontend; @@ -574,67 +581,18 @@ void ExtensionsServiceBackend::LoadSingleExtension( } extension->set_location(Extension::LOAD); - ExtensionList* extensions = new ExtensionList; - extensions->push_back(extension); - ReportExtensionsLoaded(extensions); + ReportExtensionLoaded(extension); } -void ExtensionsServiceBackend::LoadInstalledExtension( - DictionaryValue* manifest, const std::string& id, - const FilePath& path, Extension::Location location) { - if (CheckExternalUninstall(id, location)) { - frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod( - frontend_, - &ExtensionsService::UninstallExtension, - id, true)); - - // No error needs to be reported. The extension effectively doesn't exist. - return; - } - - std::string error; - Extension* extension = NULL; - if (manifest) { - scoped_ptr<Extension> tmp(new Extension(path)); - if (tmp->InitFromValue(*manifest, true, &error) && - extension_file_util::ValidateExtension(tmp.get(), &error)) { - extension = tmp.release(); - } - } else { - // TODO(mpcomplete): obsolete. remove after migration period. - // http://code.google.com/p/chromium/issues/detail?id=19733 - extension = extension_file_util::LoadExtension(path, - true, // Require id - &error); - } - - if (!extension) { - ReportExtensionLoadError(path, error); - return; - } - - // TODO(erikkay) now we only report a single extension loaded at a time. - // Perhaps we should change the notifications to remove ExtensionList. - extension->set_location(location); - ExtensionList* extensions = new ExtensionList; - if (extension) - extensions->push_back(extension); - ReportExtensionsLoaded(extensions); -} void ExtensionsServiceBackend::ReportExtensionLoadError( const FilePath& extension_path, const std::string &error) { - // TODO(port): note that this isn't guaranteed to work properly on Linux. - std::string path_str = WideToASCII(extension_path.ToWStringHack()); - std::string message = StringPrintf("Could not load extension from '%s'. %s", - path_str.c_str(), error.c_str()); - ExtensionErrorReporter::GetInstance()->ReportError(message, alert_on_error_); + ::ReportExtensionLoadError(extension_path, error, alert_on_error_); } -void ExtensionsServiceBackend::ReportExtensionsLoaded( - ExtensionList* extensions) { +void ExtensionsServiceBackend::ReportExtensionLoaded(Extension* extension) { frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod( - frontend_, &ExtensionsService::OnExtensionsLoaded, extensions)); + frontend_, &ExtensionsService::OnExtensionLoaded, extension)); } bool ExtensionsServiceBackend::LookupExternalExtension( @@ -679,21 +637,26 @@ void ExtensionsServiceBackend::CheckForExternalUpdates( } } -bool ExtensionsServiceBackend::CheckExternalUninstall( - const std::string& id, Extension::Location location) { +void ExtensionsServiceBackend::CheckExternalUninstall( + scoped_refptr<ExtensionsService> frontend, const std::string& id, + Extension::Location location) { // Check if the providers know about this extension. ProviderMap::const_iterator i = external_extension_providers_.find(location); - if (i != external_extension_providers_.end()) { - scoped_ptr<Version> version; - version.reset(i->second->RegisteredVersion(id, NULL)); - if (version.get()) - return false; // Yup, known extension, don't uninstall. - } else { - // Not from an external provider, so it's fine. - return false; + if (i == external_extension_providers_.end()) { + NOTREACHED() << "CheckExternalUninstall called for non-external extension " + << location; + return; } - return true; // This is not a known extension, uninstall. + scoped_ptr<Version> version; + version.reset(i->second->RegisteredVersion(id, NULL)); + if (version.get()) + return; // Yup, known extension, don't uninstall. + + // This is an external extension that we don't have registered. Uninstall. + frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod( + frontend.get(), &ExtensionsService::UninstallExtension, + id, true)); } void ExtensionsServiceBackend::ClearProvidersForTesting() { diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 6a56749..d745058 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -169,8 +169,8 @@ class ExtensionsService // Called by the backend when the initial extension load has completed. void OnLoadedInstalledExtensions(); - // Called by the backend when extensions have been loaded. - void OnExtensionsLoaded(ExtensionList* extensions); + // Called by the backend when an extension has been loaded. + void OnExtensionLoaded(Extension* extension); // Called by the backend when an extension has been installed. void OnExtensionInstalled(Extension* extension); @@ -216,6 +216,12 @@ class ExtensionsService bool include_enabled, bool include_disabled); + // Load a single extension from the prefs. This can be done on the UI thread + // because we don't touch the disk. + void LoadInstalledExtension( + DictionaryValue* manifest, const std::string& id, + const FilePath& path, Extension::Location location); + // The profile this ExtensionsService is part of. Profile* profile_; @@ -266,17 +272,10 @@ class ExtensionsServiceBackend virtual ~ExtensionsServiceBackend(); - // Loads the installed extensions. - // Errors are reported through ExtensionErrorReporter. On completion, - // OnExtensionsLoaded() is called with any successfully loaded extensions. - void LoadInstalledExtensions(scoped_refptr<ExtensionsService> frontend, - InstalledExtensions* installed); - // Loads a single extension from |path| where |path| is the top directory of // a specific extension where its manifest file lives. - // Errors are reported through ExtensionErrorReporter. On completion, - // OnExtensionsLoadedFromDirectory() is called with any successfully loaded - // extensions. + // Errors are reported through ExtensionErrorReporter. On success, + // OnExtensionLoaded() is called. // TODO(erikkay): It might be useful to be able to load a packed extension // (presumably into memory) without installing it. void LoadSingleExtension(const FilePath &path, @@ -288,6 +287,12 @@ class ExtensionsServiceBackend void CheckForExternalUpdates(std::set<std::string> ids_to_ignore, scoped_refptr<ExtensionsService> frontend); + // For the extension in |version_path| with |id|, check to see if it's an + // externally managed extension. If so, tell the frontend to uninstall it. + void CheckExternalUninstall(scoped_refptr<ExtensionsService> frontend, + const std::string& id, + Extension::Location location); + // Clear all ExternalExtensionProviders. void ClearProvidersForTesting(); @@ -302,12 +307,6 @@ class ExtensionsServiceBackend const FilePath& path, Extension::Location location); private: - // Loads a single installed extension. - void LoadInstalledExtension(DictionaryValue* manifest, - const std::string& id, - const FilePath& path, - Extension::Location location); - // Finish installing the extension in |crx_path| after it has been unpacked to // |unpacked_path|. If |expected_id| is not empty, it's verified against the // extension's manifest before installation. If |silent| is true, there will @@ -325,8 +324,8 @@ class ExtensionsServiceBackend void ReportExtensionLoadError(const FilePath& extension_path, const std::string& error); - // Notify the frontend that extensions were loaded. - void ReportExtensionsLoaded(ExtensionList* extensions); + // Notify the frontend that an extension was loaded. + void ReportExtensionLoaded(Extension* extension); // Notify the frontend that there was an error installing an extension. void ReportExtensionInstallError(const FilePath& extension_path, @@ -342,12 +341,6 @@ class ExtensionsServiceBackend Version** version, Extension::Location* location); - // For the extension in |version_path| with |id|, check to see if it's an - // externally managed extension. If so return true if it should be - // uninstalled. - bool CheckExternalUninstall(const std::string& id, - Extension::Location location); - // This is a naked pointer which is set by each entry point. // The entry point is responsible for ensuring lifetime. ExtensionsService* frontend_; diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index d19a3d3..6df27a9 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -197,7 +197,7 @@ class ExtensionsServiceTest : public testing::Test, public NotificationObserver { public: ExtensionsServiceTest() : installed_(NULL) { - registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + registrar_.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, NotificationService::AllSources()); @@ -275,12 +275,9 @@ class ExtensionsServiceTest const NotificationSource& source, const NotificationDetails& details) { switch (type.value) { - case NotificationType::EXTENSIONS_LOADED: { - ExtensionList* list = Details<ExtensionList>(details).ptr(); - for (ExtensionList::iterator iter = list->begin(); iter != list->end(); - ++iter) { - loaded_.push_back(*iter); - } + case NotificationType::EXTENSION_LOADED: { + Extension* extension = Details<Extension>(details).ptr(); + loaded_.push_back(extension); // The tests rely on the errors being in a certain order, which can vary // depending on how filesystem iteration works. std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index e49dfa1..7fa7832 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -268,7 +268,7 @@ UserScriptMaster::UserScriptMaster(MessageLoop* worker_loop, registrar_.Add(this, NotificationType::EXTENSIONS_READY, NotificationService::AllSources()); - registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + registrar_.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, NotificationService::AllSources()); @@ -336,22 +336,18 @@ void UserScriptMaster::Observe(NotificationType type, extensions_service_ready_ = true; StartScan(); break; - case NotificationType::EXTENSIONS_LOADED: { + case NotificationType::EXTENSION_LOADED: { // TODO(aa): Fix race here. A page could need a content script on startup, // before the extension has loaded. We need to freeze the renderer in // that case. // See: http://code.google.com/p/chromium/issues/detail?id=11547. // Add any content scripts inside the extension. - ExtensionList* extensions = Details<ExtensionList>(details).ptr(); - for (ExtensionList::iterator extension_iterator = extensions->begin(); - extension_iterator != extensions->end(); ++extension_iterator) { - Extension* extension = *extension_iterator; - const UserScriptList& scripts = extension->content_scripts(); - for (UserScriptList::const_iterator iter = scripts.begin(); - iter != scripts.end(); ++iter) { - lone_scripts_.push_back(*iter); - } + Extension* extension = Details<Extension>(details).ptr(); + const UserScriptList& scripts = extension->content_scripts(); + for (UserScriptList::const_iterator iter = scripts.begin(); + iter != scripts.end(); ++iter) { + lone_scripts_.push_back(*iter); } if (extensions_service_ready_) StartScan(); diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index a36887c..5bb921b 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -334,7 +334,7 @@ ChromeURLRequestContext::ChromeURLRequestContext(Profile* profile) prefs_->AddPrefObserver(prefs::kDefaultCharset, this); if (!is_off_the_record_) { - registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + registrar_.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, NotificationService::AllSources()); @@ -397,15 +397,12 @@ void ChromeURLRequestContext::Observe(NotificationType type, &ChromeURLRequestContext::OnDefaultCharsetChange, default_charset)); } - } else if (NotificationType::EXTENSIONS_LOADED == type) { + } else if (NotificationType::EXTENSION_LOADED == type) { ExtensionPaths* new_paths = new ExtensionPaths; - ExtensionList* extensions = Details<ExtensionList>(details).ptr(); - DCHECK(extensions); - for (ExtensionList::const_iterator iter = extensions->begin(); - iter != extensions->end(); ++iter) { - new_paths->insert(ExtensionPaths::value_type((*iter)->id(), - (*iter)->path())); - } + Extension* extension = Details<Extension>(details).ptr(); + DCHECK(extension); + new_paths->insert(ExtensionPaths::value_type(extension->id(), + extension->path())); g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &ChromeURLRequestContext::OnNewExtensions, new_paths)); diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc index c783451..a3335f1 100644 --- a/chrome/browser/plugin_service.cc +++ b/chrome/browser/plugin_service.cc @@ -61,7 +61,7 @@ PluginService::PluginService() } #endif - registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + registrar_.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, NotificationService::AllSources()); @@ -208,22 +208,18 @@ void PluginService::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { switch (type.value) { - case NotificationType::EXTENSIONS_LOADED: { + case NotificationType::EXTENSION_LOADED: { // TODO(mpcomplete): We also need to force a renderer to refresh its // cache of the plugin list when we inject user scripts, since it could // have a stale version by the time extensions are loaded. // See: http://code.google.com/p/chromium/issues/detail?id=12306 - - ExtensionList* extensions = Details<ExtensionList>(details).ptr(); - for (ExtensionList::iterator extension = extensions->begin(); - extension != extensions->end(); ++extension) { - for (size_t i = 0; i < (*extension)->plugins().size(); ++i ) { - const Extension::PluginInfo& plugin = (*extension)->plugins()[i]; - NPAPI::PluginList::Singleton()->ResetPluginsLoaded(); - NPAPI::PluginList::Singleton()->AddExtraPluginPath(plugin.path); - if (!plugin.is_public) - private_plugins_[plugin.path] = (*extension)->url(); - } + Extension* extension = Details<Extension>(details).ptr(); + for (size_t i = 0; i < extension->plugins().size(); ++i ) { + const Extension::PluginInfo& plugin = extension->plugins()[i]; + NPAPI::PluginList::Singleton()->ResetPluginsLoaded(); + NPAPI::PluginList::Singleton()->AddExtraPluginPath(plugin.path); + if (!plugin.is_public) + private_plugins_[plugin.path] = extension->url(); } break; } diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 8cde6bf..0b351a6 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -600,8 +600,8 @@ class NotificationType { // unloaded and reloaded. EXTENSIONS_READY, - // Sent when new extensions are loaded. The details are an ExtensionList*. - EXTENSIONS_LOADED, + // Sent when a new extension is loaded. The details are an Extension. + EXTENSION_LOADED, // Sent when attempting to load a new extension, but they are disabled. The // details are an Extension*. |