diff options
39 files changed, 64 insertions, 1438 deletions
diff --git a/chrome/browser/extensions/extension_file_util.cc b/chrome/browser/extensions/extension_file_util.cc index a9db4b3..346bfab 100644 --- a/chrome/browser/extensions/extension_file_util.cc +++ b/chrome/browser/extensions/extension_file_util.cc @@ -11,8 +11,6 @@ #include "base/string_util.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_prefs.h" -#include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_io.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_l10n_util.h" #include "chrome/common/extensions/extension_constants.h" @@ -227,27 +225,6 @@ bool ValidateExtension(Extension* extension, std::string* error) { } } - // Validate claimed privacy blacklists. - for (size_t i = 0; i < extension->privacy_blacklists().size(); ++i) { - const Extension::PrivacyBlacklistInfo& blacklist_info = - extension->privacy_blacklists()[i]; - std::string path_utf8(WideToUTF8(blacklist_info.path.ToWStringHack())); - if (!file_util::PathExists(blacklist_info.path)) { - *error = StringPrintf("Could not load '%s' for privacy blacklist: " - "file does not exist.", - path_utf8.c_str()); - return false; - } - Blacklist blacklist; - std::string parsing_error; - if (!BlacklistIO::ReadText(&blacklist, blacklist_info.path, - &parsing_error)) { - *error = StringPrintf("Could not load '%s' for privacy blacklist: %s", - path_utf8.c_str(), parsing_error.c_str()); - return false; - } - } - // Validate icon location for page actions. ExtensionAction* page_action = extension->page_action(); if (page_action) { diff --git a/chrome/browser/extensions/extension_file_util_unittest.cc b/chrome/browser/extensions/extension_file_util_unittest.cc index 6266c22..31ed023 100644 --- a/chrome/browser/extensions/extension_file_util_unittest.cc +++ b/chrome/browser/extensions/extension_file_util_unittest.cc @@ -220,40 +220,6 @@ TEST(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnBadManifest) { "Line: 2, column: 16, Syntax error.", error.c_str()); } -TEST(ExtensionFileUtil, MissingPrivacyBlacklist) { - FilePath install_dir; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); - install_dir = install_dir.AppendASCII("extensions") - .AppendASCII("privacy_blacklists") - .AppendASCII("missing_blacklist"); - - std::string error; - scoped_ptr<Extension> extension( - extension_file_util::LoadExtension(install_dir, false, &error)); - ASSERT_TRUE(extension == NULL); - ASSERT_FALSE(error.empty()); - EXPECT_TRUE(MatchPatternASCII(error, - "Could not load '*privacy_blacklist.pbl' for privacy blacklist: " - "file does not exist.")) << error; -} - -TEST(ExtensionFileUtil, InvalidPrivacyBlacklist) { - FilePath install_dir; - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); - install_dir = install_dir.AppendASCII("extensions") - .AppendASCII("privacy_blacklists") - .AppendASCII("invalid_blacklist"); - - std::string error; - scoped_ptr<Extension> extension( - extension_file_util::LoadExtension(install_dir, false, &error)); - ASSERT_TRUE(extension == NULL); - ASSERT_FALSE(error.empty()); - EXPECT_TRUE(MatchPatternASCII(error, - "Could not load '*privacy_blacklist.pbl' for privacy blacklist: " - "Incorrect header.")) << error; -} - #define URL_PREFIX "chrome-extension://extension-id/" TEST(ExtensionFileUtil, ExtensionURLToRelativeFilePath) { diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index dc0c0ae..a8eccf0 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -815,50 +815,6 @@ 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)); - - 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() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - 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; -} - void ExtensionsService::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 12bb85e..4b18c90 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -25,7 +25,6 @@ #include "chrome/browser/extensions/extensions_quota_service.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/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/extensions/extension.h" @@ -58,7 +57,6 @@ class ExtensionUpdateService { class ExtensionsService : public base::RefCountedThreadSafe<ExtensionsService, ChromeThread::DeleteOnUIThread>, - public BlacklistPathProvider, public ExtensionUpdateService, public NotificationObserver { public: @@ -241,11 +239,6 @@ class ExtensionsService NotificationType type, bool be_noisy); - // BlacklistPathProvider: - virtual bool AreBlacklistPathsReady() const; - virtual std::vector<FilePath> GetPersistentBlacklistPaths(); - virtual std::vector<FilePath> GetTransientBlacklistPaths(); - // NotificationObserver virtual void Observe(NotificationType type, const NotificationSource& source, diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index ea6b942..3e0bc31 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -12,7 +12,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/privacy_blacklist/blacklist.h" #include "chrome/browser/privacy_blacklist/blacklist_request_info.h" #include "chrome/browser/profile.h" #include "chrome/common/chrome_constants.h" @@ -684,12 +684,10 @@ bool ChromeURLRequestContext::InterceptCookie(const URLRequest* request, // blacklist request data. if (!request_info) return true; - const BlacklistManager* blacklist_manager = - request_info->GetBlacklistManager(); + const Blacklist* blacklist = request_info->GetBlacklist(); // TODO(phajdan.jr): remove the NULL check when blacklists are stable. - if (!blacklist_manager) - return NULL; - const Blacklist* blacklist = blacklist_manager->GetCompiledBlacklist(); + if (!blacklist) + return true; scoped_ptr<Blacklist::Match> match(blacklist->FindMatch(request->url())); if (!match.get()) return true; @@ -716,12 +714,10 @@ bool ChromeURLRequestContext::AllowSendingCookies(const URLRequest* request) // blacklist request data. if (!request_info) return true; - const BlacklistManager* blacklist_manager = - request_info->GetBlacklistManager(); + const Blacklist* blacklist = request_info->GetBlacklist(); // TODO(phajdan.jr): remove the NULL check when blacklists are stable. - if (!blacklist_manager) - return NULL; - const Blacklist* blacklist = blacklist_manager->GetCompiledBlacklist(); + if (!blacklist) + return true; scoped_ptr<Blacklist::Match> match(blacklist->FindMatch(request->url())); if (!match.get()) return true; @@ -736,8 +732,8 @@ bool ChromeURLRequestContext::AllowSendingCookies(const URLRequest* request) return true; } -BlacklistManager* ChromeURLRequestContext::GetBlacklistManager() const { - return blacklist_manager_.get(); +const Blacklist* ChromeURLRequestContext::GetPrivacyBlacklist() const { + return privacy_blacklist_; } void ChromeURLRequestContext::OnNewExtensions( @@ -784,14 +780,14 @@ ChromeURLRequestContext::ChromeURLRequestContext( user_script_dir_path_ = other->user_script_dir_path_; appcache_service_ = other->appcache_service_; host_zoom_map_ = other->host_zoom_map_; - blacklist_manager_ = other->blacklist_manager_; + privacy_blacklist_ = other->privacy_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::set_privacy_blacklist( + const Blacklist* privacy_blacklist) { + privacy_blacklist_ = privacy_blacklist; } void ChromeURLRequestContext::OnAcceptLanguageChange( @@ -862,7 +858,7 @@ ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile) host_zoom_map_ = profile->GetHostZoomMap(); - blacklist_manager_ = profile->GetBlacklistManager(); + privacy_blacklist_ = profile->GetPrivacyBlacklist(); // TODO(eroman): this doesn't look safe; sharing between IO and UI threads! transport_security_state_ = profile->GetTransportSecurityState(); @@ -904,7 +900,7 @@ void ChromeURLRequestContextFactory::ApplyProfileParametersToContext( context->set_extension_default_locales(extension_default_locales_); context->set_user_script_dir_path(user_script_dir_path_); context->set_host_zoom_map(host_zoom_map_); - context->set_blacklist_manager(blacklist_manager_.get()); + context->set_privacy_blacklist(privacy_blacklist_); context->set_transport_security_state( 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 b8ae704..a1bc78c 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -13,7 +13,7 @@ #include "chrome/common/pref_service.h" #include "net/url_request/url_request_context.h" -class BlacklistManager; +class Blacklist; class CommandLine; class Profile; @@ -191,8 +191,8 @@ class ChromeURLRequestContext : public URLRequestContext { const HostZoomMap* host_zoom_map() const { return host_zoom_map_; } - // Gets the Privacy Blacklist Manager, if any for this context. - BlacklistManager* GetBlacklistManager() const; + // Gets the Privacy Blacklist, if any for this context. + const Blacklist* GetPrivacyBlacklist() const; // Callback for when new extensions are loaded. void OnNewExtensions(const std::string& id, @@ -264,7 +264,7 @@ class ChromeURLRequestContext : public URLRequestContext { void set_host_zoom_map(HostZoomMap* host_zoom_map) { host_zoom_map_ = host_zoom_map; } - void set_blacklist_manager(BlacklistManager* blacklist_manager); + void set_privacy_blacklist(const Blacklist* privacy_blacklist); void set_appcache_service(ChromeAppCacheService* service) { appcache_service_ = service; } @@ -293,7 +293,8 @@ class ChromeURLRequestContext : public URLRequestContext { scoped_refptr<ChromeAppCacheService> appcache_service_; scoped_refptr<HostZoomMap> host_zoom_map_; - scoped_refptr<BlacklistManager> blacklist_manager_; + + const Blacklist* privacy_blacklist_; bool is_media_; bool is_off_the_record_; @@ -341,7 +342,7 @@ class ChromeURLRequestContextFactory { ChromeURLRequestContext::ExtensionDefaultLocales extension_default_locales_; FilePath user_script_dir_path_; scoped_refptr<HostZoomMap> host_zoom_map_; - scoped_refptr<BlacklistManager> blacklist_manager_; + const Blacklist* privacy_blacklist_; net::TransportSecurityState* transport_security_state_; scoped_refptr<net::SSLConfigService> ssl_config_service_; diff --git a/chrome/browser/privacy_blacklist/blacklist_interceptor.cc b/chrome/browser/privacy_blacklist/blacklist_interceptor.cc index 2a571e9..b187141 100644 --- a/chrome/browser/privacy_blacklist/blacklist_interceptor.cc +++ b/chrome/browser/privacy_blacklist/blacklist_interceptor.cc @@ -9,7 +9,6 @@ #include "base/string_util.h" #include "base/values.h" #include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" #include "chrome/browser/privacy_blacklist/blacklist_request_info.h" #include "chrome/common/jstemplate_builder.h" #include "net/url_request/url_request_simple_job.h" @@ -78,9 +77,7 @@ class URLRequestBlacklistJob : public URLRequestSimpleJob { const Blacklist::Provider* GetBestMatchingEntryProvider() const { // If kBlockAll is specified, assign blame to such an entry. // Otherwise pick the first one. - const BlacklistManager* blacklist_manager = - request_info_.GetBlacklistManager(); - const Blacklist* blacklist = blacklist_manager->GetCompiledBlacklist(); + const Blacklist* blacklist = request_info_.GetBlacklist(); scoped_ptr<Blacklist::Match> match(blacklist->FindMatch(request_->url())); const Blacklist::Entry* entry = NULL; if (match->attributes() & Blacklist::kBlockAll) { @@ -120,9 +117,7 @@ URLRequestJob* BlacklistInterceptor::MaybeIntercept(URLRequest* request) { return NULL; } - const BlacklistManager* blacklist_manager = - request_info->GetBlacklistManager(); - const Blacklist* blacklist = blacklist_manager->GetCompiledBlacklist(); + const Blacklist* blacklist = request_info->GetBlacklist(); scoped_ptr<Blacklist::Match> match(blacklist->FindMatch(request->url())); if (!match.get()) { diff --git a/chrome/browser/privacy_blacklist/blacklist_interceptor_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_interceptor_unittest.cc index f1cadcf..35ec289 100644 --- a/chrome/browser/privacy_blacklist/blacklist_interceptor_unittest.cc +++ b/chrome/browser/privacy_blacklist/blacklist_interceptor_unittest.cc @@ -4,13 +4,8 @@ #include "app/l10n_util.h" #include "base/message_loop.h" -#include "base/path_service.h" -#include "chrome/browser/chrome_thread.h" #include "chrome/browser/privacy_blacklist/blacklist_interceptor.h" -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" #include "chrome/browser/privacy_blacklist/blacklist_request_info.h" -#include "chrome/browser/privacy_blacklist/blacklist_test_util.h" -#include "chrome/common/chrome_paths.h" #include "grit/browser_resources.h" #include "grit/generated_resources.h" #include "net/base/io_buffer.h" @@ -26,16 +21,7 @@ const char kBlockedUrl[] = "http://example.com/annoying_ads/ad.jpg"; class BlacklistInterceptorTest : public testing::Test { public: - BlacklistInterceptorTest() - : loop_(MessageLoop::TYPE_IO), - ui_thread_(ChromeThread::UI, &loop_), - file_thread_(ChromeThread::FILE, &loop_), - io_thread_(ChromeThread::IO, &loop_) { - } - - virtual void SetUp() { - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); - test_data_dir_ = test_data_dir_.AppendASCII("blacklist_samples"); + BlacklistInterceptorTest() : loop_(MessageLoop::TYPE_IO) { } protected: @@ -55,18 +41,12 @@ class BlacklistInterceptorTest : public testing::Test { BlacklistInterceptor interceptor_; - FilePath test_data_dir_; - private: bool ContainsResourceString(const std::string& text, int string_id) { return text.find(l10n_util::GetStringUTF8(string_id)) != std::string::npos; } MessageLoop loop_; - - ChromeThread ui_thread_; - ChromeThread file_thread_; - ChromeThread io_thread_; }; TEST_F(BlacklistInterceptorTest, Basic) { @@ -74,20 +54,19 @@ TEST_F(BlacklistInterceptorTest, Basic) { } TEST_F(BlacklistInterceptorTest, Intercepted) { - BlacklistTestingProfile profile; - TestBlacklistPathProvider path_provider(&profile); - path_provider.AddTransientPath( - test_data_dir_.AppendASCII("annoying_ads.pbl")); - scoped_refptr<BlacklistManager> blacklist_manager( - new BlacklistManager(&profile, &path_provider)); - blacklist_manager->Initialize(); - MessageLoop::current()->RunAllPending(); - EXPECT_FALSE(InterceptedTestRequest(kDataUrl, NULL)); + Blacklist blacklist; + Blacklist::Provider* provider = new Blacklist::Provider(); + blacklist.AddProvider(provider); + Blacklist::Entry* entry = + new Blacklist::Entry("@/annoying_ads/@", provider, false); + entry->AddAttributes(Blacklist::kBlockAll); + blacklist.AddEntry(entry); + BlacklistRequestInfo* request_info = new BlacklistRequestInfo(GURL(kBlockedUrl), ResourceType::MAIN_FRAME, - blacklist_manager.get()); + &blacklist); EXPECT_TRUE(InterceptedTestRequest(kBlockedUrl, request_info)); } diff --git a/chrome/browser/privacy_blacklist/blacklist_listener.cc b/chrome/browser/privacy_blacklist/blacklist_listener.cc deleted file mode 100644 index 5e00236..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_listener.cc +++ /dev/null @@ -1,92 +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. - -#include "chrome/browser/privacy_blacklist/blacklist_listener.h" - -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" -#include "chrome/browser/privacy_blacklist/blacklist_request_info.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/renderer_host/global_request_id.h" -#include "chrome/common/notification_service.h" -#include "chrome/common/notification_type.h" -#include "net/url_request/url_request.h" - -BlacklistListener::BlacklistListener(ResourceQueue* resource_queue) - : resource_queue_(resource_queue) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - registrar_.Add(this, - NotificationType::BLACKLIST_MANAGER_ERROR, - NotificationService::AllSources()); - registrar_.Add(this, - NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, - NotificationService::AllSources()); -} - -BlacklistListener::~BlacklistListener() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); -} - -void BlacklistListener::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - switch (type.value) { - // TODO(phajdan.jr): Do not resume requests silently after an error. - case NotificationType::BLACKLIST_MANAGER_ERROR: - case NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED: - { - Profile* profile = Source<Profile>(source).ptr(); - ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, - NewRunnableMethod(this, &BlacklistListener::StartDelayedRequests, - profile->GetBlacklistManager())); - } - break; - default: - NOTREACHED(); - } -} - -bool BlacklistListener::ShouldDelayRequest( - URLRequest* request, - const ResourceDispatcherHostRequestInfo& request_info, - const GlobalRequestID& request_id) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - - BlacklistRequestInfo* blacklist_request_info = - BlacklistRequestInfo::FromURLRequest(request); - const BlacklistManager* blacklist_manager = - blacklist_request_info->GetBlacklistManager(); - - if (blacklist_manager->GetCompiledBlacklist()) { - // We have a blacklist ready. No need to delay the request. - return false; - } - - delayed_requests_[blacklist_manager].push_back(request_id); - return true; -} - -void BlacklistListener::WillShutdownResourceQueue() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - resource_queue_ = NULL; -} - -void BlacklistListener::StartDelayedRequests( - BlacklistManager* blacklist_manager) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - - if (resource_queue_) { - const RequestList& requests = delayed_requests_[blacklist_manager]; - for (RequestList::const_iterator i = requests.begin(); - i != requests.end(); ++i) { - resource_queue_->StartDelayedRequest(this, *i); - } - } - - delayed_requests_[blacklist_manager].clear(); -} diff --git a/chrome/browser/privacy_blacklist/blacklist_listener.h b/chrome/browser/privacy_blacklist/blacklist_listener.h deleted file mode 100644 index a74ed8e..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_listener.h +++ /dev/null @@ -1,68 +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_LISTENER_H_ -#define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_LISTENER_H_ - -#include <map> -#include <vector> - -#include "base/ref_counted.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/renderer_host/resource_queue.h" -#include "chrome/common/notification_observer.h" -#include "chrome/common/notification_registrar.h" - -class BlacklistManager; - -// Delays requests until privacy blacklists are ready. -class BlacklistListener - : public ResourceQueueDelegate, - public NotificationObserver, - public base::RefCountedThreadSafe<BlacklistListener, - ChromeThread::DeleteOnUIThread> { - public: - // UI THREAD ONLY ------------------------------------------------------------ - - explicit BlacklistListener(ResourceQueue* resource_queue); - virtual ~BlacklistListener(); - - // NotificationObserver: - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // IO THREAD ONLY ------------------------------------------------------------ - - // ResourceQueueDelegate: - virtual bool ShouldDelayRequest( - URLRequest* request, - const ResourceDispatcherHostRequestInfo& request_info, - const GlobalRequestID& request_id); - virtual void WillShutdownResourceQueue(); - - private: - friend class ChromeThread; - friend class DeleteTask<BlacklistListener>; - - // Tell our resource queue to start the requests we requested to be delayed. - void StartDelayedRequests(BlacklistManager* blacklist_manager); - - // Resource queue we're delegate of. - ResourceQueue* resource_queue_; - - typedef std::vector<GlobalRequestID> RequestList; - typedef std::map<const BlacklistManager*, RequestList> DelayedRequestMap; - - // Keep track of requests we have requested to delay so that we can resume - // them as the blacklists load (note that we have a request list per blacklist - // manager). - DelayedRequestMap delayed_requests_; - - NotificationRegistrar registrar_; - - DISALLOW_COPY_AND_ASSIGN(BlacklistListener); -}; - -#endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_LISTENER_H_ diff --git a/chrome/browser/privacy_blacklist/blacklist_listener_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_listener_unittest.cc deleted file mode 100644 index 0625009..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_listener_unittest.cc +++ /dev/null @@ -1,183 +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. - -#include "chrome/browser/privacy_blacklist/blacklist_listener.h" - -#include "base/message_loop.h" -#include "base/thread.h" -#include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_request_info.h" -#include "chrome/browser/privacy_blacklist/blacklist_test_util.h" -#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" -#include "chrome/browser/renderer_host/resource_handler.h" -#include "chrome/browser/renderer_host/resource_queue.h" -#include "chrome/common/notification_observer.h" -#include "chrome/common/notification_registrar.h" -#include "chrome/common/notification_source.h" -#include "chrome/common/notification_type.h" -#include "net/url_request/url_request_unittest.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -const char kTestUrl[] = "data:text/plain,Hello World!"; - -// Dummy ResourceHandler required for ResourceDispatcherHostRequestInfo. -class DummyResourceHandler : public ResourceHandler { - public: - DummyResourceHandler() { - } - - virtual bool OnRequestRedirected(int request_id, const GURL& url, - ResourceResponse* response, - bool* defer) { - NOTREACHED(); - return true; - } - - virtual bool OnResponseStarted(int request_id, - ResourceResponse* response) { - NOTREACHED(); - return true; - } - - virtual bool OnWillRead(int request_id, - net::IOBuffer** buf, - int* buf_size, - int min_size) { - NOTREACHED(); - return true; - } - - virtual bool OnReadCompleted(int request_id, int* bytes_read) { - NOTREACHED(); - return true; - } - - virtual bool OnResponseCompleted(int request_id, - const URLRequestStatus& status, - const std::string& security_info) { - NOTREACHED(); - return true; - } - - private: - DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler); -}; - -ResourceDispatcherHostRequestInfo* GetRequestInfo(int request_id) { - return new ResourceDispatcherHostRequestInfo( - new DummyResourceHandler(), ChildProcessInfo::RENDER_PROCESS, 0, 0, - request_id, "null", "null", ResourceType::MAIN_FRAME, - 0, false, false, -1, -1); -} - -class BlacklistListenerTest - : public testing::Test, - public NotificationObserver { - public: - BlacklistListenerTest() - : path_provider_(&profile_), - loop_(MessageLoop::TYPE_IO), - mock_ui_thread_(ChromeThread::UI, MessageLoop::current()), - mock_file_thread_(ChromeThread::FILE, MessageLoop::current()), - mock_io_thread_(ChromeThread::IO, MessageLoop::current()) { - } - - virtual void SetUp() { - blacklist_manager_ = new BlacklistManager(&profile_, &path_provider_); - blacklist_listener_ = new BlacklistListener(&resource_queue_); - - profile_.set_blacklist_manager(blacklist_manager_.get()); - - ResourceQueue::DelegateSet delegates; - delegates.insert(blacklist_listener_.get()); - resource_queue_.Initialize(delegates); - } - - virtual void TearDown() { - resource_queue_.Shutdown(); - blacklist_listener_ = NULL; - blacklist_manager_ = NULL; - loop_.RunAllPending(); - } - - // NotificationObserver - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - MessageLoop::current()->Quit(); - } - - protected: - void WaitForBlacklistUpdate() { - NotificationRegistrar registrar; - registrar.Add(this, - NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, - Source<Profile>(&profile_)); - MessageLoop::current()->Run(); - } - - TestURLRequest* StartTestRequest(URLRequest::Delegate* delegate) { - TestURLRequest* request = new TestURLRequest(GURL(kTestUrl), delegate); - BlacklistRequestInfo* request_info = - new BlacklistRequestInfo(request->url(), ResourceType::MAIN_FRAME, - blacklist_manager_.get()); - request->SetUserData(&BlacklistRequestInfo::kURLRequestDataKey, - request_info); - scoped_ptr<ResourceDispatcherHostRequestInfo> rdh_info(GetRequestInfo(0)); - resource_queue_.AddRequest(request, *rdh_info.get()); - return request; - } - - BlacklistTestingProfile profile_; - - TestBlacklistPathProvider path_provider_; - - scoped_refptr<BlacklistManager> blacklist_manager_; - - scoped_refptr<BlacklistListener> blacklist_listener_; - - private: - MessageLoop loop_; - - ChromeThread mock_ui_thread_; - ChromeThread mock_file_thread_; - ChromeThread mock_io_thread_; - - ResourceQueue resource_queue_; -}; - -TEST_F(BlacklistListenerTest, Delay) { - blacklist_manager_->Initialize(); - - TestDelegate delegate; - scoped_ptr<TestURLRequest> request(StartTestRequest(&delegate)); - - // The request should get delayed, because the BlacklistManager is not yet - // ready. When we run pending tasks, it should initialize itself, notify - // the BlacklistListener, and start the request. - ASSERT_FALSE(request->is_pending()); - - MessageLoop::current()->RunAllPending(); - EXPECT_EQ("Hello World!", delegate.data_received()); -} - -TEST_F(BlacklistListenerTest, NoDelay) { - blacklist_manager_->Initialize(); - - // Make sure that the BlacklistManager is ready before we start the request. - WaitForBlacklistUpdate(); - - TestDelegate delegate; - scoped_ptr<TestURLRequest> request(StartTestRequest(&delegate)); - - // The request should be started immediately. - ASSERT_TRUE(request->is_pending()); - - MessageLoop::current()->RunAllPending(); - EXPECT_EQ("Hello World!", delegate.data_received()); -} - -} // namespace diff --git a/chrome/browser/privacy_blacklist/blacklist_manager.cc b/chrome/browser/privacy_blacklist/blacklist_manager.cc deleted file mode 100644 index c2253ef..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_manager.cc +++ /dev/null @@ -1,234 +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. - -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" - -#include "base/message_loop.h" -#include "base/string_util.h" -#include "base/task.h" -#include "base/thread.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/privacy_blacklist/blacklist.h" -#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" - -BlacklistPathProvider::~BlacklistPathProvider() { -} - -BlacklistManager::BlacklistManager(Profile* profile, - BlacklistPathProvider* path_provider) - : first_read_finished_(false), - profile_(profile), - compiled_blacklist_path_( - profile->GetPath().Append(chrome::kPrivacyBlacklistFileName)), - path_provider_(path_provider) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - 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)); -} - -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, - const NotificationSource& source, - const NotificationDetails& details) { - 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: - NOTREACHED(); - break; - } -} - -BlacklistManager::~BlacklistManager() { -} - -void BlacklistManager::CompileBlacklist() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - DCHECK(path_provider_->AreBlacklistPathsReady()); - - // The compiled blacklist is going to change. Make sure our clients don't use - // the old one and wait for the update instead by indicating that the compiled - // blacklist is not ready. - ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, - NewRunnableMethod(this, - &BlacklistManager::ResetPublishedCompiledBlacklist)); - - // Schedule actual compilation on the background thread. - ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, - NewRunnableMethod(this, &BlacklistManager::DoCompileBlacklist, - path_provider_->GetPersistentBlacklistPaths())); -} - -void BlacklistManager::DoCompileBlacklist( - const std::vector<FilePath>& source_blacklists) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); - - Blacklist blacklist; - std::string error_string; - std::vector<string16> errors; - for (std::vector<FilePath>::const_iterator i = source_blacklists.begin(); - i != source_blacklists.end(); ++i) { - std::string error_string; - if (!BlacklistIO::ReadText(&blacklist, *i, &error_string)) { - string16 path = WideToUTF16(i->ToWStringHack()); - errors.push_back(path + ASCIIToUTF16(": " + error_string)); - } - } - - if (!errors.empty()) { - ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, - NewRunnableMethod(this, - &BlacklistManager::OnBlacklistCompilationReadErrors, - errors)); - } - - // Write the new compiled blacklist based on the data we could read - // successfully. - bool success = BlacklistIO::WriteBinary(&blacklist, compiled_blacklist_path_); - ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, - NewRunnableMethod(this, &BlacklistManager::OnBlacklistCompilationFinished, - success)); -} - -void BlacklistManager::OnBlacklistCompilationFinished(bool success) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - if (success) { - ReadBlacklist(); - } else { - string16 error_message(ASCIIToUTF16("Blacklist compilation failed.")); - NotificationService::current()->Notify( - NotificationType::BLACKLIST_MANAGER_ERROR, - Source<Profile>(profile_), - Details<string16>(&error_message)); - } -} - -void BlacklistManager::OnBlacklistCompilationReadErrors( - const std::vector<string16>& errors) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - string16 error_message(ASCIIToUTF16("Blacklist compilation failed.\n")); - for (std::vector<string16>::const_iterator i = errors.begin(); - i != errors.end(); ++i) { - error_message += *i + ASCIIToUTF16("\n"); - } - NotificationService::current()->Notify( - NotificationType::BLACKLIST_MANAGER_ERROR, - Source<Profile>(profile_), - Details<string16>(&error_message)); -} - -void BlacklistManager::ReadBlacklist() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - DCHECK(path_provider_->AreBlacklistPathsReady()); - - ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, - NewRunnableMethod(this, &BlacklistManager::DoReadBlacklist, - path_provider_->GetTransientBlacklistPaths())); -} - -void BlacklistManager::DoReadBlacklist( - const std::vector<FilePath>& transient_blacklists) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); - - scoped_ptr<Blacklist> blacklist(new Blacklist); - 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(); - } - ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, - NewRunnableMethod(this, - &BlacklistManager::UpdatePublishedCompiledBlacklist, - blacklist.release())); -} - -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 != NULL)); -} - -void BlacklistManager::OnBlacklistReadFinished(bool success) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - 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. - CompileBlacklist(); - } - } - first_read_finished_ = true; -} - -void BlacklistManager::ResetPublishedCompiledBlacklist() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - compiled_blacklist_.reset(); -} diff --git a/chrome/browser/privacy_blacklist/blacklist_manager.h b/chrome/browser/privacy_blacklist/blacklist_manager.h deleted file mode 100644 index 1ababd6..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_manager.h +++ /dev/null @@ -1,107 +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_MANAGER_H_ -#define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "base/file_path.h" -#include "base/ref_counted.h" -#include "base/scoped_ptr.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/common/notification_registrar.h" - -class Blacklist; -class Profile; - -class BlacklistPathProvider { - public: - // 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; - - // 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 -// blacklists. -class BlacklistManager - : public NotificationObserver, - public base::RefCountedThreadSafe<BlacklistManager, - ChromeThread::DeleteOnUIThread> { - public: - // Create BlacklistManager (must be done on UI thread). - BlacklistManager(Profile* profile, BlacklistPathProvider* path_provider); - - // Initialize the BlacklistManager (on UI thread). - void Initialize(); - - // 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, - const NotificationSource& source, - const NotificationDetails& details); - -#ifdef UNIT_TEST - const FilePath& compiled_blacklist_path() { return compiled_blacklist_path_; } -#endif // UNIT_TEST - - private: - friend class ChromeThread; - friend class DeleteTask<BlacklistManager>; - - virtual ~BlacklistManager(); - - // Compile all persistent blacklists to one binary blacklist stored on disk. - void CompileBlacklist(); - void DoCompileBlacklist(const std::vector<FilePath>& source_blacklists); - void OnBlacklistCompilationReadErrors(const std::vector<string16>& errors); - void OnBlacklistCompilationFinished(bool success); - - // Read all blacklists from disk (the compiled one and also the transient - // 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 UpdatePublishedCompiledBlacklist(Blacklist* blacklist); - void OnBlacklistReadFinished(bool success); - - // Sets the |compiled_blacklist_| to NULL to indicate that the blacklist is - // not ready. - void ResetPublishedCompiledBlacklist(); - - // True after the first blacklist read has finished (regardless of success). - // Used to avoid an infinite loop. - bool first_read_finished_; - - Profile* profile_; - - // Path where we store the compiled blacklist. - FilePath compiled_blacklist_path_; - - // Keep the compiled blacklist object in memory. - scoped_ptr<Blacklist> compiled_blacklist_; - - BlacklistPathProvider* path_provider_; - - NotificationRegistrar registrar_; - - DISALLOW_COPY_AND_ASSIGN(BlacklistManager); -}; - -#endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ diff --git a/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc b/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc deleted file mode 100644 index d6e6992..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_manager_browsertest.cc +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2010 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. - -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" - -#include "app/l10n_util.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/extensions/extensions_service.h" -#include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" -#include "chrome/browser/profile.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/test/in_process_browser_test.h" -#include "chrome/test/ui_test_utils.h" -#include "grit/browser_resources.h" -#include "grit/generated_resources.h" -#include "net/base/mock_host_resolver.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -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: - virtual void SetUp() { - CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kEnablePrivacyBlacklists); - ExtensionBrowserTest::SetUp(); - } - - virtual void SetUpInProcessBrowserTestFixture() { - ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); - - host_resolver()->AddSimulatedFailure("www.example.com"); - } - - protected: - BlacklistManager* GetBlacklistManager() { - return browser()->profile()->GetBlacklistManager(); - } - - 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; - } -}; - -IN_PROC_BROWSER_TEST_F(BlacklistManagerBrowserTest, Basic) { - static const char kTestUrl[] = "http://www.example.com/annoying_ads/ad.jpg"; - - // Test loading an extension with blacklist. - ASSERT_TRUE(LoadExtension( - test_data_dir_.AppendASCII("common").AppendASCII("privacy_blacklist"))); - - // Navigate to a blacklisted URL. The request should be blocked. - ui_test_utils::NavigateToURL(browser(), GURL(kTestUrl)); - string16 expected_title(l10n_util::GetStringUTF16(IDS_BLACKLIST_TITLE)); - string16 tab_title; - ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &tab_title)); - EXPECT_EQ(expected_title, tab_title); - EXPECT_TRUE(BlacklistHasMatch(kTestUrl)); -} diff --git a/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc deleted file mode 100644 index 55089a4..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_manager_unittest.cc +++ /dev/null @@ -1,199 +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. - -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" - -#include "base/message_loop.h" -#include "base/path_service.h" -#include "base/thread.h" -#include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_test_util.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/notification_observer.h" -#include "chrome/common/notification_registrar.h" -#include "chrome/common/notification_source.h" -#include "chrome/common/notification_type.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class BlacklistManagerTest : public testing::Test, public NotificationObserver { - public: - BlacklistManagerTest() - : path_provider_(&profile_), - mock_ui_thread_(ChromeThread::UI, MessageLoop::current()), - mock_file_thread_(ChromeThread::FILE), - mock_io_thread_(ChromeThread::IO, MessageLoop::current()) { - } - - virtual void SetUp() { - ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); - test_data_dir_ = test_data_dir_.AppendASCII("blacklist_samples"); - ASSERT_TRUE(mock_file_thread_.Start()); - } - - virtual void TearDown() { - mock_file_thread_.Stop(); - loop_.RunAllPending(); - } - - // NotificationObserver - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - MessageLoop::current()->Quit(); - } - - protected: - void WaitForBlacklistError() { - NotificationRegistrar registrar; - registrar.Add(this, - NotificationType::BLACKLIST_MANAGER_ERROR, - Source<Profile>(&profile_)); - MessageLoop::current()->Run(); - } - - void WaitForBlacklistUpdate() { - NotificationRegistrar registrar; - registrar.Add(this, - NotificationType::BLACKLIST_MANAGER_BLACKLIST_READ_FINISHED, - Source<Profile>(&profile_)); - MessageLoop::current()->Run(); - } - - FilePath test_data_dir_; - - BlacklistTestingProfile profile_; - - TestBlacklistPathProvider path_provider_; - - private: - MessageLoop loop_; - - ChromeThread mock_ui_thread_; - ChromeThread mock_file_thread_; - ChromeThread mock_io_thread_; -}; - -// 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; -} - -TEST_F(BlacklistManagerTest, Basic) { - scoped_refptr<BlacklistManager> manager( - new BlacklistManager(&profile_, &path_provider_)); - manager->Initialize(); - WaitForBlacklistUpdate(); - - const Blacklist* blacklist = manager->GetCompiledBlacklist(); - EXPECT_TRUE(blacklist); - - // Repeated invocations of GetCompiledBlacklist should return the same object. - EXPECT_EQ(blacklist, manager->GetCompiledBlacklist()); -} - -TEST_F(BlacklistManagerTest, BlacklistPathProvider) { - scoped_refptr<BlacklistManager> manager( - new BlacklistManager(&profile_, &path_provider_)); - manager->Initialize(); - WaitForBlacklistUpdate(); - - const Blacklist* blacklist1 = manager->GetCompiledBlacklist(); - EXPECT_FALSE(BlacklistHasMatch(blacklist1, - "http://host/annoying_ads/ad.jpg")); - - path_provider_.AddPersistentPath( - test_data_dir_.AppendASCII("annoying_ads.pbl")); - WaitForBlacklistUpdate(); - - const Blacklist* blacklist2 = manager->GetCompiledBlacklist(); - - // Added a real blacklist, the manager should recompile. - EXPECT_TRUE(BlacklistHasMatch(blacklist2, "http://host/annoying_ads/ad.jpg")); - EXPECT_FALSE(BlacklistHasMatch(blacklist2, "http://host/other_ads/ad.jpg")); - - path_provider_.AddTransientPath(test_data_dir_.AppendASCII("other_ads.pbl")); - WaitForBlacklistUpdate(); - - const Blacklist* blacklist3 = manager->GetCompiledBlacklist(); - - // In theory blacklist2 and blacklist3 could be the same object, so we're - // not checking for inequality. - EXPECT_TRUE(BlacklistHasMatch(blacklist3, "http://host/annoying_ads/ad.jpg")); - EXPECT_TRUE(BlacklistHasMatch(blacklist3, "http://host/other_ads/ad.jpg")); - - // Now make sure that transient blacklists don't survive after re-creating - // the BlacklistManager. - manager = NULL; - path_provider_.clear(); - path_provider_.AddPersistentPath( - test_data_dir_.AppendASCII("annoying_ads.pbl")); - manager = new BlacklistManager(&profile_, &path_provider_); - manager->Initialize(); - WaitForBlacklistUpdate(); - - const Blacklist* blacklist4 = manager->GetCompiledBlacklist(); - - EXPECT_TRUE(BlacklistHasMatch(blacklist4, "http://host/annoying_ads/ad.jpg")); - EXPECT_FALSE(BlacklistHasMatch(blacklist4, "http://host/other_ads/ad.jpg")); -} - -TEST_F(BlacklistManagerTest, BlacklistPathReadError) { - scoped_refptr<BlacklistManager> manager( - new BlacklistManager(&profile_, &path_provider_)); - manager->Initialize(); - WaitForBlacklistUpdate(); - - FilePath bogus_path(test_data_dir_.AppendASCII("does_not_exist_randomness")); - ASSERT_FALSE(file_util::PathExists(bogus_path)); - path_provider_.AddPersistentPath(bogus_path); - WaitForBlacklistUpdate(); - - const Blacklist* blacklist = manager->GetCompiledBlacklist(); - EXPECT_TRUE(blacklist); -} - -TEST_F(BlacklistManagerTest, CompiledBlacklistReadError) { - FilePath compiled_blacklist_path; - - { - scoped_refptr<BlacklistManager> manager( - new BlacklistManager(&profile_, &path_provider_)); - manager->Initialize(); - WaitForBlacklistUpdate(); - - path_provider_.AddPersistentPath( - test_data_dir_.AppendASCII("annoying_ads.pbl")); - WaitForBlacklistUpdate(); - const Blacklist* blacklist = manager->GetCompiledBlacklist(); - EXPECT_TRUE(BlacklistHasMatch(blacklist, - "http://host/annoying_ads/ad.jpg")); - - compiled_blacklist_path = manager->compiled_blacklist_path(); - } - - ASSERT_TRUE(file_util::PathExists(compiled_blacklist_path)); - ASSERT_TRUE(file_util::Delete(compiled_blacklist_path, false)); - - { - scoped_refptr<BlacklistManager> manager( - new BlacklistManager(&profile_, &path_provider_)); - manager->Initialize(); - WaitForBlacklistUpdate(); - - // The manager should recompile the blacklist. - const Blacklist* blacklist = manager->GetCompiledBlacklist(); - EXPECT_TRUE(BlacklistHasMatch(blacklist, - "http://host/annoying_ads/ad.jpg")); - } -} - -} // namespace diff --git a/chrome/browser/privacy_blacklist/blacklist_request_info.cc b/chrome/browser/privacy_blacklist/blacklist_request_info.cc index b5ecfb5..ff60513 100644 --- a/chrome/browser/privacy_blacklist/blacklist_request_info.cc +++ b/chrome/browser/privacy_blacklist/blacklist_request_info.cc @@ -4,17 +4,15 @@ #include "chrome/browser/privacy_blacklist/blacklist_request_info.h" -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" - // static const void* const BlacklistRequestInfo::kURLRequestDataKey = 0; BlacklistRequestInfo::BlacklistRequestInfo(const GURL& url, ResourceType::Type resource_type, - BlacklistManager* blacklist_manager) + const Blacklist* blacklist) : url_(url), resource_type_(resource_type), - blacklist_manager_(blacklist_manager) { + blacklist_(blacklist) { } BlacklistRequestInfo::~BlacklistRequestInfo() { diff --git a/chrome/browser/privacy_blacklist/blacklist_request_info.h b/chrome/browser/privacy_blacklist/blacklist_request_info.h index 84a74d1..f662d41 100644 --- a/chrome/browser/privacy_blacklist/blacklist_request_info.h +++ b/chrome/browser/privacy_blacklist/blacklist_request_info.h @@ -19,12 +19,12 @@ class BlacklistRequestInfo : public URLRequest::UserData { static const void* const kURLRequestDataKey; BlacklistRequestInfo(const GURL& url, ResourceType::Type resource_type, - BlacklistManager* blacklist_manager); + const Blacklist* blacklist); ~BlacklistRequestInfo(); ResourceType::Type resource_type() const { return resource_type_; } - const BlacklistManager* GetBlacklistManager() const { - return blacklist_manager_.get(); + const Blacklist* GetBlacklist() const { + return blacklist_; } // Get the blacklist request info stored in |request|, or NULL if there is no @@ -38,8 +38,8 @@ class BlacklistRequestInfo : public URLRequest::UserData { // Type of the requested resource (main frame, image, etc). const ResourceType::Type resource_type_; - // BlacklistManager used for the request. - scoped_refptr<BlacklistManager> blacklist_manager_; + // Blacklist used for the request. + const Blacklist* blacklist_; DISALLOW_COPY_AND_ASSIGN(BlacklistRequestInfo); }; diff --git a/chrome/browser/privacy_blacklist/blacklist_test_util.cc b/chrome/browser/privacy_blacklist/blacklist_test_util.cc deleted file mode 100644 index da4fdc9..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_test_util.cc +++ /dev/null @@ -1,76 +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. - -#include "chrome/browser/privacy_blacklist/blacklist_test_util.h" - -#include "base/file_path.h" -#include "base/values.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_constants.h" -#include "chrome/common/notification_service.h" -#include "testing/gtest/include/gtest/gtest.h" - -BlacklistTestingProfile::BlacklistTestingProfile() { - EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); - path_ = temp_dir_.path(); -} - -TestBlacklistPathProvider::TestBlacklistPathProvider(Profile* profile) - : profile_(profile) { -} - -bool TestBlacklistPathProvider::AreBlacklistPathsReady() const { - return true; -} - -std::vector<FilePath> TestBlacklistPathProvider::GetPersistentBlacklistPaths() { - return persistent_paths_; -} - -std::vector<FilePath> TestBlacklistPathProvider::GetTransientBlacklistPaths() { - return transient_paths_; -} - -void TestBlacklistPathProvider::AddPersistentPath(const FilePath& path) { - persistent_paths_.push_back(path); - SendUpdateNotification(); -} - -void TestBlacklistPathProvider::AddTransientPath(const FilePath& path) { - transient_paths_.push_back(path); - SendUpdateNotification(); -} - -void TestBlacklistPathProvider::clear() { - persistent_paths_.clear(); - transient_paths_.clear(); - SendUpdateNotification(); -} - -void TestBlacklistPathProvider::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); - - // Create an extension with dummy path. -#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_), - Details<Extension>(&extension)); -} diff --git a/chrome/browser/privacy_blacklist/blacklist_test_util.h b/chrome/browser/privacy_blacklist/blacklist_test_util.h deleted file mode 100644 index 1b79c3d..0000000 --- a/chrome/browser/privacy_blacklist/blacklist_test_util.h +++ /dev/null @@ -1,64 +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_TEST_UTIL_H_ -#define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_TEST_UTIL_H_ - -#include <vector> - -#include "base/scoped_temp_dir.h" -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" -#include "chrome/test/testing_profile.h" - -class FilePath; - -// Testing profile which uses a temporary directory. -class BlacklistTestingProfile : public TestingProfile { - public: - BlacklistTestingProfile(); - - BlacklistManager* GetBlacklistManager() { return blacklist_manager_; } - void set_blacklist_manager(BlacklistManager* manager) { - blacklist_manager_ = manager; - } - - private: - ScopedTempDir temp_dir_; - - BlacklistManager* blacklist_manager_; - - DISALLOW_COPY_AND_ASSIGN(BlacklistTestingProfile); -}; - -// Path provider which allows easy updates from the outside and sends -// notifications for each change. -class TestBlacklistPathProvider : public BlacklistPathProvider { - public: - explicit TestBlacklistPathProvider(Profile* profile); - - // BlacklistPathProvider: - virtual bool AreBlacklistPathsReady() const; - virtual std::vector<FilePath> GetPersistentBlacklistPaths(); - virtual std::vector<FilePath> GetTransientBlacklistPaths(); - - // Adds a path to the provder and sends an update notification. - void AddPersistentPath(const FilePath& path); - void AddTransientPath(const FilePath& path); - - // Removes all paths from the provider and send an update notification. - void clear(); - - private: - void SendUpdateNotification(); - - Profile* profile_; - - // Keep track of added paths. - std::vector<FilePath> persistent_paths_; - std::vector<FilePath> transient_paths_; - - DISALLOW_COPY_AND_ASSIGN(TestBlacklistPathProvider); -}; - -#endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_TEST_UTIL_H_ diff --git a/chrome/browser/privacy_blacklist/blacklist_ui.cc b/chrome/browser/privacy_blacklist/blacklist_ui.cc index 9425176..354e2d4 100644 --- a/chrome/browser/privacy_blacklist/blacklist_ui.cc +++ b/chrome/browser/privacy_blacklist/blacklist_ui.cc @@ -10,7 +10,6 @@ #include "chrome/browser/blocked_popup_container.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" #include "chrome/browser/privacy_blacklist/blacklist_request_info.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" @@ -69,9 +68,7 @@ void BlacklistUI::OnNonvisualContentBlocked(const URLRequest* request) { BlacklistRequestInfo* request_info = BlacklistRequestInfo::FromURLRequest(request); - const BlacklistManager* blacklist_manager = - request_info->GetBlacklistManager(); - const Blacklist* blacklist = blacklist_manager->GetCompiledBlacklist(); + const Blacklist* blacklist = request_info->GetBlacklist(); scoped_ptr<Blacklist::Match> match(blacklist->FindMatch(request->url())); const ResourceDispatcherHostRequestInfo* info = ResourceDispatcherHost::InfoForRequest(request); diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 3231ede2..7aaeea8 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -35,7 +35,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_manager.h" +#include "chrome/browser/privacy_blacklist/blacklist.h" #include "chrome/browser/profile_manager.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/search_versus_navigate_classifier.h" @@ -413,8 +413,8 @@ class OffTheRecordProfileImpl : public Profile, return host_zoom_map_.get(); } - virtual BlacklistManager* GetBlacklistManager() { - return GetOriginalProfile()->GetBlacklistManager(); + virtual Blacklist* GetPrivacyBlacklist() { + return GetOriginalProfile()->GetPrivacyBlacklist(); } virtual SessionService* GetSessionService() { @@ -573,8 +573,8 @@ ProfileImpl::ProfileImpl(const FilePath& path) media_request_context_(NULL), extensions_request_context_(NULL), host_zoom_map_(NULL), - blacklist_manager_(NULL), - blacklist_manager_created_(false), + privacy_blacklist_(NULL), + privacy_blacklist_created_(false), history_service_created_(false), favicon_service_created_(false), created_web_data_service_(false), @@ -969,17 +969,16 @@ HostZoomMap* ProfileImpl::GetHostZoomMap() { return host_zoom_map_.get(); } -BlacklistManager* ProfileImpl::GetBlacklistManager() { +Blacklist* ProfileImpl::GetPrivacyBlacklist() { 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(); + if (!privacy_blacklist_created_) { + privacy_blacklist_created_ = true; + privacy_blacklist_.reset(new Blacklist()); } - return blacklist_manager_.get(); + return privacy_blacklist_.get(); } HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 1d15753..737d2e0 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -30,7 +30,7 @@ namespace webkit_database { class DatabaseTracker; } -class BlacklistManager; +class Blacklist; class BookmarkModel; class BrowserThemeProvider; class ChromeURLRequestContextGetter; @@ -291,8 +291,8 @@ class Profile { // Returns the Hostname <-> Zoom Level map for this profile. virtual HostZoomMap* GetHostZoomMap() = 0; - // Returns the Privacy Blacklist Manager for this profile. - virtual BlacklistManager* GetBlacklistManager() = 0; + // Returns the Privacy Blacklist for this profile. + virtual Blacklist* GetPrivacyBlacklist() = 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* GetRequestContextForExtensions(); virtual net::SSLConfigService* GetSSLConfigService(); virtual HostZoomMap* GetHostZoomMap(); - virtual BlacklistManager* GetBlacklistManager(); + virtual Blacklist* GetPrivacyBlacklist(); virtual SessionService* GetSessionService(); virtual void ShutdownSessionService(); virtual bool HasSessionService() const; @@ -522,7 +522,7 @@ class ProfileImpl : public Profile, scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_; scoped_refptr<HostZoomMap> host_zoom_map_; - scoped_refptr<BlacklistManager> blacklist_manager_; + scoped_ptr<Blacklist> privacy_blacklist_; scoped_refptr<DownloadManager> download_manager_; scoped_refptr<HistoryService> history_service_; scoped_refptr<FaviconService> favicon_service_; @@ -534,7 +534,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 privacy_blacklist_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 19096a4..f70089b 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -29,8 +29,6 @@ #include "chrome/browser/net/url_request_tracking.h" #include "chrome/browser/plugin_service.h" #include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_listener.h" -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" #include "chrome/browser/privacy_blacklist/blacklist_request_info.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/async_resource_handler.h" @@ -265,11 +263,6 @@ ResourceDispatcherHost::ResourceDispatcherHost() kMaxOutstandingRequestsCostPerProcess), receiver_(NULL) { ResourceQueue::DelegateSet resource_queue_delegates; - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnablePrivacyBlacklists)) { - blacklist_listener_ = new BlacklistListener(&resource_queue_); - resource_queue_delegates.insert(blacklist_listener_.get()); - } resource_queue_delegates.insert(user_script_listener_.get()); resource_queue_.Initialize(resource_queue_delegates); } @@ -563,7 +556,7 @@ void ResourceDispatcherHost::BeginRequest( switches::kEnablePrivacyBlacklists)) { request->SetUserData(&BlacklistRequestInfo::kURLRequestDataKey, new BlacklistRequestInfo(request_data.url, request_data.resource_type, - context ? context->GetBlacklistManager() : NULL)); + context ? context->GetPrivacyBlacklist() : NULL)); } BeginRequestInternal(request); @@ -1100,9 +1093,7 @@ bool ResourceDispatcherHost::CompleteResponseStarted(URLRequest* request) { BlacklistRequestInfo* request_info = BlacklistRequestInfo::FromURLRequest(request); if (request_info) { - const BlacklistManager* blacklist_manager = - request_info->GetBlacklistManager(); - const Blacklist* blacklist = blacklist_manager->GetCompiledBlacklist(); + const Blacklist* blacklist = request_info->GetBlacklist(); scoped_ptr<Blacklist::Match> match(blacklist->FindMatch(request->url())); if (match.get() && match->attributes() & Blacklist::kBlockByType) { if (match->MatchType(response->response_head.mime_type)) diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h index 3f2816d..eff192d 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host.h @@ -28,7 +28,6 @@ #include "net/url_request/url_request.h" #include "webkit/glue/resource_type.h" -class BlacklistListener; class CrossSiteResourceHandler; class DownloadFileManager; class DownloadRequestManager; @@ -414,10 +413,6 @@ class ResourceDispatcherHost : public URLRequest::Delegate { // Handles requests blocked by privacy blacklists. BlacklistInterceptor blacklist_interceptor_; - // Makes sure that each request is reliably checked against the privacy - // blacklist. - scoped_refptr<BlacklistListener> blacklist_listener_; - scoped_refptr<UserScriptListener> user_script_listener_; scoped_refptr<SafeBrowsingService> safe_browsing_; diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index b6ece5c..b977944 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -26,7 +26,6 @@ #include "chrome/browser/notifications/notifications_prefs_cache.h" #include "chrome/browser/plugin_service.h" #include "chrome/browser/privacy_blacklist/blacklist.h" -#include "chrome/browser/privacy_blacklist/blacklist_manager.h" #include "chrome/browser/privacy_blacklist/blacklist_ui.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/audio_renderer_host.h" @@ -145,11 +144,10 @@ void RenderParamsFromPrintSettings(const printing::PrintSettings& settings, Blacklist::Match* GetPrivacyBlacklistMatchForURL( const GURL& url, ChromeURLRequestContext* context) { - BlacklistManager* blacklist_manager = context->GetBlacklistManager(); + const Blacklist* blacklist = context->GetPrivacyBlacklist(); // TODO(phajdan.jr): DCHECK(blacklist_manager) when blacklists are stable. - if (!blacklist_manager) + if (!blacklist) return NULL; - const Blacklist* blacklist = blacklist_manager->GetCompiledBlacklist(); return blacklist->FindMatch(url); } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 69680d1..551b232 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -267,7 +267,7 @@ 'browser/chromeos/external_protocol_dialog.h', 'browser/chromeos/gview_request_interceptor.cc', 'browser/chromeos/gview_request_interceptor.h', - 'browser/chromeos/ipc_message.h', + 'browser/chromeos/ipc_message.h', 'browser/chromeos/language_library.cc', 'browser/chromeos/language_library.h', 'browser/chromeos/language_menu_button.cc', @@ -1325,10 +1325,6 @@ 'browser/privacy_blacklist/blacklist_interceptor.cc', 'browser/privacy_blacklist/blacklist_io.h', 'browser/privacy_blacklist/blacklist_io.cc', - 'browser/privacy_blacklist/blacklist_listener.h', - 'browser/privacy_blacklist/blacklist_listener.cc', - 'browser/privacy_blacklist/blacklist_manager.h', - 'browser/privacy_blacklist/blacklist_manager.cc', 'browser/privacy_blacklist/blacklist_request_info.h', 'browser/privacy_blacklist/blacklist_request_info.cc', 'browser/privacy_blacklist/blacklist_store.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 5b70806..2d68d00 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -752,10 +752,6 @@ 'browser/printing/print_job_unittest.cc', 'browser/privacy_blacklist/blacklist_interceptor_unittest.cc', 'browser/privacy_blacklist/blacklist_io_unittest.cc', - 'browser/privacy_blacklist/blacklist_listener_unittest.cc', - 'browser/privacy_blacklist/blacklist_manager_unittest.cc', - 'browser/privacy_blacklist/blacklist_test_util.cc', - 'browser/privacy_blacklist/blacklist_test_util.h', 'browser/privacy_blacklist/blacklist_unittest.cc', 'browser/process_info_snapshot_mac_unittest.cc', 'browser/profile_manager_unittest.cc', @@ -1119,7 +1115,6 @@ 'browser/gtk/bookmark_manager_browsertest.cc', 'browser/net/cookie_policy_browsertest.cc', 'browser/net/ftp_browsertest.cc', - 'browser/privacy_blacklist/blacklist_manager_browsertest.cc', 'browser/ssl/ssl_browser_tests.cc', 'browser/task_manager_browsertest.cc', ], diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 9f86ac8..1ad3ee2 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -969,26 +969,6 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, return true; } - // Initialize privacy blacklists (optional). - if (source.HasKey(keys::kPrivacyBlacklists)) { - ListValue* blacklists; - if (!source.GetList(keys::kPrivacyBlacklists, &blacklists)) { - *error = errors::kInvalidPrivacyBlacklists; - return false; - } - - for (size_t i = 0; i < blacklists->GetSize(); ++i) { - std::string path; - if (!blacklists->GetString(i, &path)) { - *error = ExtensionErrorUtils::FormatErrorMessage( - errors::kInvalidPrivacyBlacklistsPath, IntToString(i)); - return false; - } - privacy_blacklists_.push_back(PrivacyBlacklistInfo()); - privacy_blacklists_.back().path = path_.AppendASCII(path); - } - } - // Initialize plugins (optional). if (source.HasKey(keys::kPlugins)) { ListValue* list_value; diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 03eaee3..8175948 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -78,10 +78,6 @@ class Extension { static const char* kPermissionNames[]; static const size_t kNumPermissions; - struct PrivacyBlacklistInfo { - FilePath path; // Path to the plain-text blacklist. - }; - // An NPAPI plugin included in the extension. struct PluginInfo { FilePath path; // Path to the plugin. @@ -208,9 +204,6 @@ class Extension { const UserScriptList& content_scripts() const { return content_scripts_; } ExtensionAction* page_action() const { return page_action_.get(); } ExtensionAction* browser_action() const { return browser_action_.get(); } - const std::vector<PrivacyBlacklistInfo>& privacy_blacklists() const { - return privacy_blacklists_; - } const std::vector<PluginInfo>& plugins() const { return plugins_; } const GURL& background_url() const { return background_url_; } const GURL& options_url() const { return options_url_; } @@ -363,9 +356,6 @@ class Extension { // The extension's browser action, if any. scoped_ptr<ExtensionAction> browser_action_; - // Optional list of privacy blacklistrom. - std::vector<PrivacyBlacklistInfo> privacy_blacklists_; - // Optional list of NPAPI plugins and associated properties. std::vector<PluginInfo> plugins_; diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc index 817b54f..d203552 100644 --- a/chrome/common/extensions/extension_constants.cc +++ b/chrome/common/extensions/extension_constants.cc @@ -39,7 +39,6 @@ const wchar_t* kPermissions = L"permissions"; const wchar_t* kPlugins = L"plugins"; const wchar_t* kPluginsPath = L"path"; const wchar_t* kPluginsPublic = L"public"; -const wchar_t* kPrivacyBlacklists = L"privacy_blacklists"; const wchar_t* kPublicKey = L"key"; const wchar_t* kRunAt = L"run_at"; const wchar_t* kSignature = L"signature"; @@ -155,10 +154,6 @@ const char* kInvalidPluginsPath = "Invalid value for 'plugins[*].path'."; const char* kInvalidPluginsPublic = "Invalid value for 'plugins[*].public'."; -const char* kInvalidPrivacyBlacklists = - "Invalid value for 'privacy_blacklists'."; -const char* kInvalidPrivacyBlacklistsPath = - "Invalid value for 'privacy_blacklists[*]'."; const char* kInvalidBackground = "Invalid value for 'background_page'."; const char* kInvalidRunAt = diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h index 430070e..c28c583 100644 --- a/chrome/common/extensions/extension_constants.h +++ b/chrome/common/extensions/extension_constants.h @@ -40,7 +40,6 @@ namespace extension_manifest_keys { extern const wchar_t* kPlugins; extern const wchar_t* kPluginsPath; extern const wchar_t* kPluginsPublic; - extern const wchar_t* kPrivacyBlacklists; extern const wchar_t* kPublicKey; extern const wchar_t* kSignature; extern const wchar_t* kRunAt; @@ -99,8 +98,6 @@ namespace extension_manifest_errors { extern const char* kInvalidPlugins; extern const char* kInvalidPluginsPath; extern const char* kInvalidPluginsPublic; - extern const char* kInvalidPrivacyBlacklists; - extern const char* kInvalidPrivacyBlacklistsPath; extern const char* kInvalidRunAt; extern const char* kInvalidSignature; diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc index 1cdc590..d0e14e4 100644 --- a/chrome/common/extensions/extension_unittest.cc +++ b/chrome/common/extensions/extension_unittest.cc @@ -208,21 +208,6 @@ TEST(ExtensionTest, InitFromValueInvalid) { EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidPermissionScheme)); - // Test invalid privacy blacklists list. - input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); - input_value->SetInteger(keys::kPrivacyBlacklists, 42); - EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); - EXPECT_EQ(errors::kInvalidPrivacyBlacklists, error); - - // Test invalid privacy blacklists list item. - input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); - ListValue* privacy_blacklists = NULL; - input_value->GetList(keys::kPrivacyBlacklists, &privacy_blacklists); - ASSERT_FALSE(NULL == privacy_blacklists); - privacy_blacklists->Set(0, Value::CreateIntegerValue(42)); - EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); - EXPECT_TRUE(MatchPatternASCII(error, errors::kInvalidPrivacyBlacklistsPath)); - // Multiple page actions are not allowed. input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); DictionaryValue* action = new DictionaryValue; diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index d3f5640..409a082 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -755,15 +755,6 @@ class NotificationType { // Privacy Blacklist ------------------------------------------------------- - // 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 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 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. diff --git a/chrome/test/data/extensions/common/privacy_blacklist/manifest.json b/chrome/test/data/extensions/common/privacy_blacklist/manifest.json deleted file mode 100644 index 8e3b221..0000000 --- a/chrome/test/data/extensions/common/privacy_blacklist/manifest.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "description": "Extension which has a privacy blacklist", - "name": "privacy_blacklist", - "privacy_blacklists": [ - "privacy_blacklist.pbl" - ], - "version": "0.1" -}
\ No newline at end of file diff --git a/chrome/test/data/extensions/common/privacy_blacklist/privacy_blacklist.pbl b/chrome/test/data/extensions/common/privacy_blacklist/privacy_blacklist.pbl deleted file mode 100644 index df63d90..0000000 --- a/chrome/test/data/extensions/common/privacy_blacklist/privacy_blacklist.pbl +++ /dev/null @@ -1,12 +0,0 @@ -[Chromium::PrivacyBlacklist] -|Name: AnnoyingAds -|URL: http://www.example.com - -# Block Ads by servers -example.com/@ => kBlockAll - -# Block Ads by name -@/annoying/120x600.jpg => kBlockAll - -# Block Ads by path -@/annoying_ads/@ => kBlockAll diff --git a/chrome/test/data/extensions/privacy_blacklists/invalid_blacklist/manifest.json b/chrome/test/data/extensions/privacy_blacklists/invalid_blacklist/manifest.json deleted file mode 100644 index 2f9801a..0000000 --- a/chrome/test/data/extensions/privacy_blacklists/invalid_blacklist/manifest.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "description": "Extension which has an invalid privacy blacklist", - "name": "invalid", - "privacy_blacklists": [ - "privacy_blacklist.pbl" - ], - "version": "0.1" -} diff --git a/chrome/test/data/extensions/privacy_blacklists/invalid_blacklist/privacy_blacklist.pbl b/chrome/test/data/extensions/privacy_blacklists/invalid_blacklist/privacy_blacklist.pbl deleted file mode 100644 index 9ce7649..0000000 --- a/chrome/test/data/extensions/privacy_blacklists/invalid_blacklist/privacy_blacklist.pbl +++ /dev/null @@ -1 +0,0 @@ -garbage diff --git a/chrome/test/data/extensions/privacy_blacklists/missing_blacklist/manifest.json b/chrome/test/data/extensions/privacy_blacklists/missing_blacklist/manifest.json deleted file mode 100644 index d47fac5..0000000 --- a/chrome/test/data/extensions/privacy_blacklists/missing_blacklist/manifest.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "description": "Extension which has a missing privacy blacklist", - "name": "missing_blacklist", - "privacy_blacklists": [ - "privacy_blacklist.pbl" - ], - "version": "0.1" -} diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 3e38d3e..e5e1b49 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -168,7 +168,7 @@ class TestingProfile : public Profile { } virtual net::SSLConfigService* GetSSLConfigService() { return NULL; } - virtual BlacklistManager* GetBlacklistManager() { return NULL; } + virtual Blacklist* GetPrivacyBlacklist() { return NULL; } virtual HostZoomMap* GetHostZoomMap() { return NULL; } void set_session_service(SessionService* session_service) { session_service_ = session_service; |