| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
| 13 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
| 14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
| 15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 | 17 |
| 18 #if defined(FULL_SAFE_BROWSING) | 18 #if defined(SAFE_BROWSING_CSD) |
| 19 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 19 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(safe_browsing::SafeBrowsingTabObserver); | 22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(safe_browsing::SafeBrowsingTabObserver); |
| 23 | 23 |
| 24 namespace safe_browsing { | 24 namespace safe_browsing { |
| 25 | 25 |
| 26 #if !defined(FULL_SAFE_BROWSING) | 26 #if !defined(SAFE_BROWSING_CSD) |
| 27 // Provide a dummy implementation so that scoped_ptr<ClientSideDetectionHost> | 27 // Provide a dummy implementation so that scoped_ptr<ClientSideDetectionHost> |
| 28 // has a concrete destructor to call. This is necessary because it is used | 28 // has a concrete destructor to call. This is necessary because it is used |
| 29 // as a member of SafeBrowsingTabObserver, even if it only ever contains NULL. | 29 // as a member of SafeBrowsingTabObserver, even if it only ever contains NULL. |
| 30 // TODO(shess): This is weird, why not just guard the instance variable? |
| 30 class ClientSideDetectionHost { }; | 31 class ClientSideDetectionHost { }; |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 SafeBrowsingTabObserver::SafeBrowsingTabObserver( | 34 SafeBrowsingTabObserver::SafeBrowsingTabObserver( |
| 34 content::WebContents* web_contents) : web_contents_(web_contents) { | 35 content::WebContents* web_contents) : web_contents_(web_contents) { |
| 35 #if defined(FULL_SAFE_BROWSING) | 36 #if defined(SAFE_BROWSING_CSD) |
| 36 Profile* profile = | 37 Profile* profile = |
| 37 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 38 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 38 PrefService* prefs = profile->GetPrefs(); | 39 PrefService* prefs = profile->GetPrefs(); |
| 39 if (prefs) { | 40 if (prefs) { |
| 40 pref_change_registrar_.Init(prefs); | 41 pref_change_registrar_.Init(prefs); |
| 41 pref_change_registrar_.Add( | 42 pref_change_registrar_.Add( |
| 42 prefs::kSafeBrowsingEnabled, | 43 prefs::kSafeBrowsingEnabled, |
| 43 base::Bind(&SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost, | 44 base::Bind(&SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost, |
| 44 base::Unretained(this))); | 45 base::Unretained(this))); |
| 45 | 46 |
| 46 if (prefs->GetBoolean(prefs::kSafeBrowsingEnabled) && | 47 if (prefs->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 47 g_browser_process->safe_browsing_detection_service()) { | 48 g_browser_process->safe_browsing_detection_service()) { |
| 48 safebrowsing_detection_host_.reset( | 49 safebrowsing_detection_host_.reset( |
| 49 ClientSideDetectionHost::Create(web_contents)); | 50 ClientSideDetectionHost::Create(web_contents)); |
| 50 } | 51 } |
| 51 } | 52 } |
| 52 #endif | 53 #endif |
| 53 } | 54 } |
| 54 | 55 |
| 55 SafeBrowsingTabObserver::~SafeBrowsingTabObserver() { | 56 SafeBrowsingTabObserver::~SafeBrowsingTabObserver() { |
| 56 } | 57 } |
| 57 | 58 |
| 58 //////////////////////////////////////////////////////////////////////////////// | 59 //////////////////////////////////////////////////////////////////////////////// |
| 59 // Internal helpers | 60 // Internal helpers |
| 60 | 61 |
| 61 void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() { | 62 void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() { |
| 62 #if defined(FULL_SAFE_BROWSING) | 63 #if defined(SAFE_BROWSING_CSD) |
| 63 Profile* profile = | 64 Profile* profile = |
| 64 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 65 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 65 PrefService* prefs = profile->GetPrefs(); | 66 PrefService* prefs = profile->GetPrefs(); |
| 66 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled); | 67 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled); |
| 67 if (safe_browsing && | 68 if (safe_browsing && |
| 68 g_browser_process->safe_browsing_detection_service()) { | 69 g_browser_process->safe_browsing_detection_service()) { |
| 69 if (!safebrowsing_detection_host_.get()) { | 70 if (!safebrowsing_detection_host_.get()) { |
| 70 safebrowsing_detection_host_.reset( | 71 safebrowsing_detection_host_.reset( |
| 71 ClientSideDetectionHost::Create(web_contents_)); | 72 ClientSideDetectionHost::Create(web_contents_)); |
| 72 } | 73 } |
| 73 } else { | 74 } else { |
| 74 safebrowsing_detection_host_.reset(); | 75 safebrowsing_detection_host_.reset(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 78 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 78 rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection( | 79 rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection( |
| 79 rvh->GetRoutingID(), safe_browsing)); | 80 rvh->GetRoutingID(), safe_browsing)); |
| 80 #endif | 81 #endif |
| 81 } | 82 } |
| 82 | 83 |
| 83 // Forwards to detection host is client-side detection is enabled. | |
| 84 bool SafeBrowsingTabObserver::DidPageReceiveSafeBrowsingMatch() const { | 84 bool SafeBrowsingTabObserver::DidPageReceiveSafeBrowsingMatch() const { |
| 85 #if defined(FULL_SAFE_BROWSING) | 85 #if defined(SAFE_BROWSING_CSD) |
| 86 return safebrowsing_detection_host_ && | 86 return safebrowsing_detection_host_ && |
| 87 safebrowsing_detection_host_->DidPageReceiveSafeBrowsingMatch(); | 87 safebrowsing_detection_host_->DidPageReceiveSafeBrowsingMatch(); |
| 88 #else | 88 #else |
| 89 return false; | 89 return false; |
| 90 #endif | 90 #endif |
| 91 } | 91 } |
| 92 | 92 |
| 93 } // namespace safe_browsing | 93 } // namespace safe_browsing |
| OLD | NEW |