| OLD | NEW |
| 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_observer.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/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
| 14 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 14 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 15 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" | 15 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 16 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
| 17 #include "chrome/common/notification_details.h" | |
| 18 #include "chrome/common/notification_service.h" | |
| 19 #include "chrome/common/notification_type.h" | |
| 20 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 21 | 18 |
| 22 class BlockedContentNotice : public Task { | 19 // Displays more info why some content has been blocked. |
| 20 class DisplayBlockedContentNoticeTask : public Task { |
| 23 public: | 21 public: |
| 24 BlockedContentNotice(const GURL& gurl, | 22 DisplayBlockedContentNoticeTask(const GURL& gurl, |
| 25 const Blacklist::Match* match, | 23 const Blacklist::Match* match, |
| 26 const ResourceDispatcherHostRequestInfo* info) | 24 const ResourceDispatcherHostRequestInfo* info) |
| 27 : gurl_(gurl), | 25 : gurl_(gurl), |
| 28 match_(match), | 26 match_(match), |
| 29 child_id_(info->child_id()), | 27 child_id_(info->child_id()), |
| 30 route_id_(info->route_id()) { | 28 route_id_(info->route_id()) { |
| 31 if (match_->attributes() & Blacklist::kDontStoreCookies) { | |
| 32 // No cookies stored. | |
| 33 reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES); | |
| 34 } else if (match_->attributes() & Blacklist::kDontSendCookies) { | |
| 35 // No cookies sent. | |
| 36 reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_COOKIES); | |
| 37 } else if (match_->attributes() & Blacklist::kDontSendReferrer) { | |
| 38 // No referrer sent. | |
| 39 reason_ = l10n_util::GetStringUTF16(IDS_BLACKLIST_BLOCKED_REFERRER); | |
| 40 } | |
| 41 } | 29 } |
| 42 | 30 |
| 43 virtual void Run() { | 31 virtual void Run() { |
| 44 RenderViewHost* view = RenderViewHost::FromID(child_id_, route_id_); | 32 RenderViewHost* view = RenderViewHost::FromID(child_id_, route_id_); |
| 45 if (!view) | 33 if (!view) |
| 46 return; // The view may be gone by the time we get here. | 34 return; // The view may be gone by the time we get here. |
| 47 | 35 |
| 48 view->delegate()->AddBlockedNotice(gurl_, reason_); | 36 string16 reason; |
| 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); |
| 49 } | 51 } |
| 50 | 52 |
| 51 private: | 53 private: |
| 52 const GURL gurl_; | 54 const GURL gurl_; |
| 53 const Blacklist::Match* match_; | 55 const Blacklist::Match* match_; |
| 54 const int child_id_; | 56 const int child_id_; |
| 55 const int route_id_; | 57 const int route_id_; |
| 56 | 58 |
| 57 string16 reason_; | 59 DISALLOW_COPY_AND_ASSIGN(DisplayBlockedContentNoticeTask); |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 void BlacklistObserver::ContentBlocked(const URLRequest* request) { | 62 // static |
| 63 void BlacklistUI::OnNonvisualContentBlocked(const URLRequest* request) { |
| 64 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 65 |
| 61 const URLRequest::UserData* d = | 66 const URLRequest::UserData* d = |
| 62 request->GetUserData(&Blacklist::kRequestDataKey); | 67 request->GetUserData(&Blacklist::kRequestDataKey); |
| 63 const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d); | 68 const Blacklist::Match* match = static_cast<const Blacklist::Match*>(d); |
| 64 const ResourceDispatcherHostRequestInfo* info = | 69 const ResourceDispatcherHostRequestInfo* info = |
| 65 ResourceDispatcherHost::InfoForRequest(request); | 70 ResourceDispatcherHost::InfoForRequest(request); |
| 66 const GURL& gurl = request->url(); | 71 const GURL& gurl = request->url(); |
| 67 | 72 |
| 68 // Notify the UI that something non-visual has been blocked. | 73 // Notify the UI that something non-visual has been blocked. |
| 69 ChromeThread::PostTask( | 74 ChromeThread::PostTask( |
| 70 ChromeThread::UI, FROM_HERE, | 75 ChromeThread::UI, FROM_HERE, |
| 71 new BlockedContentNotice(gurl, match, info)); | 76 new DisplayBlockedContentNoticeTask(gurl, match, info)); |
| 72 } | 77 } |
| OLD | NEW |