diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-30 16:11:27 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-30 16:11:27 +0000 |
commit | a307e31e82d2b9006802d4381dc5f3da2b993a8d (patch) | |
tree | e46d5b0b6ea59aa1fb7d47f917bc837b37dd88b8 | |
parent | 48a74f65c7775737ccee06a34eb5f73a5172172f (diff) | |
download | chromium_src-a307e31e82d2b9006802d4381dc5f3da2b993a8d.zip chromium_src-a307e31e82d2b9006802d4381dc5f3da2b993a8d.tar.gz chromium_src-a307e31e82d2b9006802d4381dc5f3da2b993a8d.tar.bz2 |
Integrate BlacklistManager with Profile.
Now each Profile has a BlacklistManager that maintains a compiled Blacklist for that Profile.
The system does not yet pause user-initiated web requests until the blacklist system is ready. However, the code is not supposed to be ready, and is hidden behind a --enable-privacy-blacklists command-line flag.
TEST=Covered by browser_test.
BUG=21541
Review URL: http://codereview.chromium.org/371063
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33290 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 315 insertions, 229 deletions
diff --git a/chrome/browser/automation/automation_profile_impl.cc b/chrome/browser/automation/automation_profile_impl.cc index ca208f6..62d9cde 100644 --- a/chrome/browser/automation/automation_profile_impl.cc +++ b/chrome/browser/automation/automation_profile_impl.cc @@ -38,9 +38,6 @@ class AutomationURLRequestContext : public ChromeURLRequestContext { ftp_transaction_factory_ = NULL; cookie_store_ = NULL; strict_transport_security_state_ = NULL; - - // Clear ChromeURLRequestContext members. - blacklist_ = NULL; } scoped_refptr<ChromeURLRequestContext> original_context_; diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index b185150..2772660 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -750,6 +750,10 @@ void ExtensionsService::ReportExtensionLoadError( ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); } +bool ExtensionsService::AreBlacklistPathsReady() const { + return ready_; +} + std::vector<FilePath> ExtensionsService::GetPersistentBlacklistPaths() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 4a91fff..8ac318e 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -221,6 +221,7 @@ class ExtensionsService bool be_noisy); // BlacklistPathProvider: + virtual bool AreBlacklistPathsReady() const; virtual std::vector<FilePath> GetPersistentBlacklistPaths(); virtual std::vector<FilePath> GetTransientBlacklistPaths(); diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index db31bb2..bf008aa 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -13,6 +13,7 @@ #include "chrome/browser/extensions/user_script_master.h" #include "chrome/browser/net/sqlite_persistent_cookie_store.h" #include "chrome/browser/net/dns_global.h" +#include "chrome/browser/privacy_blacklist/blacklist_manager.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -35,10 +36,6 @@ #endif namespace { -// TODO(eroman): The ChromeURLRequestContext's Blacklist* is shared with the -// Profile... This is a problem since the Profile dies before -// the IO thread, so we may end up accessing a deleted variable. -// http://crbug.com/26733. // ---------------------------------------------------------------------------- // Helper methods to check current thread @@ -687,7 +684,7 @@ bool ChromeURLRequestContext::InterceptCookie(const URLRequest* request, const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d); if (match->attributes() & Blacklist::kDontStoreCookies) { NotificationService::current()->Notify( - NotificationType::BLACKLIST_BLOCKED_RESOURCE, + NotificationType::BLACKLIST_NONVISUAL_RESOURCE_BLOCKED, Source<const ChromeURLRequestContext>(this), Details<const URLRequest>(request)); @@ -709,7 +706,7 @@ bool ChromeURLRequestContext::AllowSendingCookies(const URLRequest* request) const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d); if (match->attributes() & Blacklist::kDontSendCookies) { NotificationService::current()->Notify( - NotificationType::BLACKLIST_BLOCKED_RESOURCE, + NotificationType::BLACKLIST_NONVISUAL_RESOURCE_BLOCKED, Source<const ChromeURLRequestContext>(this), Details<const URLRequest>(request)); @@ -719,6 +716,13 @@ bool ChromeURLRequestContext::AllowSendingCookies(const URLRequest* request) return true; } +const Blacklist* ChromeURLRequestContext::GetBlacklist() const { + // TODO(phajdan.jr): Remove the check when Privacy Blacklists become stable. + if (!blacklist_manager_) + return NULL; + return blacklist_manager_->GetCompiledBlacklist(); +} + void ChromeURLRequestContext::OnNewExtensions(const std::string& id, const FilePath& path) { if (!is_off_the_record_) @@ -753,13 +757,18 @@ ChromeURLRequestContext::ChromeURLRequestContext( // Set ChromeURLRequestContext members appcache_service_ = other->appcache_service_; + blacklist_manager_ = other->blacklist_manager_; extension_paths_ = other->extension_paths_; user_script_dir_path_ = other->user_script_dir_path_; - blacklist_ = other->blacklist_; is_media_ = other->is_media_; is_off_the_record_ = other->is_off_the_record_; } +void ChromeURLRequestContext::set_blacklist_manager( + BlacklistManager* blacklist_manager) { + blacklist_manager_ = blacklist_manager; +} + void ChromeURLRequestContext::OnAcceptLanguageChange( const std::string& accept_language) { CheckCurrentlyOnIOThread(); @@ -820,8 +829,7 @@ ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile) cookie_policy_type_ = net::CookiePolicy::FromInt( prefs->GetInteger(prefs::kCookieBehavior)); - // TODO(eroman): this doesn't look safe; sharing between IO and UI threads! - blacklist_ = profile->GetBlacklist(); + blacklist_manager_ = profile->GetBlacklistManager(); // TODO(eroman): this doesn't look safe; sharing between IO and UI threads! strict_transport_security_state_ = profile->GetStrictTransportSecurityState(); @@ -860,7 +868,7 @@ void ChromeURLRequestContextFactory::ApplyProfileParametersToContext( context->set_cookie_policy_type(cookie_policy_type_); context->set_extension_paths(extension_paths_); context->set_user_script_dir_path(user_script_dir_path_); - context->set_blacklist(blacklist_); + context->set_blacklist_manager(blacklist_manager_.get()); context->set_strict_transport_security_state( strict_transport_security_state_); context->set_ssl_config_service(ssl_config_service_); diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 88b4428..0d9bed040 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -13,6 +13,7 @@ #include "net/url_request/url_request_context.h" class Blacklist; +class BlacklistManager; class CommandLine; class Profile; @@ -178,7 +179,7 @@ class ChromeURLRequestContext : public URLRequestContext { virtual bool AllowSendingCookies(const URLRequest* request) const; // Gets the Privacy Blacklist, if any for this context. - const Blacklist* blacklist() const { return blacklist_; } + const Blacklist* GetBlacklist() const; // Callback for when new extensions are loaded. void OnNewExtensions(const std::string& id, const FilePath& path); @@ -242,9 +243,7 @@ class ChromeURLRequestContext : public URLRequestContext { void set_extension_paths(const ExtensionPaths& paths) { extension_paths_ = paths; } - void set_blacklist(const Blacklist* blacklist) { - blacklist_ = blacklist; - } + void set_blacklist_manager(BlacklistManager* blacklist_manager); void set_appcache_service(ChromeAppCacheService* service) { appcache_service_ = service; } @@ -267,8 +266,8 @@ class ChromeURLRequestContext : public URLRequestContext { FilePath user_script_dir_path_; scoped_refptr<ChromeAppCacheService> appcache_service_; + scoped_refptr<BlacklistManager> blacklist_manager_; - const Blacklist* blacklist_; bool is_media_; bool is_off_the_record_; @@ -309,7 +308,7 @@ class ChromeURLRequestContextFactory { net::CookiePolicy::Type cookie_policy_type_; ChromeURLRequestContext::ExtensionPaths extension_paths_; FilePath user_script_dir_path_; - Blacklist* blacklist_; + scoped_refptr<BlacklistManager> blacklist_manager_; net::StrictTransportSecurityState* strict_transport_security_state_; scoped_refptr<net::SSLConfigService> ssl_config_service_; diff --git a/chrome/browser/privacy_blacklist/blacklist_manager.cc b/chrome/browser/privacy_blacklist/blacklist_manager.cc index 2a9f4c7..ca8dc0b 100644 --- a/chrome/browser/privacy_blacklist/blacklist_manager.cc +++ b/chrome/browser/privacy_blacklist/blacklist_manager.cc @@ -12,6 +12,7 @@ #include "chrome/browser/privacy_blacklist/blacklist_io.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_constants.h" +#include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" @@ -19,27 +20,35 @@ BlacklistPathProvider::~BlacklistPathProvider() { } -BlacklistManager::BlacklistManager() +BlacklistManager::BlacklistManager(Profile* profile, + BlacklistPathProvider* path_provider) : first_read_finished_(false), - profile_(NULL), - path_provider_(NULL) { + profile_(profile), + compiled_blacklist_path_( + profile->GetPath().Append(chrome::kPrivacyBlacklistFileName)), + path_provider_(path_provider) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); -} - -void BlacklistManager::Initialize(Profile* profile, - BlacklistPathProvider* path_provider) { - profile_ = profile; - compiled_blacklist_path_ = - profile->GetPath().Append(chrome::kPrivacyBlacklistFileName); - path_provider_ = path_provider; + DCHECK(path_provider_); registrar_.Add(this, + NotificationType::EXTENSIONS_READY, + Source<Profile>(profile)); + registrar_.Add(this, NotificationType::EXTENSION_LOADED, Source<Profile>(profile)); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, Source<Profile>(profile)); - ReadBlacklist(); +} + +void BlacklistManager::Initialize() { + if (path_provider_->AreBlacklistPathsReady()) + ReadBlacklist(); +} + +const Blacklist* BlacklistManager::GetCompiledBlacklist() const { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + return compiled_blacklist_.get(); } void BlacklistManager::Observe(NotificationType type, @@ -48,8 +57,23 @@ void BlacklistManager::Observe(NotificationType type, DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); switch (type.value) { + case NotificationType::EXTENSIONS_READY: + ReadBlacklist(); + break; case NotificationType::EXTENSION_LOADED: case NotificationType::EXTENSION_UNLOADED: + // Don't do anything if the path provider isn't ready. We're going to get + // the paths when it becomes ready. + // This makes an assumption that it isn't possible to install an extension + // before ExtensionsService becomes ready. + if (!path_provider_->AreBlacklistPathsReady()) + break; + + // We don't need to recompile the on-disk blacklist when the extension + // doesn't have any blacklist. + if (Details<Extension>(details).ptr()->privacy_blacklists().empty()) + break; + CompileBlacklist(); break; default: @@ -58,8 +82,12 @@ void BlacklistManager::Observe(NotificationType type, } } +BlacklistManager::~BlacklistManager() { +} + void BlacklistManager::CompileBlacklist() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + DCHECK(path_provider_->AreBlacklistPathsReady()); ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, NewRunnableMethod(this, &BlacklistManager::DoCompileBlacklist, @@ -71,10 +99,8 @@ void BlacklistManager::DoCompileBlacklist( DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); bool success = true; - Blacklist blacklist; std::string error_string; - for (std::vector<FilePath>::const_iterator i = source_blacklists.begin(); i != source_blacklists.end(); ++i) { if (!BlacklistIO::ReadText(&blacklist, *i, &error_string)) { @@ -109,6 +135,7 @@ void BlacklistManager::OnBlacklistCompilationFinished(bool success) { void BlacklistManager::ReadBlacklist() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + DCHECK(path_provider_->AreBlacklistPathsReady()); ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, NewRunnableMethod(this, &BlacklistManager::DoReadBlacklist, @@ -120,54 +147,53 @@ void BlacklistManager::DoReadBlacklist( DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); scoped_ptr<Blacklist> blacklist(new Blacklist); - if (!BlacklistIO::ReadBinary(blacklist.get(), compiled_blacklist_path_)) { - ReportBlacklistReadResult(NULL); - return; - } - - std::string error_string; - std::vector<FilePath>::const_iterator i; - for (i = transient_blacklists.begin(); - i != transient_blacklists.end(); ++i) { - if (!BlacklistIO::ReadText(blacklist.get(), *i, &error_string)) { - ReportBlacklistReadResult(NULL); - return; + if (BlacklistIO::ReadBinary(blacklist.get(), compiled_blacklist_path_)) { + std::string error_string; + std::vector<FilePath>::const_iterator i; + for (i = transient_blacklists.begin(); + i != transient_blacklists.end(); ++i) { + if (!BlacklistIO::ReadText(blacklist.get(), *i, &error_string)) { + blacklist.reset(); + break; + } } + } else { + blacklist.reset(); } - - ReportBlacklistReadResult(blacklist.release()); + ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, + &BlacklistManager::UpdatePublishedCompiledBlacklist, + blacklist.release())); } -void BlacklistManager::ReportBlacklistReadResult(Blacklist* blacklist) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); +void BlacklistManager::UpdatePublishedCompiledBlacklist(Blacklist* blacklist) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + if (blacklist) + compiled_blacklist_.reset(blacklist); ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, NewRunnableMethod(this, &BlacklistManager::OnBlacklistReadFinished, - blacklist)); + blacklist != NULL)); } -void BlacklistManager::OnBlacklistReadFinished(Blacklist* blacklist) { +void BlacklistManager::OnBlacklistReadFinished(bool success) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - if (!blacklist) { + if (success) { + NotificationService::current()->Notify( + NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, + Source<Profile>(profile_), + NotificationService::NoDetails()); + } else { + string16 error_message(ASCIIToUTF16("Blacklist read failed.")); + NotificationService::current()->Notify( + NotificationType::BLACKLIST_MANAGER_ERROR, + Source<Profile>(profile_), + Details<string16>(&error_message)); if (!first_read_finished_) { // If we're loading for the first time, the compiled blacklist could // just not exist. Try compiling it once. - first_read_finished_ = true; CompileBlacklist(); - } else { - string16 error_message(ASCIIToUTF16("Blacklist read failed.")); - NotificationService::current()->Notify( - NotificationType::BLACKLIST_MANAGER_ERROR, - Source<Profile>(profile_), - Details<string16>(&error_message)); } - return; } first_read_finished_ = true; - compiled_blacklist_.reset(blacklist); - - NotificationService::current()->Notify( - NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, - Source<Profile>(profile_), - Details<Blacklist>(blacklist)); } diff --git a/chrome/browser/privacy_blacklist/blacklist_manager.h b/chrome/browser/privacy_blacklist/blacklist_manager.h index ad401f7..5d6e97b 100644 --- a/chrome/browser/privacy_blacklist/blacklist_manager.h +++ b/chrome/browser/privacy_blacklist/blacklist_manager.h @@ -19,11 +19,20 @@ class Profile; class BlacklistPathProvider { public: - virtual ~BlacklistPathProvider(); + // Returns true if the provider is ready (has loaded the blacklist paths + // and we can query them). Called on UI thread. + virtual bool AreBlacklistPathsReady() const = 0; - // The methods below will be invoked on the UI thread. + // Returns paths that will still be there after browser shutdown + // (installed extensions). Called on UI thread. virtual std::vector<FilePath> GetPersistentBlacklistPaths() = 0; + + // Returns paths that will disappear after browser shutdown + // (unpacked extensions). Called on UI thread. virtual std::vector<FilePath> GetTransientBlacklistPaths() = 0; + + protected: + virtual ~BlacklistPathProvider(); }; // Updates one compiled binary blacklist based on a list of plaintext @@ -33,13 +42,15 @@ class BlacklistManager public base::RefCountedThreadSafe<BlacklistManager, ChromeThread::DeleteOnUIThread> { public: - BlacklistManager(); - void Initialize(Profile* profile, BlacklistPathProvider* path_provider); + // Create BlacklistManager (must be done on UI thread). + BlacklistManager(Profile* profile, BlacklistPathProvider* path_provider); + + // Initialize the BlacklistManager (on UI thread). + void Initialize(); - const Blacklist* GetCompiledBlacklist() const { - // TODO(phajdan.jr): Determine on which thread this should be invoked (IO?). - return compiled_blacklist_.get(); - } + // Returns compiled blacklist, or NULL if not ready. Only valid to call on IO + // thread. + const Blacklist* GetCompiledBlacklist() const; // NotificationObserver virtual void Observe(NotificationType type, @@ -54,7 +65,7 @@ class BlacklistManager friend class ChromeThread; friend class DeleteTask<BlacklistManager>; - ~BlacklistManager() {} + virtual ~BlacklistManager(); // Compile all persistent blacklists to one binary blacklist stored on disk. void CompileBlacklist(); @@ -62,11 +73,12 @@ class BlacklistManager void OnBlacklistCompilationFinished(bool success); // Read all blacklists from disk (the compiled one and also the transient - // blacklists). + // blacklists). In case of failure, if we haven't loaded any blacklist yet, + // we'll compile the blacklist and try to read it again. void ReadBlacklist(); void DoReadBlacklist(const std::vector<FilePath>& transient_blacklists); - void ReportBlacklistReadResult(Blacklist* blacklist); - void OnBlacklistReadFinished(Blacklist* blacklist); + void UpdatePublishedCompiledBlacklist(Blacklist* blacklist); + void OnBlacklistReadFinished(bool success); // True after the first blacklist read has finished (regardless of success). // Used to avoid an infinite loop. diff --git a/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc b/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc index b5d5316..a235df3 100644 --- a/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc +++ b/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc @@ -4,10 +4,12 @@ #include "chrome/browser/privacy_blacklist/blacklist_manager.h" +#include "base/command_line.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/profile.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_source.h" #include "chrome/test/in_process_browser_test.h" @@ -16,31 +18,32 @@ namespace { -// Returns true if |blacklist| contains a match for |url|. -bool BlacklistHasMatch(const Blacklist* blacklist, const char* url) { - Blacklist::Match* match = blacklist->findMatch(GURL(url)); - - if (!match) - return false; - - delete match; - return true; +void GetBlacklistHasMatchOnIOThread(const BlacklistManager* manager, + const GURL& url, + bool *has_match) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + const Blacklist* blacklist = manager->GetCompiledBlacklist(); + scoped_ptr<Blacklist::Match> match(blacklist->findMatch(url)); + *has_match = (match.get() != NULL); + ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, + new MessageLoop::QuitTask()); } } // namespace class BlacklistManagerBrowserTest : public ExtensionBrowserTest { public: - void InitializeBlacklistManager() { - Profile* profile = browser()->profile(); - blacklist_manager_ = new BlacklistManager(); - blacklist_manager_->Initialize(profile, profile->GetExtensionsService()); - WaitForBlacklistUpdate(); + virtual void SetUp() { + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnablePrivacyBlacklists); + ExtensionBrowserTest::SetUp(); } - virtual void CleanUpOnMainThread() { - blacklist_manager_ = NULL; - ExtensionBrowserTest::CleanUpOnMainThread(); + virtual void SetUpInProcessBrowserTestFixture() { + ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); + + received_blacklist_notification_ = false; + host_resolver()->AddSimulatedFailure("www.example.com"); } // NotificationObserver @@ -52,48 +55,55 @@ class BlacklistManagerBrowserTest : public ExtensionBrowserTest { ExtensionBrowserTest::Observe(type, source, details); return; } + received_blacklist_notification_ = true; MessageLoop::current()->Quit(); } protected: - void WaitForBlacklistUpdate() { - NotificationRegistrar registrar; - registrar.Add(this, - NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, - Source<Profile>(browser()->profile())); + BlacklistManager* GetBlacklistManager() { + return browser()->profile()->GetBlacklistManager(); + } + + bool GetAndResetReceivedBlacklistNotification() { + bool result = received_blacklist_notification_; + received_blacklist_notification_ = false; + return result; + } + + bool BlacklistHasMatch(const std::string& url) { + bool has_match = false; + ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, + NewRunnableFunction(GetBlacklistHasMatchOnIOThread, + GetBlacklistManager(), + GURL(url), + &has_match)); ui_test_utils::RunMessageLoop(); + return has_match; } - scoped_refptr<BlacklistManager> blacklist_manager_; + private: + bool received_blacklist_notification_; }; IN_PROC_BROWSER_TEST_F(BlacklistManagerBrowserTest, Basic) { - static const char kTestUrl[] = "http://host/annoying_ads/ad.jpg"; + static const char kTestUrl[] = "http://www.example.com/annoying_ads/ad.jpg"; - InitializeBlacklistManager(); - ASSERT_TRUE(blacklist_manager_->GetCompiledBlacklist()); - EXPECT_FALSE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(), - kTestUrl)); + NotificationRegistrar registrar; + registrar.Add(this, + NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, + Source<Profile>(browser()->profile())); // Test loading an extension with blacklist. ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII("common").AppendASCII("privacy_blacklist"))); - if (!BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(), - kTestUrl)) { - WaitForBlacklistUpdate(); - } - EXPECT_TRUE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(), - kTestUrl)); - - // Make sure that after unloading the extension we update the blacklist. - ExtensionsService* extensions_service = - browser()->profile()->GetExtensionsService(); - ASSERT_EQ(1U, extensions_service->extensions()->size()); - UnloadExtension(extensions_service->extensions()->front()->id()); - if (BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(), - kTestUrl)) { - WaitForBlacklistUpdate(); - } - EXPECT_FALSE(BlacklistHasMatch(blacklist_manager_->GetCompiledBlacklist(), - kTestUrl)); + + // Wait until the blacklist is loaded and ready. + if (!GetAndResetReceivedBlacklistNotification()) + ui_test_utils::RunMessageLoop(); + + // The blacklist should block our test URL. + EXPECT_TRUE(BlacklistHasMatch(kTestUrl)); + + // TODO(phajdan.jr): Verify that we really blocked the request etc. + ui_test_utils::NavigateToURL(browser(), GURL(kTestUrl)); } diff --git a/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc index 42ed8e53..2b48b5c 100644 --- a/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc +++ b/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc @@ -8,9 +8,11 @@ #include "base/path_service.h" #include "base/scoped_temp_dir.h" #include "base/thread.h" +#include "base/values.h" #include "chrome/browser/privacy_blacklist/blacklist.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/notification_service.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" @@ -35,6 +37,10 @@ class TestBlacklistPathProvider : public BlacklistPathProvider { explicit TestBlacklistPathProvider(Profile* profile) : profile_(profile) { } + virtual bool AreBlacklistPathsReady() const { + return true; + } + virtual std::vector<FilePath> GetPersistentBlacklistPaths() { return persistent_paths_; } @@ -61,12 +67,25 @@ class TestBlacklistPathProvider : public BlacklistPathProvider { private: void SendUpdateNotification() { + ListValue* privacy_blacklists = new ListValue; + privacy_blacklists->Append(new StringValue("dummy.pbl")); + + DictionaryValue manifest; + manifest.SetString(extension_manifest_keys::kVersion, "1.0"); + manifest.SetString(extension_manifest_keys::kName, "test"); + manifest.Set(extension_manifest_keys::kPrivacyBlacklists, + privacy_blacklists); + #if defined(OS_WIN) FilePath path(FILE_PATH_LITERAL("c:\\foo")); #elif defined(OS_POSIX) FilePath path(FILE_PATH_LITERAL("/foo")); #endif Extension extension(path); + std::string error; + ASSERT_TRUE(extension.InitFromValue(manifest, false, &error)); + ASSERT_TRUE(error.empty()); + NotificationService::current()->Notify( NotificationType::EXTENSION_LOADED, Source<Profile>(profile_), @@ -86,7 +105,8 @@ class BlacklistManagerTest : public testing::Test, public NotificationObserver { BlacklistManagerTest() : path_provider_(&profile_), mock_ui_thread_(ChromeThread::UI, MessageLoop::current()), - mock_file_thread_(ChromeThread::FILE) { + mock_file_thread_(ChromeThread::FILE), + mock_io_thread_(ChromeThread::IO, MessageLoop::current()) { } virtual void SetUp() { @@ -135,6 +155,7 @@ class BlacklistManagerTest : public testing::Test, public NotificationObserver { ChromeThread mock_ui_thread_; ChromeThread mock_file_thread_; + ChromeThread mock_io_thread_; }; // Returns true if |blacklist| contains a match for |url|. @@ -149,8 +170,9 @@ bool BlacklistHasMatch(const Blacklist* blacklist, const char* url) { } TEST_F(BlacklistManagerTest, Basic) { - scoped_refptr<BlacklistManager> manager(new BlacklistManager()); - manager->Initialize(&profile_, &path_provider_); + scoped_refptr<BlacklistManager> manager( + new BlacklistManager(&profile_, &path_provider_)); + manager->Initialize(); WaitForBlacklistUpdate(); const Blacklist* blacklist = manager->GetCompiledBlacklist(); @@ -161,8 +183,9 @@ TEST_F(BlacklistManagerTest, Basic) { } TEST_F(BlacklistManagerTest, BlacklistPathProvider) { - scoped_refptr<BlacklistManager> manager(new BlacklistManager()); - manager->Initialize(&profile_, &path_provider_); + scoped_refptr<BlacklistManager> manager( + new BlacklistManager(&profile_, &path_provider_)); + manager->Initialize(); WaitForBlacklistUpdate(); const Blacklist* blacklist1 = manager->GetCompiledBlacklist(); @@ -196,8 +219,8 @@ TEST_F(BlacklistManagerTest, BlacklistPathProvider) { path_provider_.clear(); path_provider_.AddPersistentPath( test_data_dir_.AppendASCII("annoying_ads.pbl")); - manager = new BlacklistManager(); - manager->Initialize(&profile_, &path_provider_); + manager = new BlacklistManager(&profile_, &path_provider_); + manager->Initialize(); WaitForBlacklistUpdate(); const Blacklist* blacklist4 = manager->GetCompiledBlacklist(); @@ -207,8 +230,9 @@ TEST_F(BlacklistManagerTest, BlacklistPathProvider) { } TEST_F(BlacklistManagerTest, BlacklistPathReadError) { - scoped_refptr<BlacklistManager> manager(new BlacklistManager()); - manager->Initialize(&profile_, &path_provider_); + scoped_refptr<BlacklistManager> manager( + new BlacklistManager(&profile_, &path_provider_)); + manager->Initialize(); WaitForBlacklistUpdate(); FilePath bogus_path(test_data_dir_.AppendASCII("does_not_exist_randomness")); @@ -224,8 +248,9 @@ TEST_F(BlacklistManagerTest, CompiledBlacklistReadError) { FilePath compiled_blacklist_path; { - scoped_refptr<BlacklistManager> manager(new BlacklistManager()); - manager->Initialize(&profile_, &path_provider_); + scoped_refptr<BlacklistManager> manager( + new BlacklistManager(&profile_, &path_provider_)); + manager->Initialize(); WaitForBlacklistUpdate(); path_provider_.AddPersistentPath( @@ -242,8 +267,9 @@ TEST_F(BlacklistManagerTest, CompiledBlacklistReadError) { ASSERT_TRUE(file_util::Delete(compiled_blacklist_path, false)); { - scoped_refptr<BlacklistManager> manager(new BlacklistManager()); - manager->Initialize(&profile_, &path_provider_); + scoped_refptr<BlacklistManager> manager( + new BlacklistManager(&profile_, &path_provider_)); + manager->Initialize(); WaitForBlacklistUpdate(); // The manager should recompile the blacklist. diff --git a/chrome/browser/privacy_blacklist/blacklist_observer.h b/chrome/browser/privacy_blacklist/blacklist_observer.h deleted file mode 100644 index a545ac8..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_observer.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_OBSERVER_H_ -#define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_OBSERVER_H_ - -class URLRequest; - -class BlacklistObserver { - public: - // Called when non-visual content is blocked by the privacy blacklist. - static void ContentBlocked(const URLRequest* request); -}; - -#endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_OBSERVER_H_ diff --git a/chrome/browser/privacy_blacklist/blacklist_observer.cc b/chrome/browser/privacy_blacklist/blacklist_ui.cc index b62d0c8..6d2327e 100644 --- a/chrome/browser/privacy_blacklist/blacklist_observer.cc +++ b/chrome/browser/privacy_blacklist/blacklist_ui.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/privacy_blacklist/blacklist_observer.h" +#include "chrome/browser/privacy_blacklist/blacklist_ui.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" @@ -14,38 +14,40 @@ #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/notification_details.h" -#include "chrome/common/notification_service.h" -#include "chrome/common/notification_type.h" #include "grit/generated_resources.h" -class BlockedContentNotice : public Task { +// Displays more info why some content has been blocked. +class DisplayBlockedContentNoticeTask : public Task { public: - BlockedContentNotice(const GURL& gurl, - const Blacklist::Match* match, - const ResourceDispatcherHostRequestInfo* info) + DisplayBlockedContentNoticeTask(const GURL& gurl, + const Blacklist::Match* match, + const ResourceDispatcherHostRequestInfo* info) : gurl_(gurl), match_(match), child_id_(info->child_id()), route_id_(info->route_id()) { + } + + virtual void Run() { + RenderViewHost* view = RenderViewHost::FromID(child_id_, route_id_); + if (!view) + return; // The view may be gone by the time we get here. + + string16 reason; if (match_->attributes() & Blacklist::kDontStoreCookies) { // No cookies stored. - reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES); + reason = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES); } else if (match_->attributes() & Blacklist::kDontSendCookies) { // No cookies sent. - reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES); + reason = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES); } else if (match_->attributes() & Blacklist::kDontSendReferrer) { // No referrer sent. - reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_REFERRER); + reason = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_REFERRER); + } else { + NOTREACHED(); } - } - virtual void Run() { - RenderViewHost* view = RenderViewHost::FromID(child_id_, route_id_); - if (!view) - return; // The view may be gone by the time we get here. - - view->delegate()->AddBlockedNotice(gurl_, reason_); + view->delegate()->AddBlockedNotice(gurl_, reason); } private: @@ -54,10 +56,13 @@ class BlockedContentNotice : public Task { const int child_id_; const int route_id_; - string16 reason_; + DISALLOW_COPY_AND_ASSIGN(DisplayBlockedContentNoticeTask); }; -void BlacklistObserver::ContentBlocked(const URLRequest* request) { +// static +void BlacklistUI::OnNonvisualContentBlocked(const URLRequest* request) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + const URLRequest::UserData* d = request->GetUserData(&Blacklist::kRequestDataKey); const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d); @@ -68,5 +73,5 @@ void BlacklistObserver::ContentBlocked(const URLRequest* request) { // Notify the UI that something non-visual has been blocked. ChromeThread::PostTask( ChromeThread::UI, FROM_HERE, - new BlockedContentNotice(gurl, match, info)); + new DisplayBlockedContentNoticeTask(gurl, match, info)); } diff --git a/chrome/browser/privacy_blacklist/blacklist_ui.h b/chrome/browser/privacy_blacklist/blacklist_ui.h new file mode 100644 index 0000000..ce76ad8 --- /dev/null +++ b/chrome/browser/privacy_blacklist/blacklist_ui.h @@ -0,0 +1,18 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_UI_H_ +#define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_UI_H_ + +class URLRequest; + +// Set of routines to display blacklist-related UI. +class BlacklistUI { + public: + // Called on IO thread when non-visual content is blocked by a privacy + // blacklist. + static void OnNonvisualContentBlocked(const URLRequest* request); +}; + +#endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_UI_H_ diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 4204c8a..c32e1a9 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -32,7 +32,7 @@ #include "chrome/browser/net/ssl_config_service_manager.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/password_manager/password_store_default.h" -#include "chrome/browser/privacy_blacklist/blacklist_io.h" +#include "chrome/browser/privacy_blacklist/blacklist_manager.h" #include "chrome/browser/profile_manager.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/search_versus_navigate_classifier.h" @@ -404,8 +404,8 @@ class OffTheRecordProfileImpl : public Profile, return GetOriginalProfile()->GetSSLConfigService(); } - virtual Blacklist* GetBlacklist() { - return GetOriginalProfile()->GetBlacklist(); + virtual BlacklistManager* GetBlacklistManager() { + return GetOriginalProfile()->GetBlacklistManager(); } virtual SessionService* GetSessionService() { @@ -570,7 +570,8 @@ ProfileImpl::ProfileImpl(const FilePath& path) request_context_(NULL), media_request_context_(NULL), extensions_request_context_(NULL), - blacklist_(NULL), + blacklist_manager_(NULL), + blacklist_manager_created_(false), history_service_created_(false), favicon_service_created_(false), created_web_data_service_(false), @@ -600,20 +601,6 @@ ProfileImpl::ProfileImpl(const FilePath& path) prefs->AddPrefObserver(prefs::kEnableSpellCheck, this); prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this); - if (CommandLine::ForCurrentProcess()-> - HasSwitch(switches::kPrivacyBlacklist)) { - std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue( - switches::kPrivacyBlacklist); -#if defined(OS_POSIX) - FilePath path(WideToUTF8(option)); -#else - FilePath path(option); -#endif - blacklist_.reset(new Blacklist); - // TODO(phajdan.jr): Handle errors when reading blacklist. - BlacklistIO::ReadBinary(blacklist_.get(), path); - } - #if defined(OS_MACOSX) // If the profile directory doesn't already have a cache directory and it // is under ~/Library/Application Support, use a suitable cache directory @@ -758,9 +745,6 @@ ProfileImpl::~ProfileImpl() { CleanupRequestContext(media_request_context_); CleanupRequestContext(extensions_request_context_); - // When the request contexts are gone, the blacklist wont be needed anymore. - blacklist_.reset(); - // HistoryService may call into the BookmarkModel, as such we need to // delete HistoryService before the BookmarkModel. The destructor for // HistoryService will join with HistoryService's backend thread so that @@ -972,8 +956,17 @@ net::SSLConfigService* ProfileImpl::GetSSLConfigService() { return ssl_config_service_manager_->Get(); } -Blacklist* ProfileImpl::GetBlacklist() { - return blacklist_.get(); +BlacklistManager* ProfileImpl::GetBlacklistManager() { + if (!CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnablePrivacyBlacklists)) { + return NULL; + } + if (!blacklist_manager_created_) { + blacklist_manager_created_ = true; + blacklist_manager_ = new BlacklistManager(this, GetExtensionsService()); + blacklist_manager_->Initialize(); + } + return blacklist_manager_.get(); } HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index c931f31..010744a 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -31,7 +31,7 @@ namespace webkit_database { class DatabaseTracker; } -class Blacklist; +class BlacklistManager; class BookmarkModel; class BrowserThemeProvider; class ChromeURLRequestContextGetter; @@ -286,8 +286,8 @@ class Profile { // Returns the SSLConfigService for this profile. virtual net::SSLConfigService* GetSSLConfigService() = 0; - // Returns the Privacy Blaclist for this profile. - virtual Blacklist* GetBlacklist() = 0; + // Returns the Privacy Blacklist Manager for this profile. + virtual BlacklistManager* GetBlacklistManager() = 0; // Returns the session service for this profile. This may return NULL. If // this profile supports a session service (it isn't off the record), and @@ -438,7 +438,7 @@ class ProfileImpl : public Profile, virtual URLRequestContextGetter* GetRequestContextForMedia(); virtual URLRequestContextGetter* GetRequestContextForExtensions(); virtual net::SSLConfigService* GetSSLConfigService(); - virtual Blacklist* GetBlacklist(); + virtual BlacklistManager* GetBlacklistManager(); virtual SessionService* GetSessionService(); virtual void ShutdownSessionService(); virtual bool HasSessionService() const; @@ -525,8 +525,7 @@ class ProfileImpl : public Profile, scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_; - scoped_ptr<Blacklist> blacklist_; - + scoped_refptr<BlacklistManager> blacklist_manager_; scoped_refptr<DownloadManager> download_manager_; scoped_refptr<HistoryService> history_service_; scoped_refptr<FaviconService> favicon_service_; @@ -538,6 +537,7 @@ class ProfileImpl : public Profile, scoped_refptr<WebKitContext> webkit_context_; scoped_ptr<DesktopNotificationService> desktop_notification_service_; scoped_ptr<PersonalDataManager> personal_data_manager_; + bool blacklist_manager_created_; bool history_service_created_; bool favicon_service_created_; bool created_web_data_service_; diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 7203cd9..036d907 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -421,8 +421,8 @@ void ResourceDispatcherHost::BeginRequest( std::string url = request_data.url.spec(); // Note that context can still be NULL here when running unit tests. - Blacklist::Match* match = context && context->blacklist() ? - context->blacklist()->findMatch(request_data.url) : NULL; + Blacklist::Match* match = context && context->GetBlacklist() ? + context->GetBlacklist()->findMatch(request_data.url) : NULL; if (match && match->IsBlocked(request_data.url)) { // This is a special path where calling happens without the URLRequest // being created, so we must delete the match ourselves. Ensures this diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index cb29433..8006960 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -25,7 +25,7 @@ #include "chrome/browser/plugin_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_observer.h" +#include "chrome/browser/privacy_blacklist/blacklist_ui.h" #include "chrome/browser/renderer_host/audio_renderer_host.h" #include "chrome/browser/renderer_host/browser_render_process_host.h" #include "chrome/browser/renderer_host/database_dispatcher_host.h" @@ -211,7 +211,7 @@ void ResourceMessageFilter::OnFilterAdded(IPC::Channel* channel) { channel_ = channel; // Add the observers to intercept. - registrar_.Add(this, NotificationType::BLACKLIST_BLOCKED_RESOURCE, + registrar_.Add(this, NotificationType::BLACKLIST_NONVISUAL_RESOURCE_BLOCKED, NotificationService::AllSources()); } @@ -465,16 +465,16 @@ void ResourceMessageFilter::OnSetCookie(const GURL& url, ChromeURLRequestContext* context = GetRequestContextForURL(url); if (context->cookie_policy()->CanSetCookie(url, first_party_for_cookies)) { - if (context->blacklist()) { - Blacklist::Match* match = context->blacklist()->findMatch(url); - if (match) { + const Blacklist* blacklist = context->GetBlacklist(); + if (blacklist) { + scoped_ptr<Blacklist::Match> match(blacklist->findMatch(url)); + if (match.get()) { if (match->attributes() & Blacklist::kDontPersistCookies) { context->cookie_store()->SetCookie(url, Blacklist::StripCookieExpiry(cookie)); } else if (!(match->attributes() & Blacklist::kDontStoreCookies)) { context->cookie_store()->SetCookie(url, cookie); } - delete match; return; } } @@ -1020,8 +1020,9 @@ void ResourceMessageFilter::OnUpdateSpellingPanelWithMisspelledWord( void ResourceMessageFilter::Observe(NotificationType type, const NotificationSource &source, const NotificationDetails &details) { - if (type == NotificationType::BLACKLIST_BLOCKED_RESOURCE) { - BlacklistObserver::ContentBlocked(Details<const URLRequest>(details).ptr()); + if (type == NotificationType::BLACKLIST_NONVISUAL_RESOURCE_BLOCKED) { + BlacklistUI::OnNonvisualContentBlocked( + Details<const URLRequest>(details).ptr()); } } diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index c46e5e5..3fec795 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1968,12 +1968,12 @@ 'browser/privacy_blacklist/blacklist.cc', 'browser/privacy_blacklist/blacklist_io.h', 'browser/privacy_blacklist/blacklist_io.cc', - 'browser/privacy_blacklist/blacklist_observer.h', - 'browser/privacy_blacklist/blacklist_observer.cc', 'browser/privacy_blacklist/blacklist_manager.h', 'browser/privacy_blacklist/blacklist_manager.cc', 'browser/privacy_blacklist/blacklist_store.h', 'browser/privacy_blacklist/blacklist_store.cc', + 'browser/privacy_blacklist/blacklist_ui.h', + 'browser/privacy_blacklist/blacklist_ui.cc', 'browser/privacy_blacklist/blocked_response.h', 'browser/privacy_blacklist/blocked_response.cc', 'browser/process_info_snapshot_mac.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index f15b105..9b310bc 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -215,6 +215,9 @@ const char kEnableNativeWebWorkers[] = "enable-native-web-workers"; // Enable AutoFill++. const char kEnableNewAutoFill[] = "enable-new-autofill"; +// Enable Privacy Blacklists. +const char kEnablePrivacyBlacklists[] = "enable-privacy-blacklists"; + // Enable remote web font support. SVG font should always work whether // this option is specified or not. const char kEnableRemoteFonts[] = "enable-remote-fonts"; @@ -428,10 +431,6 @@ const char kPluginStartupDialog[] = "plugin-startup-dialog"; // Prints the pages on the screen. const char kPrint[] = "print"; -// Enables the Privacy Blacklist with the specified data file. -// The file contains data from all imported blacklists. -const char kPrivacyBlacklist[] = "privacy-blacklist"; - // Runs a single process for each site (i.e., group of pages from the same // registered domain) the user visits. We default to using a renderer process // for each site instance (i.e., group of pages from the same registered diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index f646d67..2162976 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -77,6 +77,7 @@ extern const char kEnableLogging[]; extern const char kEnableMonitorProfile[]; extern const char kEnableNativeWebWorkers[]; extern const char kEnableNewAutoFill[]; +extern const char kEnablePrivacyBlacklists[]; extern const char kEnableRemoteFonts[]; extern const char kEnableRendererAccessibility[]; extern const char kEnableSeccompSandbox[]; @@ -129,7 +130,6 @@ extern const char kPluginPath[]; extern const char kPluginProcess[]; extern const char kPluginStartupDialog[]; extern const char kPrint[]; -extern const char kPrivacyBlacklist[]; extern const char kProcessPerSite[]; extern const char kProcessPerTab[]; extern const char kProfileImportProcess[]; diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index c162cfc..4ea338d 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -743,16 +743,19 @@ class NotificationType { // Privacy Blacklist ------------------------------------------------------- - // Sent when the blacklist manager successfully finishes reading - // a blacklist. The details are a Blacklist, and the source is a Profile. + // Sent on the UI thread when the blacklist manager successfully finishes + // reading a blacklist. There are no details, and the source is a Profile. + // The new blacklist is available on the IO thread. BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, - // Sent when the blacklist manager encounters an error. The details are - // a string16 (error message), and the source is a Profile. + // Sent on the UI thread when the blacklist manager encounters an error. + // The details are a string16 (error message), and the source is a Profile. BLACKLIST_MANAGER_ERROR, - // Sent by the resource dispatcher host when a resource is blocked. - BLACKLIST_BLOCKED_RESOURCE, + // Sent on the IO thread when a non-visual resource (like a cookie) + // is blocked by a privacy blacklist. The details are a const URLRequest, + // and the source is a const ChromeURLRequestContext. + BLACKLIST_NONVISUAL_RESOURCE_BLOCKED, // Debugging --------------------------------------------------------------- diff --git a/chrome/test/data/extensions/common/privacy_blacklist/privacy_blacklist.pbl b/chrome/test/data/extensions/common/privacy_blacklist/privacy_blacklist.pbl index b9dc8d2..df63d90 100644 --- a/chrome/test/data/extensions/common/privacy_blacklist/privacy_blacklist.pbl +++ b/chrome/test/data/extensions/common/privacy_blacklist/privacy_blacklist.pbl @@ -1,9 +1,9 @@ [Chromium::PrivacyBlacklist] |Name: AnnoyingAds -|URL: http://www.ads.tv +|URL: http://www.example.com # Block Ads by servers -annoying.ads.tv/@ => kBlockAll +example.com/@ => kBlockAll # Block Ads by name @/annoying/120x600.jpg => kBlockAll diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 37c35ea..b7f5ed8 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -145,7 +145,7 @@ class TestingProfile : public Profile { return NULL; } virtual net::SSLConfigService* GetSSLConfigService() { return NULL; } - virtual Blacklist* GetBlacklist() { return NULL; } + virtual BlacklistManager* GetBlacklistManager() { return NULL; } void set_session_service(SessionService* session_service) { session_service_ = session_service; } |