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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_tab_observer.cc
diff --git a/chrome/browser/safe_browsing/safe_browsing_tab_observer.cc b/chrome/browser/safe_browsing/safe_browsing_tab_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f4daa6e26adb5c0194c9d239aa081dccda055379
--- /dev/null
+++ b/chrome/browser/safe_browsing/safe_browsing_tab_observer.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2011 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/safe_browsing/safe_browsing_tab_observer.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/client_side_detection_host.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/render_messages.h"
+#include "content/browser/renderer_host/render_view_host.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_source.h"
+
+namespace safe_browsing {
+
+SafeBrowsingTabObserver::SafeBrowsingTabObserver(
+ TabContentsWrapper* wrapper) : wrapper_(wrapper) {
+#if defined(ENABLE_SAFE_BROWSING)
+ PrefService* prefs = wrapper_->profile()->GetPrefs();
+ if (prefs) {
+ pref_change_registrar_.Init(prefs);
+ pref_change_registrar_.Add(prefs::kSafeBrowsingEnabled, this);
+
+ if (prefs->GetBoolean(prefs::kSafeBrowsingEnabled) &&
+ g_browser_process->safe_browsing_detection_service()) {
+ safebrowsing_detection_host_.reset(
+ ClientSideDetectionHost::Create(wrapper_->tab_contents()));
+ }
+ }
+#endif
+}
+
+SafeBrowsingTabObserver::~SafeBrowsingTabObserver() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// content::NotificationObserver overrides
+
+void SafeBrowsingTabObserver::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_PREF_CHANGED: {
+ std::string* pref_name = content::Details<std::string>(details).ptr();
+ DCHECK(content::Source<PrefService>(source).ptr() ==
+ wrapper_->profile()->GetPrefs());
+ if (*pref_name == prefs::kSafeBrowsingEnabled) {
+ UpdateSafebrowsingDetectionHost();
+ } else {
+ NOTREACHED() << "unexpected pref change notification" << *pref_name;
+ }
+ break;
+ }
+ default:
+ NOTREACHED();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Internal helpers
+
+void SafeBrowsingTabObserver::UpdateSafebrowsingDetectionHost() {
+#if defined(ENABLE_SAFE_BROWSING)
+ PrefService* prefs = wrapper_->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(
+ ClientSideDetectionHost::Create(wrapper_->tab_contents()));
+ }
+ } else {
+ safebrowsing_detection_host_.reset();
+ }
+
+ RenderViewHost* rvh = wrapper_->tab_contents()->render_view_host();
+ rvh->Send(new ChromeViewMsg_SetClientSidePhishingDetection(rvh->routing_id(),
+ safe_browsing));
+#endif
+}
+
+} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698