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

Side by Side Diff: chrome/browser/privacy_blacklist/blacklist_ui.cc

Issue 501082: Implement delaying resource requests until privacy blacklists are ready. (Closed)
Patch Set: don't get stuck on errors Created 10 years, 11 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/privacy_blacklist/blacklist_ui.h" 5 #include "chrome/browser/privacy_blacklist/blacklist_ui.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "chrome/browser/blocked_popup_container.h" 10 #include "chrome/browser/blocked_popup_container.h"
11 #include "chrome/browser/chrome_thread.h" 11 #include "chrome/browser/chrome_thread.h"
12 #include "chrome/browser/privacy_blacklist/blacklist.h" 12 #include "chrome/browser/privacy_blacklist/blacklist.h"
13 #include "chrome/browser/privacy_blacklist/blacklist_manager.h"
14 #include "chrome/browser/privacy_blacklist/blacklist_request_info.h"
13 #include "chrome/browser/renderer_host/render_view_host.h" 15 #include "chrome/browser/renderer_host/render_view_host.h"
14 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 16 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
15 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" 17 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
16 #include "chrome/browser/tab_contents/tab_contents.h" 18 #include "chrome/browser/tab_contents/tab_contents.h"
17 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
18 20
19 // Displays more info why some content has been blocked. 21 // Displays more info why some content has been blocked.
20 class DisplayBlockedContentNoticeTask : public Task { 22 class DisplayBlockedContentNoticeTask : public Task {
21 public: 23 public:
22 DisplayBlockedContentNoticeTask(const GURL& gurl, 24 DisplayBlockedContentNoticeTask(const GURL& url,
23 const Blacklist::Match* match, 25 const Blacklist::Match* match,
24 const ResourceDispatcherHostRequestInfo* info) 26 const ResourceDispatcherHostRequestInfo* info)
25 : gurl_(gurl), 27 : url_(url),
26 match_(match),
27 child_id_(info->child_id()), 28 child_id_(info->child_id()),
28 route_id_(info->route_id()) { 29 route_id_(info->route_id()) {
30 if (match->attributes() & Blacklist::kDontStoreCookies) {
31 // No cookies stored.
32 details_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
33 } else if (match->attributes() & Blacklist::kDontSendCookies) {
34 // No cookies sent.
35 details_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
36 } else if (match->attributes() & Blacklist::kDontSendReferrer) {
37 // No referrer sent.
38 details_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_REFERRER);
39 } else {
40 NOTREACHED();
41 }
29 } 42 }
30 43
31 virtual void Run() { 44 virtual void Run() {
32 RenderViewHost* view = RenderViewHost::FromID(child_id_, route_id_); 45 RenderViewHost* view = RenderViewHost::FromID(child_id_, route_id_);
33 if (!view) 46 if (!view)
34 return; // The view may be gone by the time we get here. 47 return; // The view may be gone by the time we get here.
35 48
36 string16 reason; 49 view->delegate()->AddBlockedNotice(url_, details_);
37 if (match_->attributes() & Blacklist::kDontStoreCookies) {
38 // No cookies stored.
39 reason = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
40 } else if (match_->attributes() & Blacklist::kDontSendCookies) {
41 // No cookies sent.
42 reason = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES);
43 } else if (match_->attributes() & Blacklist::kDontSendReferrer) {
44 // No referrer sent.
45 reason = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_REFERRER);
46 } else {
47 NOTREACHED();
48 }
49
50 view->delegate()->AddBlockedNotice(gurl_, reason);
51 } 50 }
52 51
53 private: 52 private:
54 const GURL gurl_; 53 // URL for which we blocked content.
55 const Blacklist::Match* match_; 54 const GURL url_;
55
56 // More detailed info what has been blocked.
57 string16 details_;
58
59 // Information that allows us to identify the right tab to display the notice.
56 const int child_id_; 60 const int child_id_;
57 const int route_id_; 61 const int route_id_;
58 62
59 DISALLOW_COPY_AND_ASSIGN(DisplayBlockedContentNoticeTask); 63 DISALLOW_COPY_AND_ASSIGN(DisplayBlockedContentNoticeTask);
60 }; 64 };
61 65
62 // static 66 // static
63 void BlacklistUI::OnNonvisualContentBlocked(const URLRequest* request) { 67 void BlacklistUI::OnNonvisualContentBlocked(const URLRequest* request) {
64 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 68 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
65 69
66 const URLRequest::UserData* d = 70 BlacklistRequestInfo* request_info =
67 request->GetUserData(&Blacklist::kRequestDataKey); 71 BlacklistRequestInfo::FromURLRequest(request);
68 const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d); 72 const BlacklistManager* blacklist_manager =
73 request_info->GetBlacklistManager();
74 const Blacklist* blacklist = blacklist_manager->GetCompiledBlacklist();
75 scoped_ptr<Blacklist::Match> match(blacklist->findMatch(request->url()));
69 const ResourceDispatcherHostRequestInfo* info = 76 const ResourceDispatcherHostRequestInfo* info =
70 ResourceDispatcherHost::InfoForRequest(request); 77 ResourceDispatcherHost::InfoForRequest(request);
71 const GURL& gurl = request->url();
72 78
73 // Notify the UI that something non-visual has been blocked. 79 // Notify the UI that something non-visual has been blocked.
74 ChromeThread::PostTask( 80 ChromeThread::PostTask(
75 ChromeThread::UI, FROM_HERE, 81 ChromeThread::UI, FROM_HERE,
76 new DisplayBlockedContentNoticeTask(gurl, match, info)); 82 new DisplayBlockedContentNoticeTask(request->url(), match.get(), info));
77 } 83 }
OLDNEW
« no previous file with comments | « chrome/browser/privacy_blacklist/blacklist_test_util.cc ('k') | chrome/browser/privacy_blacklist/blocked_response.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698