summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser_process_impl.cc9
-rw-r--r--chrome/browser/chrome_content_browser_client.cc6
-rw-r--r--chrome/browser/download/download_file_manager.cc6
-rw-r--r--chrome/browser/download/download_manager.cc8
-rw-r--r--chrome/browser/download/download_safe_browsing_client.cc12
-rw-r--r--chrome/browser/download/download_safe_browsing_client.h9
-rw-r--r--chrome/browser/download/download_safe_browsing_client_unittest.cc4
-rw-r--r--chrome/browser/profiles/off_the_record_profile_io_data.cc6
-rw-r--r--chrome/browser/profiles/profile_impl_io_data.cc7
-rw-r--r--chrome/browser/profiles/profile_io_data.cc1
-rw-r--r--chrome/browser/profiles/profile_io_data.h5
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc10
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h20
-rw-r--r--chrome/browser/safe_browsing/client_side_detection_host.cc12
-rw-r--r--chrome/browser/safe_browsing/client_side_detection_host_unittest.cc5
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.cc44
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper.cc29
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents_wrapper.h4
-rw-r--r--chrome/common/render_messages.h4
-rw-r--r--chrome/renderer/chrome_content_renderer_client.cc12
-rw-r--r--chrome/renderer/chrome_render_view_observer.cc19
-rw-r--r--chrome/renderer/chrome_render_view_observer.h6
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host.cc10
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_delegate.cc2
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_delegate.h20
25 files changed, 176 insertions, 94 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index d554f7e..243b5be 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -938,6 +938,8 @@ void BrowserProcessImpl::CreateBackgroundPrintingManager() {
void BrowserProcessImpl::CreateSafeBrowsingService() {
DCHECK(safe_browsing_service_.get() == NULL);
+ // Set this flag to true so that we don't retry indefinitely to
+ // create the service class if there was an error.
created_safe_browsing_service_ = true;
#if defined(ENABLE_SAFE_BROWSING)
safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService();
@@ -953,14 +955,11 @@ void BrowserProcessImpl::CreateSafeBrowsingDetectionService() {
#if defined(ENABLE_SAFE_BROWSING)
FilePath model_file_dir;
- Profile* profile = profile_manager() ?
- profile_manager()->GetDefaultProfile() : NULL;
if (IsSafeBrowsingDetectionServiceEnabled() &&
- PathService::Get(chrome::DIR_USER_DATA, &model_file_dir) &&
- profile && profile->GetRequestContext()) {
+ PathService::Get(chrome::DIR_USER_DATA, &model_file_dir)) {
safe_browsing_detection_service_.reset(
safe_browsing::ClientSideDetectionService::Create(
- model_file_dir, profile->GetRequestContext()));
+ model_file_dir, g_browser_process->system_request_context()));
}
#endif
}
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 6dbe1f6..9758443 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -304,9 +304,11 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
}
// Disable client-side phishing detection in the renderer if it is disabled
- // in the browser process.
- if (!g_browser_process->safe_browsing_detection_service())
+ // in the Profile preferences or the browser process.
+ if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
+ !g_browser_process->safe_browsing_detection_service()) {
command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
+ }
static const char* const kSwitchNames[] = {
switches::kAllowHTTPBackgroundPage,
diff --git a/chrome/browser/download/download_file_manager.cc b/chrome/browser/download/download_file_manager.cc
index 37640ba..76803ec 100644
--- a/chrome/browser/download/download_file_manager.cc
+++ b/chrome/browser/download/download_file_manager.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/tab_contents/tab_util.h"
+#include "chrome/common/pref_names.h"
#include "content/browser/browser_thread.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/browser/tab_contents/tab_contents.h"
@@ -145,8 +146,9 @@ void DownloadFileManager::StartDownload(DownloadCreateInfo* info) {
manager->CreateDownloadItem(info);
#if defined(ENABLE_SAFE_BROWSING)
- bool hash_needed = g_browser_process->safe_browsing_service()->
- DownloadBinHashNeeded();
+ bool hash_needed = manager->profile()->GetPrefs()->GetBoolean(
+ prefs::kSafeBrowsingEnabled) &&
+ g_browser_process->safe_browsing_service()->DownloadBinHashNeeded();
#else
bool hash_needed = false;
#endif
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index c61912a..452dffb6 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -37,6 +37,7 @@
#include "chrome/browser/ui/download/download_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/pref_names.h"
#include "content/browser/browser_thread.h"
#include "content/browser/renderer_host/render_process_host.h"
#include "content/browser/renderer_host/render_view_host.h"
@@ -270,7 +271,8 @@ void DownloadManager::StartDownload(int32 download_id) {
// Create a client to verify download URL with safebrowsing.
// It deletes itself after the callback.
scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient(
- download_id, download->url_chain(), download->referrer_url());
+ download_id, download->url_chain(), download->referrer_url(),
+ profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled));
sb_client->CheckDownloadUrl(
NewCallback(this, &DownloadManager::CheckDownloadUrlDone));
#else
@@ -673,7 +675,9 @@ void DownloadManager::OnAllDataSaved(int32 download_id,
scoped_refptr<DownloadSBClient> sb_client =
new DownloadSBClient(download_id,
download->url_chain(),
- download->referrer_url());
+ download->referrer_url(),
+ profile_->GetPrefs()->GetBoolean(
+ prefs::kSafeBrowsingEnabled));
sb_client->CheckDownloadHash(
hash, NewCallback(this, &DownloadManager::CheckDownloadHashDone));
#else
diff --git a/chrome/browser/download/download_safe_browsing_client.cc b/chrome/browser/download/download_safe_browsing_client.cc
index 3f4117c..671a65a 100644
--- a/chrome/browser/download/download_safe_browsing_client.cc
+++ b/chrome/browser/download/download_safe_browsing_client.cc
@@ -23,10 +23,12 @@
DownloadSBClient::DownloadSBClient(int32 download_id,
const std::vector<GURL>& url_chain,
- const GURL& referrer_url)
+ const GURL& referrer_url,
+ bool safe_browsing_enabled)
: download_id_(download_id),
url_chain_(url_chain),
- referrer_url_(referrer_url) {
+ referrer_url_(referrer_url),
+ safe_browsing_enabled_(safe_browsing_enabled) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!url_chain.empty());
ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host();
@@ -73,7 +75,8 @@ void DownloadSBClient::CheckDownloadUrlOnIOThread(
// Will be released in OnDownloadUrlCheckResult.
AddRef();
- if (sb_service_.get() && !sb_service_->CheckDownloadUrl(url_chain, this)) {
+ if (safe_browsing_enabled_ && sb_service_.get() &&
+ !sb_service_->CheckDownloadUrl(url_chain, this)) {
// Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult.
return;
}
@@ -97,7 +100,8 @@ void DownloadSBClient::CheckDownloadHashOnIOThread(const std::string& hash) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// Will be released in OnDownloadUrlCheckResult.
AddRef();
- if (sb_service_.get() && !sb_service_->CheckDownloadHash(hash, this)) {
+ if (safe_browsing_enabled_ && sb_service_.get() &&
+ !sb_service_->CheckDownloadHash(hash, this)) {
// Wait for SafeBrowsingService to call back OnDownloadUrlCheckResult.
return;
}
diff --git a/chrome/browser/download/download_safe_browsing_client.h b/chrome/browser/download/download_safe_browsing_client.h
index 0527192..a6d0712 100644
--- a/chrome/browser/download/download_safe_browsing_client.h
+++ b/chrome/browser/download/download_safe_browsing_client.h
@@ -35,9 +35,10 @@ class DownloadSBClient
DownloadSBClient(int32 download_id,
const std::vector<GURL>& url_chain,
- const GURL& referrer_url);
+ const GURL& referrer_url,
+ bool safe_browsing_enabled);
- // Call safebrowsing service to verifiy the download.
+ // Call safebrowsing service to verify the download.
// For each DownloadSBClient instance, either CheckDownloadUrl or
// CheckDownloadHash can be called, and be called only once.
// DownloadSBClient instance.
@@ -110,6 +111,10 @@ class DownloadSBClient
// When a safebrowsing check starts, for stats purpose.
base::TimeTicks start_time_;
+ // Whether the profile from which this client was created has enabled the
+ // safe browsing service.
+ bool safe_browsing_enabled_;
+
DISALLOW_COPY_AND_ASSIGN(DownloadSBClient);
};
diff --git a/chrome/browser/download/download_safe_browsing_client_unittest.cc b/chrome/browser/download/download_safe_browsing_client_unittest.cc
index d248b4d..05bc36e 100644
--- a/chrome/browser/download/download_safe_browsing_client_unittest.cc
+++ b/chrome/browser/download/download_safe_browsing_client_unittest.cc
@@ -59,7 +59,7 @@ TEST_F(DownloadSBClientTest, UrlHit) {
url_chain.push_back(GURL(kUrl3));
scoped_refptr<DownloadSBClient> client(
- new DownloadSBClient(1, url_chain, GURL(kRefUrl)));
+ new DownloadSBClient(1, url_chain, GURL(kRefUrl), true));
client->SetSBService(sb_service.get());
client->ReportMalware(SafeBrowsingService::BINARY_MALWARE_URL, "");
@@ -82,7 +82,7 @@ TEST_F(DownloadSBClientTest, DigestHit) {
url_chain.push_back(GURL(kUrl3));
scoped_refptr<DownloadSBClient> client(
- new DownloadSBClient(1, url_chain, GURL(kRefUrl)));
+ new DownloadSBClient(1, url_chain, GURL(kRefUrl), true));
client->SetSBService(sb_service.get());
client->ReportMalware(SafeBrowsingService::BINARY_MALWARE_HASH, hash_data);
diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc
index 476c41f..30f9f2c 100644
--- a/chrome/browser/profiles/off_the_record_profile_io_data.cc
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/browser/browser_thread.h"
#include "content/browser/resource_context.h"
@@ -108,6 +109,11 @@ void OffTheRecordProfileIOData::Handle::LazyInitialize() const {
io_data_->InitializeProfileParams(profile_);
ChromeNetworkDelegate::InitializeReferrersEnabled(
io_data_->enable_referrers(), profile_->GetPrefs());
+#if defined(ENABLE_SAFE_BROWSING)
+ io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled,
+ profile_->GetPrefs(), NULL);
+ io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO);
+#endif
initialized_ = true;
}
}
diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc
index b5cb886..949f14e 100644
--- a/chrome/browser/profiles/profile_impl_io_data.cc
+++ b/chrome/browser/profiles/profile_impl_io_data.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/net/sqlite_persistent_cookie_store.h"
+#include "chrome/browser/prefs/pref_member.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -131,6 +132,7 @@ ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter(
if (iter != app_request_context_getter_map_.end())
return iter->second;
+
ChromeURLRequestContextGetter* context =
ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp(
profile_, io_data_, app_id);
@@ -147,6 +149,11 @@ void ProfileImplIOData::Handle::LazyInitialize() const {
io_data_->clear_local_state_on_exit()->Init(
prefs::kClearSiteDataOnExit, profile_->GetPrefs(), NULL);
io_data_->clear_local_state_on_exit()->MoveToThread(BrowserThread::IO);
+#if defined(ENABLE_SAFE_BROWSING)
+ io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled,
+ profile_->GetPrefs(), NULL);
+ io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO);
+#endif
initialized_ = true;
}
}
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
index da39eb4..01e7bd5 100644
--- a/chrome/browser/profiles/profile_io_data.cc
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -545,4 +545,5 @@ void ProfileIOData::ShutdownOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
enable_referrers_.Destroy();
clear_local_state_on_exit_.Destroy();
+ safe_browsing_enabled_.Destroy();
}
diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h
index 8cbdfd4..de505c8 100644
--- a/chrome/browser/profiles/profile_io_data.h
+++ b/chrome/browser/profiles/profile_io_data.h
@@ -106,6 +106,10 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
return weak_extensions_request_context_.get();
}
+ BooleanPrefMember* safe_browsing_enabled() const {
+ return &safe_browsing_enabled_;
+ }
+
protected:
friend class base::RefCountedThreadSafe<ProfileIOData>;
@@ -267,6 +271,7 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
// Member variables which are pointed to by the various context objects.
mutable BooleanPrefMember enable_referrers_;
mutable BooleanPrefMember clear_local_state_on_exit_;
+ mutable BooleanPrefMember safe_browsing_enabled_;
// Pointed to by URLRequestContext.
mutable scoped_ptr<ChromeURLDataManagerBackend>
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
index 5c10442..a4b809c 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -112,6 +112,7 @@ bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest(
ResourceHandler* ChromeResourceDispatcherHostDelegate::RequestBeginning(
ResourceHandler* handler,
net::URLRequest* request,
+ const content::ResourceContext& resource_context,
bool is_subresource,
int child_id,
int route_id) {
@@ -121,7 +122,9 @@ ResourceHandler* ChromeResourceDispatcherHostDelegate::RequestBeginning(
#if defined(ENABLE_SAFE_BROWSING)
// Insert safe browsing at the front of the chain, so it gets to decide
// on policies first.
- if (safe_browsing_->enabled()) {
+ ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
+ resource_context.GetUserData(NULL));
+ if (io_data->safe_browsing_enabled()->GetValue()) {
handler = CreateSafeBrowsingResourceHandler(
handler, child_id, route_id, is_subresource);
}
@@ -138,10 +141,13 @@ ResourceHandler* ChromeResourceDispatcherHostDelegate::RequestBeginning(
ResourceHandler* ChromeResourceDispatcherHostDelegate::DownloadStarting(
ResourceHandler* handler,
+ const content::ResourceContext& resource_context,
int child_id,
int route_id) {
#if defined(ENABLE_SAFE_BROWSING)
- if (!safe_browsing_->enabled())
+ ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
+ resource_context.GetUserData(NULL));
+ if (!io_data->safe_browsing_enabled()->GetValue())
return handler;
return CreateSafeBrowsingResourceHandler(handler, child_id, route_id, false);
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
index 97dfd6b..181c860 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
@@ -37,14 +37,18 @@ class ChromeResourceDispatcherHostDelegate
const ResourceHostMsg_Request& request_data,
const content::ResourceContext& resource_context,
const GURL& referrer) OVERRIDE;
- virtual ResourceHandler* RequestBeginning(ResourceHandler* handler,
- net::URLRequest* request,
- bool is_subresource,
- int child_id,
- int route_id) OVERRIDE;
- virtual ResourceHandler* DownloadStarting(ResourceHandler* handler,
- int child_id,
- int route_id) OVERRIDE;
+ virtual ResourceHandler* RequestBeginning(
+ ResourceHandler* handler,
+ net::URLRequest* request,
+ const content::ResourceContext& resource_context,
+ bool is_subresource,
+ int child_id,
+ int route_id) OVERRIDE;
+ virtual ResourceHandler* DownloadStarting(
+ ResourceHandler* handler,
+ const content::ResourceContext& resource_context,
+ int child_id,
+ int route_id) OVERRIDE;
virtual bool ShouldDeferStart(
net::URLRequest* request,
const content::ResourceContext& resource_context) OVERRIDE;
diff --git a/chrome/browser/safe_browsing/client_side_detection_host.cc b/chrome/browser/safe_browsing/client_side_detection_host.cc
index 3f81a76..2b2d1db 100644
--- a/chrome/browser/safe_browsing/client_side_detection_host.cc
+++ b/chrome/browser/safe_browsing/client_side_detection_host.cc
@@ -12,11 +12,13 @@
#include "base/metrics/histogram.h"
#include "base/task.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/browser_feature_extractor.h"
#include "chrome/browser/safe_browsing/client_side_detection_service.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/safe_browsing/csd.pb.h"
#include "chrome/common/safe_browsing/safebrowsing_messages.h"
#include "content/browser/browser_thread.h"
@@ -266,15 +268,13 @@ ClientSideDetectionHost* ClientSideDetectionHost::Create(
ClientSideDetectionHost::ClientSideDetectionHost(TabContents* tab)
: TabContentsObserver(tab),
- csd_service_(g_browser_process->safe_browsing_detection_service()),
- feature_extractor_(
- new BrowserFeatureExtractor(
- tab,
- g_browser_process->safe_browsing_detection_service())),
+ csd_service_(NULL),
cb_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
DCHECK(tab);
- // Note: csd_service_ and sb_service_ might be NULL.
+ csd_service_ = g_browser_process->safe_browsing_detection_service();
+ feature_extractor_.reset(new BrowserFeatureExtractor(tab, csd_service_));
sb_service_ = g_browser_process->safe_browsing_service();
+ // Note: csd_service_ and sb_service_ will be NULL here in testing.
registrar_.Add(this, content::NOTIFICATION_RESOURCE_RESPONSE_STARTED,
Source<RenderViewHostDelegate>(tab));
}
diff --git a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
index b064d48..3ce5f8a 100644
--- a/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
+++ b/chrome/browser/safe_browsing/client_side_detection_host_unittest.cc
@@ -149,7 +149,8 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness {
// Inject service classes.
csd_service_.reset(new StrictMock<MockClientSideDetectionService>());
sb_service_ = new StrictMock<MockSafeBrowsingService>();
- csd_host_ = contents_wrapper()->safebrowsing_detection_host();
+ csd_host_.reset(safe_browsing::ClientSideDetectionHost::Create(
+ contents_wrapper()->tab_contents()));
csd_host_->set_client_side_detection_service(csd_service_.get());
csd_host_->set_safe_browsing_service(sb_service_.get());
}
@@ -225,7 +226,7 @@ class ClientSideDetectionHostTest : public TabContentsWrapperTestHarness {
}
protected:
- ClientSideDetectionHost* csd_host_;
+ scoped_ptr<ClientSideDetectionHost> csd_host_;
scoped_ptr<StrictMock<MockClientSideDetectionService> > csd_service_;
scoped_refptr<StrictMock<MockSafeBrowsingService> > sb_service_;
MockTestingProfile* mock_profile_; // We don't own this object
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index f549612..f94244d 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -14,7 +14,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/malware_details.h"
#include "chrome/browser/safe_browsing/protocol_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
@@ -54,14 +54,6 @@ const int64 kDownloadUrlCheckTimeoutMs = 10000;
// Similar to kDownloadUrlCheckTimeoutMs, but for download hash checks.
const int64 kDownloadHashCheckTimeoutMs = 10000;
-// TODO(lzheng): Replace this with Profile* ProfileManager::GetDefaultProfile().
-Profile* GetDefaultProfile() {
- FilePath user_data_dir;
- PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- ProfileManager* profile_manager = g_browser_process->profile_manager();
- return profile_manager->GetDefaultProfile(user_data_dir);
-}
-
// Records disposition information about the check. |hit| should be
// |true| if there were any prefix hits in |full_hashes|.
void RecordGetHashCheckStatus(
@@ -172,10 +164,11 @@ SafeBrowsingService::SafeBrowsingService()
}
void SafeBrowsingService::Initialize() {
- // Get the profile's preference for SafeBrowsing.
- PrefService* pref_service = GetDefaultProfile()->GetPrefs();
- if (pref_service->GetBoolean(prefs::kSafeBrowsingEnabled))
- Start();
+ // Always initialize the safe browsing service. Each profile will decide
+ // whether to use it based on per-user preferences. TODO(mirandac): in
+ // follow-up CL, only initialize if a profile is launched for which safe
+ // browsing is enabled. see http://crbug.com/88661
+ Start();
}
void SafeBrowsingService::ShutDown() {
@@ -190,13 +183,11 @@ bool SafeBrowsingService::CanCheckUrl(const GURL& url) const {
url.SchemeIs(chrome::kHttpsScheme);
}
-// Only report SafeBrowsing related stats when UMA is enabled and
-// safe browsing is enabled.
+// Only report SafeBrowsing related stats when UMA is enabled. User must also
+// ensure that safe browsing is enabled from the calling profile.
bool SafeBrowsingService::CanReportStats() const {
const MetricsService* metrics = g_browser_process->metrics_service();
- const PrefService* pref_service = GetDefaultProfile()->GetPrefs();
- return metrics && metrics->reporting_active() &&
- pref_service && pref_service->GetBoolean(prefs::kSafeBrowsingEnabled);
+ return metrics && metrics->reporting_active();
}
// Binhash verification is only enabled for UMA users for now.
@@ -861,9 +852,9 @@ void SafeBrowsingService::Start() {
local_state->GetString(prefs::kSafeBrowsingWrappedKey);
}
- // We will issue network fetches using the default profile's request context.
+ // We will issue network fetches using the system request context.
scoped_refptr<net::URLRequestContextGetter> request_context_getter(
- GetDefaultProfile()->GetRequestContext());
+ g_browser_process->system_request_context());
CommandLine* cmdline = CommandLine::ForCurrentProcess();
enable_download_protection_ =
@@ -988,13 +979,13 @@ void SafeBrowsingService::DoDisplayBlockingPage(
}
// The tab might have been closed.
- TabContents* wc =
+ TabContents* tab_contents =
tab_util::GetTabContentsByID(resource.render_process_host_id,
resource.render_view_id);
- if (!wc) {
+ if (!tab_contents) {
// The tab is gone and we did not have a chance at showing the interstitial.
- // Just act as "Don't Proceed" was chosen.
+ // Just act as if "Don't Proceed" were chosen.
std::vector<UnsafeResource> resources;
resources.push_back(resource);
BrowserThread::PostTask(
@@ -1004,10 +995,11 @@ void SafeBrowsingService::DoDisplayBlockingPage(
return;
}
- if (resource.threat_type != SafeBrowsingService::SAFE && CanReportStats()) {
- GURL page_url = wc->GetURL();
+ if (resource.threat_type != SafeBrowsingService::SAFE &&
+ CanReportStats()) {
+ GURL page_url = tab_contents->GetURL();
GURL referrer_url;
- NavigationEntry* entry = wc->controller().GetActiveEntry();
+ NavigationEntry* entry = tab_contents->controller().GetActiveEntry();
if (entry)
referrer_url = entry->referrer();
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
index 3dfc4ba..4e42298 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/autocomplete_history_manager.h"
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/automation/automation_tab_helper.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
@@ -75,6 +76,9 @@ const char* kPrefsToObserve[] = {
prefs::kDefaultCharset,
prefs::kDefaultZoomLevel,
prefs::kEnableReferrers,
+#if defined (ENABLE_SAFE_BROWSING)
+ prefs::kSafeBrowsingEnabled,
+#endif
prefs::kWebKitAllowDisplayingInsecureContent,
prefs::kWebKitAllowRunningInsecureContent,
prefs::kWebKitDefaultFixedFontSize,
@@ -128,8 +132,11 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents)
password_manager_.reset(
new PasswordManager(contents, password_manager_delegate_.get()));
#if defined(ENABLE_SAFE_BROWSING)
- safebrowsing_detection_host_.reset(
- safe_browsing::ClientSideDetectionHost::Create(contents));
+ if (profile()->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) &&
+ g_browser_process->safe_browsing_detection_service()) {
+ safebrowsing_detection_host_.reset(
+ safe_browsing::ClientSideDetectionHost::Create(contents));
+ }
#endif
search_engine_tab_helper_.reset(new SearchEngineTabHelper(contents));
ssl_helper_.reset(new TabContentsSSLHelper(this));
@@ -458,6 +465,8 @@ void TabContentsWrapper::Observe(int type,
routing_id(), tab_contents()->GetZoomLevel()));
} else if (*pref_name_in == prefs::kEnableReferrers) {
UpdateRendererPreferences();
+ } else if (*pref_name_in == prefs::kSafeBrowsingEnabled) {
+ UpdateSafebrowsingDetectionHost();
} else {
NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
}
@@ -631,6 +640,22 @@ void TabContentsWrapper::UpdateRendererPreferences() {
render_view_host()->SyncRendererPrefs();
}
+void TabContentsWrapper::UpdateSafebrowsingDetectionHost() {
+ PrefService* prefs = profile()->GetPrefs();
+ bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled);
+ if (safe_browsing &&
+ g_browser_process->safe_browsing_detection_service()) {
+ if (!safebrowsing_detection_host_.get()) {
+ safebrowsing_detection_host_.reset(
+ safe_browsing::ClientSideDetectionHost::Create(tab_contents()));
+ }
+ } else {
+ safebrowsing_detection_host_.reset();
+ }
+ render_view_host()->Send(
+ new ViewMsg_SetClientSidePhishingDetection(routing_id(), safe_browsing));
+}
+
void TabContentsWrapper::RemoveInfoBarInternal(InfoBarDelegate* delegate,
bool animate) {
if (!infobars_enabled_) {
diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
index 3064302..a1f5d70 100644
--- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
+++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h
@@ -259,6 +259,10 @@ class TabContentsWrapper : public TabContentsObserver,
// Update the TabContents's RendererPreferences.
void UpdateRendererPreferences();
+ // Create or destroy SafebrowsingDetectionHost as needed if the user's
+ // safe browsing preference has changed.
+ void UpdateSafebrowsingDetectionHost();
+
void RemoveInfoBarInternal(InfoBarDelegate* delegate, bool animate);
void RemoveAllInfoBars(bool animate);
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index d33c9fb..224b1e7 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -276,6 +276,10 @@ IPC_MESSAGE_ROUTED1(ViewMsg_SetAllowDisplayingInsecureContent,
IPC_MESSAGE_ROUTED1(ViewMsg_SetAllowRunningInsecureContent,
bool /* allowed */)
+// Sent when the profile changes the kSafeBrowsingEnabled preference.
+IPC_MESSAGE_ROUTED1(ViewMsg_SetClientSidePhishingDetection,
+ bool /* enable_phishing_detection */)
+
// Instructs the renderer to save the current page to MHTML.
IPC_MESSAGE_ROUTED2(ViewMsg_SavePageAsMHTML,
int /* job_id */,
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index 5339d33..fb387f7 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -197,15 +197,6 @@ void ChromeContentRendererClient::RenderThreadStarted() {
}
void ChromeContentRendererClient::RenderViewCreated(RenderView* render_view) {
- safe_browsing::PhishingClassifierDelegate* phishing_classifier = NULL;
-#if defined(ENABLE_SAFE_BROWSING) && !defined(OS_CHROMEOS)
- if (!CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableClientSidePhishingDetection)) {
- phishing_classifier =
- safe_browsing::PhishingClassifierDelegate::Create(render_view, NULL);
- }
-#endif
-
ContentSettingsObserver* content_settings =
new ContentSettingsObserver(render_view);
new DevToolsAgent(render_view);
@@ -236,8 +227,7 @@ void ChromeContentRendererClient::RenderViewCreated(RenderView* render_view) {
TranslateHelper* translate = new TranslateHelper(render_view, autofill_agent);
new ChromeRenderViewObserver(
- render_view, content_settings, extension_dispatcher_.get(),
- translate, phishing_classifier);
+ render_view, content_settings, extension_dispatcher_.get(), translate);
// Used only for testing/automation.
if (CommandLine::ForCurrentProcess()->HasSwitch(
diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc
index dd0977e..afbefdd9 100644
--- a/chrome/renderer/chrome_render_view_observer.cc
+++ b/chrome/renderer/chrome_render_view_observer.cc
@@ -158,13 +158,12 @@ ChromeRenderViewObserver::ChromeRenderViewObserver(
RenderView* render_view,
ContentSettingsObserver* content_settings,
ExtensionDispatcher* extension_dispatcher,
- TranslateHelper* translate_helper,
- safe_browsing::PhishingClassifierDelegate* phishing_classifier)
+ TranslateHelper* translate_helper)
: RenderViewObserver(render_view),
content_settings_(content_settings),
extension_dispatcher_(extension_dispatcher),
translate_helper_(translate_helper),
- phishing_classifier_(phishing_classifier),
+ phishing_classifier_(NULL),
last_indexed_page_id_(-1),
allow_displaying_insecure_content_(false),
allow_running_insecure_content_(false),
@@ -176,6 +175,8 @@ ChromeRenderViewObserver::ChromeRenderViewObserver(
old_bindings |= BindingsPolicy::DOM_AUTOMATION);
}
render_view->webview()->setPermissionClient(this);
+ if (!command_line.HasSwitch(switches::kDisableClientSidePhishingDetection))
+ OnSetClientSidePhishingDetection(true);
}
ChromeRenderViewObserver::~ChromeRenderViewObserver() {
@@ -200,6 +201,8 @@ bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
OnSetAllowDisplayingInsecureContent)
IPC_MESSAGE_HANDLER(ViewMsg_SetAllowRunningInsecureContent,
OnSetAllowRunningInsecureContent)
+ IPC_MESSAGE_HANDLER(ViewMsg_SetClientSidePhishingDetection,
+ OnSetClientSidePhishingDetection)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -339,6 +342,16 @@ void ChromeRenderViewObserver::OnSetAllowRunningInsecureContent(bool allow) {
OnSetAllowDisplayingInsecureContent(allow);
}
+void ChromeRenderViewObserver::OnSetClientSidePhishingDetection(
+ bool enable_phishing_detection) {
+#if !defined(OS_CHROMEOS) || !defined(ENABLE_SAFE_BROWSING)
+ phishing_classifier_ = enable_phishing_detection ?
+ safe_browsing::PhishingClassifierDelegate::Create(
+ render_view(), NULL) :
+ NULL;
+#endif
+}
+
void ChromeRenderViewObserver::didSerializeDataForFrame(
const WebURL& frame_url,
const WebCString& data,
diff --git a/chrome/renderer/chrome_render_view_observer.h b/chrome/renderer/chrome_render_view_observer.h
index 98eaa9d..e05db1b 100644
--- a/chrome/renderer/chrome_render_view_observer.h
+++ b/chrome/renderer/chrome_render_view_observer.h
@@ -41,13 +41,12 @@ class ChromeRenderViewObserver : public RenderViewObserver,
public WebKit::WebPageSerializerClient,
public WebKit::WebPermissionClient {
public:
- // translate_helper and/or phishing_classifier can be NULL.
+ // translate_helper can be NULL.
ChromeRenderViewObserver(
RenderView* render_view,
ContentSettingsObserver* content_settings,
ExtensionDispatcher* extension_dispatcher,
- TranslateHelper* translate_helper,
- safe_browsing::PhishingClassifierDelegate* phishing_classifier);
+ TranslateHelper* translate_helper);
virtual ~ChromeRenderViewObserver();
private:
@@ -118,6 +117,7 @@ class ChromeRenderViewObserver : public RenderViewObserver,
void OnSetIsPrerendering(bool is_prerendering);
void OnSetAllowDisplayingInsecureContent(bool allow);
void OnSetAllowRunningInsecureContent(bool allow);
+ void OnSetClientSidePhishingDetection(bool enable_phishing_detection);
// Captures the thumbnail and text contents for indexing for the given load
// ID. If the view's load ID is different than the parameter, this call is
diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc
index 4e99336..0243717 100644
--- a/content/browser/renderer_host/resource_dispatcher_host.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host.cc
@@ -493,8 +493,8 @@ void ResourceDispatcherHost::BeginRequest(
if (delegate_) {
bool sub = request_data.resource_type != ResourceType::MAIN_FRAME;
- handler = delegate_->RequestBeginning(
- handler, request, sub, child_id, route_id);
+ handler = delegate_->RequestBeginning(handler, request, resource_context,
+ sub, child_id, route_id);
}
// Make extra info and read footer (contains request ID).
@@ -710,8 +710,10 @@ void ResourceDispatcherHost::BeginDownload(
prompt_for_save_location,
save_info));
- if (delegate_)
- handler = delegate_->DownloadStarting(handler, child_id, route_id);
+ if (delegate_) {
+ handler = delegate_->DownloadStarting(handler, context, child_id,
+ route_id);
+ }
const net::URLRequestContext* request_context = context.request_context();
diff --git a/content/browser/renderer_host/resource_dispatcher_host_delegate.cc b/content/browser/renderer_host/resource_dispatcher_host_delegate.cc
index 784dd42..65af22a 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_delegate.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_delegate.cc
@@ -21,6 +21,7 @@ bool ResourceDispatcherHostDelegate::ShouldBeginRequest(
ResourceHandler* ResourceDispatcherHostDelegate::RequestBeginning(
ResourceHandler* handler,
net::URLRequest* request,
+ const content::ResourceContext& resource_context,
bool is_subresource,
int child_id,
int route_id) {
@@ -29,6 +30,7 @@ ResourceHandler* ResourceDispatcherHostDelegate::RequestBeginning(
ResourceHandler* ResourceDispatcherHostDelegate::DownloadStarting(
ResourceHandler* handler,
+ const content::ResourceContext& resource_context,
int child_id,
int route_id) {
return handler;
diff --git a/content/browser/renderer_host/resource_dispatcher_host_delegate.h b/content/browser/renderer_host/resource_dispatcher_host_delegate.h
index 694d36c..cf60d03 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_delegate.h
+++ b/content/browser/renderer_host/resource_dispatcher_host_delegate.h
@@ -42,17 +42,21 @@ class ResourceDispatcherHostDelegate {
// content layer have been added. To add new handlers to the front, return
// a new handler that is chained to the given one, otherwise just reutrn the
// given handler.
- virtual ResourceHandler* RequestBeginning(ResourceHandler* handler,
- net::URLRequest* request,
- bool is_subresource,
- int child_id,
- int route_id);
+ virtual ResourceHandler* RequestBeginning(
+ ResourceHandler* handler,
+ net::URLRequest* request,
+ const content::ResourceContext& resource_context,
+ bool is_subresource,
+ int child_id,
+ int route_id);
// Called when a download is starting, after the resource handles from the
// content layer have been added.
- virtual ResourceHandler* DownloadStarting(ResourceHandler* handler,
- int child_id,
- int route_id);
+ virtual ResourceHandler* DownloadStarting(
+ ResourceHandler* handler,
+ const content::ResourceContext& resource_context,
+ int child_id,
+ int route_id);
// Called to determine whether a request's start should be deferred. This
// is only called if the ResourceHandler associated with the request does