Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_tab_observer.cc

Issue 8865004: Create CoreTabHelper, move remaining core TCW functionality into it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lots of helpers now Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
6
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "chrome/common/chrome_notification_types.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/common/render_messages.h"
15 #include "content/browser/renderer_host/render_view_host.h"
16 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_source.h"
18
19 namespace safe_browsing {
20
21 SafeBrowsingTabObserver::SafeBrowsingTabObserver(
22 TabContentsWrapper* wrapper) : wrapper_(wrapper) {
23 #if defined(ENABLE_SAFE_BROWSING)
24 PrefService* prefs = wrapper_->profile()->GetPrefs();
25 if (prefs) {
26 pref_change_registrar_.Init(prefs);
27 pref_change_registrar_.Add(prefs::kSafeBrowsingEnabled, this);
28
29 if (prefs->GetBoolean(prefs::kSafeBrowsingEnabled) &&
30 g_browser_process->safe_browsing_detection_service()) {
31 safebrowsing_detection_host_.reset(
32 ClientSideDetectionHost::Create(wrapper_->tab_contents()));
33 }
34 }
35 #endif
36 }
37
38 SafeBrowsingTabObserver::~SafeBrowsingTabObserver() {
39 }
40
41 ////////////////////////////////////////////////////////////////////////////////
42 // content::NotificationObserver overrides
43
44 void SafeBrowsingTabObserver::Observe(
45 int type,
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) {
48 switch (type) {
49 case chrome::NOTIFICATION_PREF_CHANGED: {
50 std::string* pref_name = content::Details<std::string>(details).ptr();
51 DCHECK(content::Source<PrefService>(source).ptr() ==
52 wrapper_->profile()->GetPrefs());
53 if (*pref_name == prefs::kSafeBrowsingEnabled) {
54 UpdateSafebrowsingDetectionHost();
55 } else {
56 NOTREACHED() << "unexpected pref change notification" << *pref_name;
57 }
58 break;
59 }
60 default:
61 NOTREACHED();
62 }
63 }
64
65 ////////////////////////////////////////////////////////////////////////////////
66 // Internal helpers
67
68 void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() {
69 #if defined(ENABLE_SAFE_BROWSING)
70 PrefService* prefs = wrapper_->profile()->GetPrefs();
71 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled);
72 if (safe_browsing &&
73 g_browser_process->safe_browsing_detection_service()) {
74 if (!safebrowsing_detection_host_.get()) {
75 safebrowsing_detection_host_.reset(
76 ClientSideDetectionHost::Create(wrapper_->tab_contents()));
77 }
78 } else {
79 safebrowsing_detection_host_.reset();
80 }
81
82 RenderViewHost* rvh = wrapper_->tab_contents()->render_view_host();
83 rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection(rvh->routing_id(),
84 safe_browsing));
85 #endif
86 }
87
88 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698