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

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

Issue 1509073002: Fixes for Safe Browsing with unrelated pending navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implementation of the SafeBrowsingBlockingPage class. 5 // Implementation of the SafeBrowsingBlockingPage class.
6 6
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
32 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
33 #include "chrome/grit/generated_resources.h" 33 #include "chrome/grit/generated_resources.h"
34 #include "chrome/grit/locale_settings.h" 34 #include "chrome/grit/locale_settings.h"
35 #include "components/google/core/browser/google_util.h" 35 #include "components/google/core/browser/google_util.h"
36 #include "components/security_interstitials/core/controller_client.h" 36 #include "components/security_interstitials/core/controller_client.h"
37 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/interstitial_page.h" 38 #include "content/public/browser/interstitial_page.h"
39 #include "content/public/browser/navigation_controller.h" 39 #include "content/public/browser/navigation_controller.h"
40 #include "content/public/browser/navigation_entry.h"
40 #include "content/public/browser/user_metrics.h" 41 #include "content/public/browser/user_metrics.h"
41 #include "content/public/browser/web_contents.h" 42 #include "content/public/browser/web_contents.h"
42 #include "content/public/common/renderer_preferences.h" 43 #include "content/public/common/renderer_preferences.h"
43 #include "grit/browser_resources.h" 44 #include "grit/browser_resources.h"
44 #include "net/base/escape.h" 45 #include "net/base/escape.h"
45 #include "ui/base/l10n/l10n_util.h" 46 #include "ui/base/l10n/l10n_util.h"
46 47
47 using base::UserMetricsAction; 48 using base::UserMetricsAction;
48 using content::BrowserThread; 49 using content::BrowserThread;
49 using content::InterstitialPage; 50 using content::InterstitialPage;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; 103 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL;
103 104
104 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we 105 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we
105 // don't leak it. 106 // don't leak it.
106 class SafeBrowsingBlockingPageFactoryImpl 107 class SafeBrowsingBlockingPageFactoryImpl
107 : public SafeBrowsingBlockingPageFactory { 108 : public SafeBrowsingBlockingPageFactory {
108 public: 109 public:
109 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( 110 SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
110 SafeBrowsingUIManager* ui_manager, 111 SafeBrowsingUIManager* ui_manager,
111 WebContents* web_contents, 112 WebContents* web_contents,
112 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) 113 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources,
113 override { 114 const GURL& main_frame_url) override {
114 return new SafeBrowsingBlockingPage(ui_manager, web_contents, 115 return new SafeBrowsingBlockingPage(ui_manager, web_contents,
115 unsafe_resources); 116 unsafe_resources, main_frame_url);
116 } 117 }
117 118
118 private: 119 private:
119 friend struct base::DefaultLazyInstanceTraits< 120 friend struct base::DefaultLazyInstanceTraits<
120 SafeBrowsingBlockingPageFactoryImpl>; 121 SafeBrowsingBlockingPageFactoryImpl>;
121 122
122 SafeBrowsingBlockingPageFactoryImpl() { } 123 SafeBrowsingBlockingPageFactoryImpl() { }
123 124
124 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl); 125 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl);
125 }; 126 };
126 127
127 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl> 128 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl>
128 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER; 129 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER;
129 130
130 // static 131 // static
131 content::InterstitialPageDelegate::TypeID 132 content::InterstitialPageDelegate::TypeID
132 SafeBrowsingBlockingPage::kTypeForTesting = 133 SafeBrowsingBlockingPage::kTypeForTesting =
133 &SafeBrowsingBlockingPage::kTypeForTesting; 134 &SafeBrowsingBlockingPage::kTypeForTesting;
134 135
135 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( 136 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
136 SafeBrowsingUIManager* ui_manager, 137 SafeBrowsingUIManager* ui_manager,
137 WebContents* web_contents, 138 WebContents* web_contents,
138 const UnsafeResourceList& unsafe_resources) 139 const UnsafeResourceList& unsafe_resources,
140 const GURL& main_frame_url)
139 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url), 141 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url),
140 malware_details_proceed_delay_ms_( 142 malware_details_proceed_delay_ms_(
141 kMalwareDetailsProceedDelayMilliSeconds), 143 kMalwareDetailsProceedDelayMilliSeconds),
142 ui_manager_(ui_manager), 144 ui_manager_(ui_manager),
143 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), 145 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)),
146 main_frame_url_(main_frame_url),
Charlie Reis 2015/12/11 05:39:24 Any reason main_frame_url_ is listed before unsafe
mattm 2015/12/15 01:42:25 Not particularly. I wanted to keep main_frame_url_
144 unsafe_resources_(unsafe_resources), 147 unsafe_resources_(unsafe_resources),
145 proceeded_(false) { 148 proceeded_(false) {
146 bool malware = false; 149 bool malware = false;
147 bool harmful = false; 150 bool harmful = false;
148 bool phishing = false; 151 bool phishing = false;
149 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin(); 152 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin();
150 iter != unsafe_resources_.end(); ++iter) { 153 iter != unsafe_resources_.end(); ++iter) {
151 const UnsafeResource& resource = *iter; 154 const UnsafeResource& resource = *iter;
152 SBThreatType threat_type = resource.threat_type; 155 SBThreatType threat_type = resource.threat_type;
153 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || 156 if (threat_type == SB_THREAT_TYPE_URL_MALWARE ||
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 SBThreatType threat_type) { 216 SBThreatType threat_type) {
214 return threat_type == SB_THREAT_TYPE_URL_PHISHING || 217 return threat_type == SB_THREAT_TYPE_URL_PHISHING ||
215 threat_type == SB_THREAT_TYPE_URL_MALWARE || 218 threat_type == SB_THREAT_TYPE_URL_MALWARE ||
216 threat_type == SB_THREAT_TYPE_URL_UNWANTED || 219 threat_type == SB_THREAT_TYPE_URL_UNWANTED ||
217 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || 220 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL ||
218 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; 221 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL;
219 } 222 }
220 223
221 bool SafeBrowsingBlockingPage::CanShowThreatDetailsOption() { 224 bool SafeBrowsingBlockingPage::CanShowThreatDetailsOption() {
222 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && 225 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() &&
223 web_contents()->GetURL().SchemeIs(url::kHttpScheme) && 226 main_frame_url_.SchemeIs(url::kHttpScheme) &&
224 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); 227 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed));
225 } 228 }
226 229
227 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { 230 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() {
228 } 231 }
229 232
230 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) { 233 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) {
231 if (page_cmd == "\"pageLoadComplete\"") { 234 if (page_cmd == "\"pageLoadComplete\"") {
232 // content::WaitForRenderFrameReady sends this message when the page 235 // content::WaitForRenderFrameReady sends this message when the page
233 // load completes. Ignore it. 236 // load completes. Ignore it.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 371
369 // Check to see if some new notifications of unsafe resources have been 372 // Check to see if some new notifications of unsafe resources have been
370 // received while we were showing the interstitial. 373 // received while we were showing the interstitial.
371 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); 374 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
372 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); 375 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
373 SafeBrowsingBlockingPage* blocking_page = NULL; 376 SafeBrowsingBlockingPage* blocking_page = NULL;
374 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { 377 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
375 // Build an interstitial for all the unsafe resources notifications. 378 // Build an interstitial for all the unsafe resources notifications.
376 // Don't show it now as showing an interstitial while an interstitial is 379 // Don't show it now as showing an interstitial while an interstitial is
377 // already showing would cause DontProceed() to be invoked. 380 // already showing would cause DontProceed() to be invoked.
378 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_, 381 blocking_page = factory_->CreateSafeBrowsingPage(
379 web_contents(), 382 ui_manager_, web_contents(), iter->second,
380 iter->second); 383 // All queued unsafe resources should be for the same page:
384 iter->second[0].GetNavigationEntryForResource()->GetURL());
381 unsafe_resource_map->erase(iter); 385 unsafe_resource_map->erase(iter);
382 } 386 }
383 387
384 // Now that this interstitial is gone, we can show the new one. 388 // Now that this interstitial is gone, we can show the new one.
385 if (blocking_page) 389 if (blocking_page)
386 blocking_page->Show(); 390 blocking_page->Show();
387 } 391 }
388 392
389 content::InterstitialPageDelegate::TypeID 393 content::InterstitialPageDelegate::TypeID
390 SafeBrowsingBlockingPage::GetTypeForTesting() const { 394 SafeBrowsingBlockingPage::GetTypeForTesting() const {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // static 466 // static
463 SafeBrowsingBlockingPage::UnsafeResourceMap* 467 SafeBrowsingBlockingPage::UnsafeResourceMap*
464 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() { 468 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() {
465 return g_unsafe_resource_map.Pointer(); 469 return g_unsafe_resource_map.Pointer();
466 } 470 }
467 471
468 // static 472 // static
469 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage( 473 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage(
470 SafeBrowsingUIManager* ui_manager, 474 SafeBrowsingUIManager* ui_manager,
471 WebContents* web_contents, 475 WebContents* web_contents,
472 const UnsafeResource& unsafe_resource) { 476 const UnsafeResource& unsafe_resource,
477 const GURL& main_frame_url) {
473 std::vector<UnsafeResource> resources; 478 std::vector<UnsafeResource> resources;
474 resources.push_back(unsafe_resource); 479 resources.push_back(unsafe_resource);
475 // Set up the factory if this has not been done already (tests do that 480 // Set up the factory if this has not been done already (tests do that
476 // before this method is called). 481 // before this method is called).
477 if (!factory_) 482 if (!factory_)
478 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer(); 483 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer();
479 return factory_->CreateSafeBrowsingPage(ui_manager, web_contents, resources); 484 return factory_->CreateSafeBrowsingPage(ui_manager, web_contents, resources,
485 main_frame_url);
480 } 486 }
481 487
482 // static 488 // static
483 void SafeBrowsingBlockingPage::ShowBlockingPage( 489 void SafeBrowsingBlockingPage::ShowBlockingPage(
484 SafeBrowsingUIManager* ui_manager, 490 SafeBrowsingUIManager* ui_manager,
485 const UnsafeResource& unsafe_resource) { 491 const UnsafeResource& unsafe_resource) {
486 DVLOG(1) << __FUNCTION__ << " " << unsafe_resource.url.spec(); 492 DVLOG(1) << __FUNCTION__ << " " << unsafe_resource.url.spec();
487 WebContents* web_contents = tab_util::GetWebContentsByID( 493 WebContents* web_contents = tab_util::GetWebContentsByID(
488 unsafe_resource.render_process_host_id, unsafe_resource.render_view_id); 494 unsafe_resource.render_process_host_id, unsafe_resource.render_view_id);
489 495
490 InterstitialPage* interstitial = 496 InterstitialPage* interstitial =
491 InterstitialPage::GetInterstitialPage(web_contents); 497 InterstitialPage::GetInterstitialPage(web_contents);
492 if (interstitial && !unsafe_resource.is_subresource) { 498 if (interstitial && !unsafe_resource.is_subresource) {
493 // There is already an interstitial showing and we are about to display a 499 // There is already an interstitial showing and we are about to display a
494 // new one for the main frame. Just hide the current one, it is now 500 // new one for the main frame. Just hide the current one, it is now
495 // irrelevent 501 // irrelevent
496 interstitial->DontProceed(); 502 interstitial->DontProceed();
497 interstitial = NULL; 503 interstitial = NULL;
498 } 504 }
499 505
500 if (!interstitial) { 506 if (!interstitial) {
501 // There are no interstitial currently showing in that tab, go ahead and 507 // There are no interstitial currently showing in that tab, go ahead and
502 // show this interstitial. 508 // show this interstitial.
503 SafeBrowsingBlockingPage* blocking_page = 509 SafeBrowsingBlockingPage* blocking_page = CreateBlockingPage(
504 CreateBlockingPage(ui_manager, web_contents, unsafe_resource); 510 ui_manager, web_contents, unsafe_resource,
511 unsafe_resource.GetNavigationEntryForResource()->GetURL());
505 blocking_page->Show(); 512 blocking_page->Show();
506 return; 513 return;
507 } 514 }
508 515
509 // This is an interstitial for a page's resource, let's queue it. 516 // This is an interstitial for a page's resource, let's queue it.
510 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); 517 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
511 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); 518 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource);
512 } 519 }
513 520
514 // static 521 // static
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 IDS_MALWARE_V3_PRIMARY_PARAGRAPH, 652 IDS_MALWARE_V3_PRIMARY_PARAGRAPH,
646 GetFormattedHostName())); 653 GetFormattedHostName()));
647 load_time_data->SetString( 654 load_time_data->SetString(
648 "explanationParagraph", 655 "explanationParagraph",
649 is_main_frame_load_blocked_ ? 656 is_main_frame_load_blocked_ ?
650 l10n_util::GetStringFUTF16( 657 l10n_util::GetStringFUTF16(
651 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH, 658 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH,
652 GetFormattedHostName()) : 659 GetFormattedHostName()) :
653 l10n_util::GetStringFUTF16( 660 l10n_util::GetStringFUTF16(
654 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE, 661 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE,
655 base::UTF8ToUTF16(web_contents()->GetURL().host()), 662 base::UTF8ToUTF16(main_frame_url_.host()),
656 GetFormattedHostName())); 663 GetFormattedHostName()));
657 load_time_data->SetString( 664 load_time_data->SetString(
658 "finalParagraph", 665 "finalParagraph",
659 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH)); 666 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH));
660 667
661 PopulateExtendedReportingOption(load_time_data); 668 PopulateExtendedReportingOption(load_time_data);
662 } 669 }
663 670
664 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData( 671 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData(
665 base::DictionaryValue* load_time_data) { 672 base::DictionaryValue* load_time_data) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 } else { 719 } else {
713 load_time_data->SetString( 720 load_time_data->SetString(
714 "finalParagraph", 721 "finalParagraph",
715 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); 722 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH));
716 } 723 }
717 724
718 PopulateExtendedReportingOption(load_time_data); 725 PopulateExtendedReportingOption(load_time_data);
719 } 726 }
720 727
721 } // namespace safe_browsing 728 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698