| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 14 #include "content/browser/renderer_host/render_view_host.h" | 14 #include "content/browser/renderer_host/render_view_host.h" |
| 15 #include "content/browser/tab_contents/tab_contents.h" | |
| 16 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
| 17 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
| 17 #include "content/public/browser/web_contents.h" |
| 18 | 18 |
| 19 #if defined(ENABLE_SAFE_BROWSING) | 19 #if defined(ENABLE_SAFE_BROWSING) |
| 20 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 20 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 namespace safe_browsing { | 23 namespace safe_browsing { |
| 24 | 24 |
| 25 #if !defined(ENABLE_SAFE_BROWSING) | 25 #if !defined(ENABLE_SAFE_BROWSING) |
| 26 // Provide a dummy implementation so that scoped_ptr<ClientSideDetectionHost> | 26 // Provide a dummy implementation so that scoped_ptr<ClientSideDetectionHost> |
| 27 // has a concrete destructor to call. This is necessary because it is used | 27 // has a concrete destructor to call. This is necessary because it is used |
| 28 // as a member of SafeBrowsingTabObserver, even if it only ever contains NULL. | 28 // as a member of SafeBrowsingTabObserver, even if it only ever contains NULL. |
| 29 class ClientSideDetectionHost { }; | 29 class ClientSideDetectionHost { }; |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 SafeBrowsingTabObserver::SafeBrowsingTabObserver( | 32 SafeBrowsingTabObserver::SafeBrowsingTabObserver( |
| 33 TabContentsWrapper* wrapper) : wrapper_(wrapper) { | 33 TabContentsWrapper* wrapper) : wrapper_(wrapper) { |
| 34 #if defined(ENABLE_SAFE_BROWSING) | 34 #if defined(ENABLE_SAFE_BROWSING) |
| 35 PrefService* prefs = wrapper_->profile()->GetPrefs(); | 35 PrefService* prefs = wrapper_->profile()->GetPrefs(); |
| 36 if (prefs) { | 36 if (prefs) { |
| 37 pref_change_registrar_.Init(prefs); | 37 pref_change_registrar_.Init(prefs); |
| 38 pref_change_registrar_.Add(prefs::kSafeBrowsingEnabled, this); | 38 pref_change_registrar_.Add(prefs::kSafeBrowsingEnabled, this); |
| 39 | 39 |
| 40 if (prefs->GetBoolean(prefs::kSafeBrowsingEnabled) && | 40 if (prefs->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 41 g_browser_process->safe_browsing_detection_service()) { | 41 g_browser_process->safe_browsing_detection_service()) { |
| 42 safebrowsing_detection_host_.reset( | 42 safebrowsing_detection_host_.reset( |
| 43 ClientSideDetectionHost::Create(wrapper_->tab_contents())); | 43 ClientSideDetectionHost::Create(wrapper_->web_contents())); |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 #endif | 46 #endif |
| 47 } | 47 } |
| 48 | 48 |
| 49 SafeBrowsingTabObserver::~SafeBrowsingTabObserver() { | 49 SafeBrowsingTabObserver::~SafeBrowsingTabObserver() { |
| 50 } | 50 } |
| 51 | 51 |
| 52 //////////////////////////////////////////////////////////////////////////////// | 52 //////////////////////////////////////////////////////////////////////////////// |
| 53 // content::NotificationObserver overrides | 53 // content::NotificationObserver overrides |
| (...skipping 23 matching lines...) Expand all Loading... |
| 77 // Internal helpers | 77 // Internal helpers |
| 78 | 78 |
| 79 void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() { | 79 void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() { |
| 80 #if defined(ENABLE_SAFE_BROWSING) | 80 #if defined(ENABLE_SAFE_BROWSING) |
| 81 PrefService* prefs = wrapper_->profile()->GetPrefs(); | 81 PrefService* prefs = wrapper_->profile()->GetPrefs(); |
| 82 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled); | 82 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled); |
| 83 if (safe_browsing && | 83 if (safe_browsing && |
| 84 g_browser_process->safe_browsing_detection_service()) { | 84 g_browser_process->safe_browsing_detection_service()) { |
| 85 if (!safebrowsing_detection_host_.get()) { | 85 if (!safebrowsing_detection_host_.get()) { |
| 86 safebrowsing_detection_host_.reset( | 86 safebrowsing_detection_host_.reset( |
| 87 ClientSideDetectionHost::Create(wrapper_->tab_contents())); | 87 ClientSideDetectionHost::Create(wrapper_->web_contents())); |
| 88 } | 88 } |
| 89 } else { | 89 } else { |
| 90 safebrowsing_detection_host_.reset(); | 90 safebrowsing_detection_host_.reset(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 RenderViewHost* rvh = wrapper_->tab_contents()->GetRenderViewHost(); | 93 RenderViewHost* rvh = wrapper_->web_contents()->GetRenderViewHost(); |
| 94 rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection(rvh->routing_id(), | 94 rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection(rvh->routing_id(), |
| 95 safe_browsing)); | 95 safe_browsing)); |
| 96 #endif | 96 #endif |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace safe_browsing | 99 } // namespace safe_browsing |
| OLD | NEW |