summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoridanan@chromium.org <idanan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-21 17:47:08 +0000
committeridanan@chromium.org <idanan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-21 17:47:08 +0000
commit3e7cf136004dd8f5a8e521360b5d602e7b1af0c2 (patch)
tree3f78cab4b9f030786bfb0224e479282770c46d24
parent7ed6bc6bcd311741da22bf45d8a88f5de89eadf8 (diff)
downloadchromium_src-3e7cf136004dd8f5a8e521360b5d602e7b1af0c2.zip
chromium_src-3e7cf136004dd8f5a8e521360b5d602e7b1af0c2.tar.gz
chromium_src-3e7cf136004dd8f5a8e521360b5d602e7b1af0c2.tar.bz2
Send notice for blackisted non-visual resources
This is just the piping to call into the blocked_popup_container (which shall be later renamed and expanded to a generalized blocked resource container) from the browser's request context. BUG=16932 TEST=none Review URL: http://codereview.chromium.org/171109 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23973 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/browser/blocked_popup_container.cc5
-rw-r--r--chrome/browser/blocked_popup_container.h6
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc13
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_observer.cc73
-rw-r--r--chrome/browser/privacy_blacklist/blacklist_observer.h21
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.cc4
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h3
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc5
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc5
-rw-r--r--chrome/browser/tab_contents/tab_contents.h1
-rw-r--r--chrome/chrome.gyp2
-rw-r--r--chrome/common/notification_type.h5
13 files changed, 148 insertions, 1 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 06b308b..d9354ca 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -4817,6 +4817,12 @@ each locale. -->
<message name="IDS_BLACKLIST_UNBLOCK" desc="Prompt to unblock a blacklisted element.">
Click to unblock
</message>
+ <message name="IDS_BLACKLIST_BLOCKED_COOKIES" desc="Cookies was blacklisted.">
+ Cookies not sent
+ </message>
+ <message name="IDS_BLACKLIST_BLOCKED_REFERRER" desc="Referrer sending was blacklisted.">
+ Referrer not sent
+ </message>
<!-- ProcessSingleton -->
<message name="IDS_PROFILE_IN_USE_LINUX" desc="Message shown when the browser cannot start because the profile is in use on a different host.">
diff --git a/chrome/browser/blocked_popup_container.cc b/chrome/browser/blocked_popup_container.cc
index 13bd6a7..4df5bef 100644
--- a/chrome/browser/blocked_popup_container.cc
+++ b/chrome/browser/blocked_popup_container.cc
@@ -105,6 +105,11 @@ void BlockedPopupContainer::LaunchPopupAtIndex(size_t index) {
EraseDataForPopupAndUpdateUI(i);
}
+void BlockedPopupContainer::AddBlockedNotice(const GURL& url,
+ const string16& reason) {
+ // TODO(idanan): Implement this. See header for description.
+}
+
size_t BlockedPopupContainer::GetBlockedPopupCount() const {
return blocked_popups_.size();
}
diff --git a/chrome/browser/blocked_popup_container.h b/chrome/browser/blocked_popup_container.h
index ebffd23..d7e5d0e 100644
--- a/chrome/browser/blocked_popup_container.h
+++ b/chrome/browser/blocked_popup_container.h
@@ -7,6 +7,8 @@
// TabContents should use the appropriate methods on TabContents to access
// information about blocked popups.
+// TODO(idanan): Rename class to BlockedContentContainer.
+
#ifndef CHROME_BROWSER_BLOCKED_POPUP_CONTAINER_H_
#define CHROME_BROWSER_BLOCKED_POPUP_CONTAINER_H_
@@ -17,6 +19,7 @@
#include "base/gfx/native_widget_types.h"
#include "base/gfx/rect.h"
+#include "base/string16.h"
#include "chrome/browser/tab_contents/constrained_window.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/common/notification_registrar.h"
@@ -100,6 +103,9 @@ class BlockedPopupContainer : public TabContentsDelegate,
// Returns the number of blocked popups
size_t GetBlockedPopupCount() const;
+ // Adds a blocked notice if one is not already there for the same host.
+ void AddBlockedNotice(const GURL& url, const string16& reason);
+
// Returns true if host |index| is whitelisted. Returns false if |index| is
// invalid.
bool IsHostWhitelisted(size_t index) const;
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 0aa4fc8..a36887c 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -450,6 +450,11 @@ bool ChromeURLRequestContext::InterceptCookie(const URLRequest* request,
if (d) {
const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d);
if (match->attributes() & Blacklist::kDontStoreCookies) {
+ NotificationService::current()->Notify(
+ NotificationType::BLACKLIST_BLOCKED_RESOURCE,
+ Source<const ChromeURLRequestContext>(this),
+ Details<const URLRequest>(request));
+
cookie->clear();
return false;
}
@@ -466,8 +471,14 @@ bool ChromeURLRequestContext::AllowSendingCookies(const URLRequest* request)
request->GetUserData(&Blacklist::kRequestDataKey);
if (d) {
const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d);
- if (match->attributes() & Blacklist::kDontSendCookies)
+ if (match->attributes() & Blacklist::kDontSendCookies) {
+ NotificationService::current()->Notify(
+ NotificationType::BLACKLIST_BLOCKED_RESOURCE,
+ Source<const ChromeURLRequestContext>(this),
+ Details<const URLRequest>(request));
+
return false;
+ }
}
return true;
}
diff --git a/chrome/browser/privacy_blacklist/blacklist_observer.cc b/chrome/browser/privacy_blacklist/blacklist_observer.cc
new file mode 100644
index 0000000..d93dbfe
--- /dev/null
+++ b/chrome/browser/privacy_blacklist/blacklist_observer.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2009 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/privacy_blacklist/blacklist_observer.h"
+
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "base/string16.h"
+#include "chrome/browser/blocked_popup_container.h"
+#include "chrome/browser/privacy_blacklist/blacklist.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_type.h"
+#include "grit/generated_resources.h"
+
+class BlockedContentNotice : public Task {
+ public:
+ BlockedContentNotice(const GURL& gurl,
+ const Blacklist::Match* match,
+ const ResourceDispatcherHost::ExtraRequestInfo* info)
+ : gurl_(gurl),
+ match_(match),
+ process_id_(info->process_id),
+ route_id_(info->route_id) {
+ if (match_->attributes() & Blacklist::kDontStoreCookies) {
+ // No cookies stored.
+ reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
+ } else if (match_->attributes() & Blacklist::kDontSendCookies) {
+ // No cookies sent.
+ reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
+ } else if (match_->attributes() & Blacklist::kDontSendReferrer) {
+ // No referrer sent.
+ reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_REFERRER);
+ }
+ }
+
+ virtual void Run() {
+ RenderViewHost* view = RenderViewHost::FromID(process_id_, route_id_);
+ if (!view)
+ return; // The view may be gone by the time we get here.
+
+ view->delegate()->AddBlockedNotice(gurl_, reason_);
+ }
+
+ private:
+ const GURL gurl_;
+ const Blacklist::Match* match_;
+ const int process_id_;
+ const int route_id_;
+
+ string16 reason_;
+};
+
+void BlacklistObserver::ContentBlocked(const URLRequest* request) {
+ const URLRequest::UserData* d =
+ request->GetUserData(&Blacklist::kRequestDataKey);
+ const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d);
+ const ResourceDispatcherHost::ExtraRequestInfo* info =
+ static_cast<const ResourceDispatcherHost::ExtraRequestInfo*>(
+ request->GetUserData(NULL));
+ const GURL& gurl = request->url();
+ BlockedContentNotice* task = new BlockedContentNotice(gurl, match, info);
+
+ // Notify the UI that something non-visual has been blocked. We can
+ // safely cast the delegate to the ResourceDispatherHost because it
+ // is the only place where Blacklist::Match data is added to requests.
+ static_cast<ResourceDispatcherHost*>(request->delegate())->
+ ui_loop()->PostTask(FROM_HERE, task);
+}
diff --git a/chrome/browser/privacy_blacklist/blacklist_observer.h b/chrome/browser/privacy_blacklist/blacklist_observer.h
new file mode 100644
index 0000000..196c658
--- /dev/null
+++ b/chrome/browser/privacy_blacklist/blacklist_observer.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_OBSERVER_H_
+#define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_OBSERVER_H_
+
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_type.h"
+
+class URLRequest;
+
+class BlacklistObserver {
+ public:
+ // Called when non-visual content is blocked by the privacy blacklist.
+ static void ContentBlocked(const URLRequest* request);
+};
+
+#endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_OBSERVER_H_
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.cc b/chrome/browser/renderer_host/render_view_host_delegate.cc
index 1afbdac..a97431c 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.cc
+++ b/chrome/browser/renderer_host/render_view_host_delegate.cc
@@ -55,6 +55,10 @@ TabContents* RenderViewHostDelegate::GetAsTabContents() {
return NULL;
}
+void RenderViewHostDelegate::AddBlockedNotice(const GURL& url,
+ const string16& reason) {
+}
+
GURL RenderViewHostDelegate::GetAlternateErrorPageURL() const {
return GURL();
}
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index d9a7d9c..2727879 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -374,6 +374,9 @@ class RenderViewHostDelegate {
// not a TabContents, returns NULL.
virtual TabContents* GetAsTabContents();
+ // Adds a notice that something was blocked.
+ virtual void AddBlockedNotice(const GURL& url, const string16& reason);
+
// Return id number of browser window which this object is attached to. If no
// browser window is attached to, just return -1.
virtual int GetBrowserWindowID() const = 0;
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 7ba1a47..4ab489f 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/privacy_blacklist/blacklist.h"
+#include "chrome/browser/privacy_blacklist/blacklist_observer.h"
#include "chrome/browser/renderer_host/audio_renderer_host.h"
#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "chrome/browser/renderer_host/database_dispatcher_host.h"
@@ -203,6 +204,8 @@ void ResourceMessageFilter::OnFilterAdded(IPC::Channel* channel) {
// Add the observers to intercept.
registrar_.Add(this, NotificationType::SPELLCHECKER_REINITIALIZED,
Source<Profile>(static_cast<Profile*>(profile_)));
+ registrar_.Add(this, NotificationType::BLACKLIST_BLOCKED_RESOURCE,
+ NotificationService::AllSources());
}
// Called on the IPC thread:
@@ -880,6 +883,8 @@ void ResourceMessageFilter::Observe(NotificationType type,
if (type == NotificationType::SPELLCHECKER_REINITIALIZED) {
spellchecker_ = Details<SpellcheckerReinitializedDetails>
(details).ptr()->spellchecker;
+ } else if (type == NotificationType::BLACKLIST_BLOCKED_RESOURCE) {
+ BlacklistObserver::ContentBlocked(Details<const URLRequest>(details).ptr());
}
}
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 18880c1..3fdce1d 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -1805,6 +1805,11 @@ TabContents* TabContents::GetAsTabContents() {
return this;
}
+void TabContents::AddBlockedNotice(const GURL& url, const string16& reason) {
+ CreateBlockedPopupContainerIfNecessary();
+ blocked_popups_->AddBlockedNotice(url, reason);
+}
+
ViewType::Type TabContents::GetRenderViewType() const {
return ViewType::TAB_CONTENTS;
}
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 22a51c5..7e86dc4 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -806,6 +806,7 @@ class TabContents : public PageNavigator,
virtual RenderViewHostDelegate::FavIcon* GetFavIconDelegate();
virtual RenderViewHostDelegate::Autofill* GetAutofillDelegate();
virtual TabContents* GetAsTabContents();
+ virtual void AddBlockedNotice(const GURL& url, const string16& reason);
virtual ViewType::Type GetRenderViewType() const;
virtual int GetBrowserWindowID() const;
virtual void RenderViewCreated(RenderViewHost* render_view_host);
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index a833360..0da33bb 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -1533,6 +1533,8 @@
'browser/privacy_blacklist/blacklist.cc',
'browser/privacy_blacklist/blacklist_io.h',
'browser/privacy_blacklist/blacklist_io.cc',
+ 'browser/privacy_blacklist/blacklist_observer.h',
+ 'browser/privacy_blacklist/blacklist_observer.cc',
'browser/privacy_blacklist/blacklist_store.h',
'browser/privacy_blacklist/blacklist_store.cc',
'browser/privacy_blacklist/blocked_response.h',
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index 8d98578..8cde6bf 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -650,6 +650,11 @@ class NotificationType {
EXTENSION_TEST_PASSED,
EXTENSION_TEST_FAILED,
+ // Privacy Blacklist -------------------------------------------------------
+
+ // Sent by the resource dispatcher host when a resource is blocked.
+ BLACKLIST_BLOCKED_RESOURCE,
+
// Debugging ---------------------------------------------------------------
// Count (must be last) ----------------------------------------------------