summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_disabled_infobar_delegate.cc4
-rw-r--r--chrome/browser/extensions/extension_host.cc2
-rw-r--r--chrome/browser/extensions/extension_process_manager.cc5
-rw-r--r--chrome/browser/extensions/extensions_service.cc60
-rw-r--r--chrome/browser/extensions/extensions_service.h8
-rw-r--r--chrome/browser/extensions/user_script_listener.cc4
-rw-r--r--chrome/browser/extensions/user_script_listener_unittest.cc62
7 files changed, 108 insertions, 37 deletions
diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
index ea8de22..0d0d7b4 100644
--- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
+++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
@@ -88,9 +88,9 @@ class ExtensionDisabledInfobarDelegate
extension_(extension) {
// The user might re-enable the extension in other ways, so watch for that.
registrar_.Add(this, NotificationType::EXTENSION_LOADED,
- Source<ExtensionsService>(service));
+ Source<Profile>(service->profile()));
registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
- Source<ExtensionsService>(service));
+ Source<Profile>(service->profile()));
}
virtual ~ExtensionDisabledInfobarDelegate() {
}
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index a468700..f9d6bd1 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -248,7 +248,7 @@ void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) {
DCHECK_EQ(render_view_host_, render_view_host);
NotificationService::current()->Notify(
NotificationType::EXTENSION_PROCESS_CRASHED,
- Source<ExtensionsService>(profile_->GetExtensionsService()),
+ Source<Profile>(profile_),
Details<ExtensionHost>(this));
}
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index e9bb7c49..6718691 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -175,11 +175,12 @@ void ExtensionProcessManager::Observe(NotificationType type,
switch (type.value) {
case NotificationType::EXTENSIONS_READY:
CreateBackgroundHosts(this,
- Source<ExtensionsService>(source).ptr()->extensions());
+ Source<Profile>(source).ptr()->GetExtensionsService()->extensions());
break;
case NotificationType::EXTENSION_LOADED: {
- ExtensionsService* service = Source<ExtensionsService>(source).ptr();
+ ExtensionsService* service =
+ Source<Profile>(source).ptr()->GetExtensionsService();
if (service->is_ready()) {
Extension* extension = Details<Extension>(details).ptr();
::CreateBackgroundHost(this, extension);
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 1692e3f..dcca59e 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -333,7 +333,7 @@ void ExtensionsService::NotifyExtensionLoaded(Extension* extension) {
NotificationService::current()->Notify(
NotificationType::EXTENSION_LOADED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<Extension>(extension));
}
@@ -342,7 +342,7 @@ void ExtensionsService::NotifyExtensionUnloaded(Extension* extension) {
NotificationService::current()->Notify(
NotificationType::EXTENSION_UNLOADED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<Extension>(extension));
if (profile_ && !profile_->IsOffTheRecord()) {
@@ -417,7 +417,7 @@ void ExtensionsService::UnloadExtension(const std::string& extension_id) {
disabled_extensions_.erase(iter);
NotificationService::current()->Notify(
NotificationType::EXTENSION_UNLOADED_DISABLED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<Extension>(extension.get()));
return;
}
@@ -463,7 +463,7 @@ void ExtensionsService::OnLoadedInstalledExtensions() {
}
NotificationService::current()->Notify(
NotificationType::EXTENSIONS_READY,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
NotificationService::NoDetails());
}
@@ -494,7 +494,7 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension,
extension_prefs_->SetExtensionState(extension, Extension::DISABLED);
NotificationService::current()->Notify(
NotificationType::EXTENSION_UPDATE_DISABLED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<Extension>(extension));
}
} else {
@@ -528,7 +528,7 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension,
if (extension->IsTheme() && extension->location() == Extension::LOAD) {
NotificationService::current()->Notify(
NotificationType::THEME_INSTALLED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<Extension>(extension));
} else {
ExtensionDOMUI::RegisterChromeURLOverrides(profile_,
@@ -538,7 +538,7 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension,
case Extension::DISABLED:
NotificationService::current()->Notify(
NotificationType::EXTENSION_UPDATE_DISABLED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<Extension>(extension));
disabled_extensions_.push_back(scoped_extension.release());
break;
@@ -558,12 +558,12 @@ void ExtensionsService::OnExtensionInstalled(Extension* extension,
if (extension->IsTheme()) {
NotificationService::current()->Notify(
NotificationType::THEME_INSTALLED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<Extension>(extension));
} else {
NotificationService::current()->Notify(
NotificationType::EXTENSION_INSTALLED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<Extension>(extension));
}
@@ -576,12 +576,12 @@ void ExtensionsService::OnExtensionOverinstallAttempted(const std::string& id) {
if (extension && extension->IsTheme()) {
NotificationService::current()->Notify(
NotificationType::THEME_INSTALLED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<Extension>(extension));
} else {
NotificationService::current()->Notify(
NotificationType::NO_THEME_DETECTED,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
NotificationService::NoDetails());
}
}
@@ -666,7 +666,7 @@ void ExtensionsService::ReportExtensionLoadError(
bool be_noisy) {
NotificationService* service = NotificationService::current();
service->Notify(type,
- Source<ExtensionsService>(this),
+ Source<Profile>(profile_),
Details<const std::string>(&error));
// TODO(port): note that this isn't guaranteed to work properly on Linux.
@@ -676,6 +676,42 @@ void ExtensionsService::ReportExtensionLoadError(
ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
}
+std::vector<FilePath> ExtensionsService::GetPersistentBlacklistPaths() {
+ std::vector<FilePath> result;
+ for (ExtensionList::const_iterator extension_iter = extensions()->begin();
+ extension_iter != extensions()->end(); ++extension_iter) {
+ if ((*extension_iter)->location() == Extension::LOAD)
+ continue;
+
+ std::vector<Extension::PrivacyBlacklistInfo> blacklists(
+ (*extension_iter)->privacy_blacklists());
+ std::vector<Extension::PrivacyBlacklistInfo>::const_iterator blacklist_iter;
+ for (blacklist_iter = blacklists.begin();
+ blacklist_iter != blacklists.end(); ++blacklist_iter) {
+ result.push_back(blacklist_iter->path);
+ }
+ }
+ return result;
+}
+
+std::vector<FilePath> ExtensionsService::GetTransientBlacklistPaths() {
+ std::vector<FilePath> result;
+ for (ExtensionList::const_iterator extension_iter = extensions()->begin();
+ extension_iter != extensions()->end(); ++extension_iter) {
+ if ((*extension_iter)->location() != Extension::LOAD)
+ continue;
+
+ std::vector<Extension::PrivacyBlacklistInfo> blacklists(
+ (*extension_iter)->privacy_blacklists());
+ std::vector<Extension::PrivacyBlacklistInfo>::const_iterator blacklist_iter;
+ for (blacklist_iter = blacklists.begin();
+ blacklist_iter != blacklists.end(); ++blacklist_iter) {
+ result.push_back(blacklist_iter->path);
+ }
+ }
+ return result;
+}
+
// ExtensionsServicesBackend
ExtensionsServiceBackend::ExtensionsServiceBackend(
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index 6d525d7..55e336d 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -21,6 +21,7 @@
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/external_extension_provider.h"
#include "chrome/browser/extensions/sandboxed_extension_unpacker.h"
+#include "chrome/browser/privacy_blacklist/blacklist_manager.h"
#include "chrome/common/extensions/extension.h"
class Browser;
@@ -51,6 +52,7 @@ class ExtensionUpdateService {
// Manages installed and running Chromium extensions.
class ExtensionsService
: public ExtensionUpdateService,
+ public BlacklistPathProvider,
public base::RefCountedThreadSafe<ExtensionsService> {
public:
@@ -201,6 +203,8 @@ class ExtensionsService
return show_extensions_prompts_;
}
+ Profile* profile() { return profile_; }
+
// Profile calls this when it is destroyed so that we know not to call it.
void ProfileDestroyed() { profile_ = NULL; }
@@ -219,6 +223,10 @@ class ExtensionsService
NotificationType type,
bool be_noisy);
+ // BlacklistPathProvider:
+ virtual std::vector<FilePath> GetPersistentBlacklistPaths();
+ virtual std::vector<FilePath> GetTransientBlacklistPaths();
+
private:
// Look up an extension by ID, optionally including either or both of enabled
// and disabled extensions.
diff --git a/chrome/browser/extensions/user_script_listener.cc b/chrome/browser/extensions/user_script_listener.cc
index 31f0971..76a4ff5 100644
--- a/chrome/browser/extensions/user_script_listener.cc
+++ b/chrome/browser/extensions/user_script_listener.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/notification_service.h"
@@ -136,7 +137,8 @@ void UserScriptListener::Observe(NotificationType type,
// Clear all our patterns and reregister all the still-loaded extensions.
URLPatterns new_patterns;
- ExtensionsService* service = Source<ExtensionsService>(source).ptr();
+ ExtensionsService* service =
+ Source<Profile>(source).ptr()->GetExtensionsService();
for (ExtensionList::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it) {
if (*it != unloaded_extension)
diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc
index 14a9d0e..2f87798 100644
--- a/chrome/browser/extensions/user_script_listener_unittest.cc
+++ b/chrome/browser/extensions/user_script_listener_unittest.cc
@@ -180,6 +180,38 @@ class ResourceDispatcherHostTester
std::vector<int> completed_requests_;
};
+class ExtensionTestingProfile : public TestingProfile {
+ public:
+ ExtensionTestingProfile() {
+ }
+
+ FilePath GetExtensionsInstallDir() {
+ return GetPath().AppendASCII(ExtensionsService::kInstallDirectoryName);
+ }
+
+ void InitializeExtensionsService() {
+ DCHECK(!GetExtensionsService());
+ service_ = new ExtensionsService(this,
+ CommandLine::ForCurrentProcess(),
+ GetPrefs(),
+ GetExtensionsInstallDir(),
+ false);
+ service_->set_extensions_enabled(true);
+ service_->set_show_extensions_prompts(false);
+ service_->ClearProvidersForTesting();
+ service_->Init();
+ }
+
+ virtual ExtensionsService* GetExtensionsService() {
+ return service_.get();
+ }
+
+ private:
+ scoped_refptr<ExtensionsService> service_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionTestingProfile);
+};
+
class UserScriptListenerTest : public testing::Test {
public:
virtual void SetUp() {
@@ -196,17 +228,9 @@ class UserScriptListenerTest : public testing::Test {
resource_tester_ = new ResourceDispatcherHostTester();
- master_ = new MockUserScriptMaster(install_dir);
+ master_ = new MockUserScriptMaster(profile_.GetExtensionsInstallDir());
- service_ = new ExtensionsService(&profile_,
- CommandLine::ForCurrentProcess(),
- profile_.GetPrefs(),
- install_dir,
- false);
- service_->set_extensions_enabled(true);
- service_->set_show_extensions_prompts(false);
- service_->ClearProvidersForTesting();
- service_->Init();
+ profile_.InitializeExtensionsService();
}
virtual void TearDown() {
@@ -217,14 +241,13 @@ class UserScriptListenerTest : public testing::Test {
}
protected:
- TestingProfile profile_;
+ ExtensionTestingProfile profile_;
MessageLoopForUI loop_;
scoped_ptr<ChromeThread> ui_thread_;
scoped_ptr<ChromeThread> file_thread_;
scoped_ptr<MockIOThread> io_thread_;
scoped_refptr<ResourceDispatcherHostTester> resource_tester_;
scoped_refptr<MockUserScriptMaster> master_;
- scoped_refptr<ExtensionsService> service_;
};
// Loads a single extension and ensures that requests to URLs with content
@@ -238,9 +261,9 @@ TEST_F(UserScriptListenerTest, SingleExtension) {
.AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0");
- service_->LoadExtension(ext1);
+ profile_.GetExtensionsService()->LoadExtension(ext1);
loop_.RunAllPending();
- ASSERT_EQ(1u, service_->extensions()->size());
+ ASSERT_EQ(1u, profile_.GetExtensionsService()->extensions()->size());
// Our extension has a content script on google.com. That request should be
// delayed.
@@ -271,18 +294,18 @@ TEST_F(UserScriptListenerTest, UnloadExtension) {
.AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0");
- service_->LoadExtension(ext1);
+ profile_.GetExtensionsService()->LoadExtension(ext1);
loop_.RunAllPending();
- ASSERT_EQ(1u, service_->extensions()->size());
+ ASSERT_EQ(1u, profile_.GetExtensionsService()->extensions()->size());
FilePath ext2 = extensions_path
.AppendASCII("good")
.AppendASCII("Extensions")
.AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa")
.AppendASCII("1.0");
- service_->LoadExtension(ext2);
+ profile_.GetExtensionsService()->LoadExtension(ext2);
loop_.RunAllPending();
- ASSERT_EQ(2u, service_->extensions()->size());
+ ASSERT_EQ(2u, profile_.GetExtensionsService()->extensions()->size());
// Our extension has a content script on google.com. That request should be
// delayed.
@@ -294,7 +317,8 @@ TEST_F(UserScriptListenerTest, UnloadExtension) {
EXPECT_TRUE(resource_tester_->IsRequestComplete(1));
// Unload the first extension and run a scan. Request should complete.
- service_->UnloadExtension("behllobkkfkfnphdnhnkndlbkcpglgmj");
+ profile_.GetExtensionsService()->UnloadExtension(
+ "behllobkkfkfnphdnhnkndlbkcpglgmj");
resource_tester_->WaitForScan(master_.get());
EXPECT_TRUE(resource_tester_->IsRequestStarted(0));