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

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: review changes for comment #10 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,
113 const GURL& main_frame_url,
112 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) 114 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources)
113 override { 115 override {
114 return new SafeBrowsingBlockingPage(ui_manager, web_contents, 116 return new SafeBrowsingBlockingPage(ui_manager, web_contents,
115 unsafe_resources); 117 main_frame_url, unsafe_resources);
116 } 118 }
117 119
118 private: 120 private:
119 friend struct base::DefaultLazyInstanceTraits< 121 friend struct base::DefaultLazyInstanceTraits<
120 SafeBrowsingBlockingPageFactoryImpl>; 122 SafeBrowsingBlockingPageFactoryImpl>;
121 123
122 SafeBrowsingBlockingPageFactoryImpl() { } 124 SafeBrowsingBlockingPageFactoryImpl() { }
123 125
124 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl); 126 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl);
125 }; 127 };
126 128
127 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl> 129 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl>
128 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER; 130 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER;
129 131
130 // static 132 // static
131 content::InterstitialPageDelegate::TypeID 133 content::InterstitialPageDelegate::TypeID
132 SafeBrowsingBlockingPage::kTypeForTesting = 134 SafeBrowsingBlockingPage::kTypeForTesting =
133 &SafeBrowsingBlockingPage::kTypeForTesting; 135 &SafeBrowsingBlockingPage::kTypeForTesting;
134 136
135 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( 137 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
136 SafeBrowsingUIManager* ui_manager, 138 SafeBrowsingUIManager* ui_manager,
137 WebContents* web_contents, 139 WebContents* web_contents,
140 const GURL& main_frame_url,
138 const UnsafeResourceList& unsafe_resources) 141 const UnsafeResourceList& unsafe_resources)
139 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url), 142 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url),
140 malware_details_proceed_delay_ms_( 143 malware_details_proceed_delay_ms_(
141 kMalwareDetailsProceedDelayMilliSeconds), 144 kMalwareDetailsProceedDelayMilliSeconds),
142 ui_manager_(ui_manager), 145 ui_manager_(ui_manager),
143 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), 146 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)),
147 main_frame_url_(main_frame_url),
144 unsafe_resources_(unsafe_resources), 148 unsafe_resources_(unsafe_resources),
145 proceeded_(false) { 149 proceeded_(false) {
146 bool malware = false; 150 bool malware = false;
147 bool harmful = false; 151 bool harmful = false;
148 bool phishing = false; 152 bool phishing = false;
149 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin(); 153 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin();
150 iter != unsafe_resources_.end(); ++iter) { 154 iter != unsafe_resources_.end(); ++iter) {
151 const UnsafeResource& resource = *iter; 155 const UnsafeResource& resource = *iter;
152 SBThreatType threat_type = resource.threat_type; 156 SBThreatType threat_type = resource.threat_type;
153 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || 157 if (threat_type == SB_THREAT_TYPE_URL_MALWARE ||
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 SBThreatType threat_type) { 217 SBThreatType threat_type) {
214 return threat_type == SB_THREAT_TYPE_URL_PHISHING || 218 return threat_type == SB_THREAT_TYPE_URL_PHISHING ||
215 threat_type == SB_THREAT_TYPE_URL_MALWARE || 219 threat_type == SB_THREAT_TYPE_URL_MALWARE ||
216 threat_type == SB_THREAT_TYPE_URL_UNWANTED || 220 threat_type == SB_THREAT_TYPE_URL_UNWANTED ||
217 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || 221 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL ||
218 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; 222 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL;
219 } 223 }
220 224
221 bool SafeBrowsingBlockingPage::CanShowThreatDetailsOption() { 225 bool SafeBrowsingBlockingPage::CanShowThreatDetailsOption() {
222 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && 226 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() &&
223 web_contents()->GetURL().SchemeIs(url::kHttpScheme) && 227 main_frame_url_.SchemeIs(url::kHttpScheme) &&
224 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); 228 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed));
225 } 229 }
226 230
227 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { 231 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() {
228 } 232 }
229 233
230 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) { 234 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) {
231 if (page_cmd == "\"pageLoadComplete\"") { 235 if (page_cmd == "\"pageLoadComplete\"") {
232 // content::WaitForRenderFrameReady sends this message when the page 236 // content::WaitForRenderFrameReady sends this message when the page
233 // load completes. Ignore it. 237 // load completes. Ignore it.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 372
369 // Check to see if some new notifications of unsafe resources have been 373 // Check to see if some new notifications of unsafe resources have been
370 // received while we were showing the interstitial. 374 // received while we were showing the interstitial.
371 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); 375 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
372 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); 376 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
373 SafeBrowsingBlockingPage* blocking_page = NULL; 377 SafeBrowsingBlockingPage* blocking_page = NULL;
374 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { 378 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
375 // Build an interstitial for all the unsafe resources notifications. 379 // Build an interstitial for all the unsafe resources notifications.
376 // Don't show it now as showing an interstitial while an interstitial is 380 // Don't show it now as showing an interstitial while an interstitial is
377 // already showing would cause DontProceed() to be invoked. 381 // already showing would cause DontProceed() to be invoked.
378 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_, 382 blocking_page = factory_->CreateSafeBrowsingPage(
379 web_contents(), 383 ui_manager_, web_contents(),
380 iter->second); 384 // All queued unsafe resources should be for the same page:
385 iter->second[0].GetNavigationEntryForResource()->GetURL(),
386 iter->second);
381 unsafe_resource_map->erase(iter); 387 unsafe_resource_map->erase(iter);
382 } 388 }
383 389
384 // Now that this interstitial is gone, we can show the new one. 390 // Now that this interstitial is gone, we can show the new one.
385 if (blocking_page) 391 if (blocking_page)
386 blocking_page->Show(); 392 blocking_page->Show();
387 } 393 }
388 394
389 content::InterstitialPageDelegate::TypeID 395 content::InterstitialPageDelegate::TypeID
390 SafeBrowsingBlockingPage::GetTypeForTesting() const { 396 SafeBrowsingBlockingPage::GetTypeForTesting() const {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // static 468 // static
463 SafeBrowsingBlockingPage::UnsafeResourceMap* 469 SafeBrowsingBlockingPage::UnsafeResourceMap*
464 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() { 470 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() {
465 return g_unsafe_resource_map.Pointer(); 471 return g_unsafe_resource_map.Pointer();
466 } 472 }
467 473
468 // static 474 // static
469 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage( 475 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage(
470 SafeBrowsingUIManager* ui_manager, 476 SafeBrowsingUIManager* ui_manager,
471 WebContents* web_contents, 477 WebContents* web_contents,
478 const GURL& main_frame_url,
472 const UnsafeResource& unsafe_resource) { 479 const UnsafeResource& unsafe_resource) {
473 std::vector<UnsafeResource> resources; 480 std::vector<UnsafeResource> resources;
474 resources.push_back(unsafe_resource); 481 resources.push_back(unsafe_resource);
475 // Set up the factory if this has not been done already (tests do that 482 // Set up the factory if this has not been done already (tests do that
476 // before this method is called). 483 // before this method is called).
477 if (!factory_) 484 if (!factory_)
478 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer(); 485 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer();
479 return factory_->CreateSafeBrowsingPage(ui_manager, web_contents, resources); 486 return factory_->CreateSafeBrowsingPage(ui_manager, web_contents,
487 main_frame_url, resources);
480 } 488 }
481 489
482 // static 490 // static
483 void SafeBrowsingBlockingPage::ShowBlockingPage( 491 void SafeBrowsingBlockingPage::ShowBlockingPage(
484 SafeBrowsingUIManager* ui_manager, 492 SafeBrowsingUIManager* ui_manager,
485 const UnsafeResource& unsafe_resource) { 493 const UnsafeResource& unsafe_resource) {
486 DVLOG(1) << __FUNCTION__ << " " << unsafe_resource.url.spec(); 494 DVLOG(1) << __FUNCTION__ << " " << unsafe_resource.url.spec();
487 WebContents* web_contents = tab_util::GetWebContentsByID( 495 WebContents* web_contents = tab_util::GetWebContentsByID(
488 unsafe_resource.render_process_host_id, unsafe_resource.render_view_id); 496 unsafe_resource.render_process_host_id, unsafe_resource.render_view_id);
489 497
490 InterstitialPage* interstitial = 498 InterstitialPage* interstitial =
491 InterstitialPage::GetInterstitialPage(web_contents); 499 InterstitialPage::GetInterstitialPage(web_contents);
492 if (interstitial && !unsafe_resource.is_subresource) { 500 if (interstitial && !unsafe_resource.is_subresource) {
493 // There is already an interstitial showing and we are about to display a 501 // 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 502 // new one for the main frame. Just hide the current one, it is now
495 // irrelevent 503 // irrelevent
496 interstitial->DontProceed(); 504 interstitial->DontProceed();
497 interstitial = NULL; 505 interstitial = NULL;
498 } 506 }
499 507
500 if (!interstitial) { 508 if (!interstitial) {
501 // There are no interstitial currently showing in that tab, go ahead and 509 // There are no interstitial currently showing in that tab, go ahead and
502 // show this interstitial. 510 // show this interstitial.
511 content::NavigationEntry* entry =
512 unsafe_resource.GetNavigationEntryForResource();
503 SafeBrowsingBlockingPage* blocking_page = 513 SafeBrowsingBlockingPage* blocking_page =
504 CreateBlockingPage(ui_manager, web_contents, unsafe_resource); 514 CreateBlockingPage(ui_manager, web_contents,
515 entry ? entry->GetURL() : GURL(), unsafe_resource);
505 blocking_page->Show(); 516 blocking_page->Show();
506 return; 517 return;
507 } 518 }
508 519
509 // This is an interstitial for a page's resource, let's queue it. 520 // This is an interstitial for a page's resource, let's queue it.
510 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); 521 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
511 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); 522 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource);
512 } 523 }
513 524
514 // static 525 // static
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 IDS_MALWARE_V3_PRIMARY_PARAGRAPH, 656 IDS_MALWARE_V3_PRIMARY_PARAGRAPH,
646 GetFormattedHostName())); 657 GetFormattedHostName()));
647 load_time_data->SetString( 658 load_time_data->SetString(
648 "explanationParagraph", 659 "explanationParagraph",
649 is_main_frame_load_blocked_ ? 660 is_main_frame_load_blocked_ ?
650 l10n_util::GetStringFUTF16( 661 l10n_util::GetStringFUTF16(
651 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH, 662 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH,
652 GetFormattedHostName()) : 663 GetFormattedHostName()) :
653 l10n_util::GetStringFUTF16( 664 l10n_util::GetStringFUTF16(
654 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE, 665 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE,
655 base::UTF8ToUTF16(web_contents()->GetURL().host()), 666 base::UTF8ToUTF16(main_frame_url_.host()),
656 GetFormattedHostName())); 667 GetFormattedHostName()));
657 load_time_data->SetString( 668 load_time_data->SetString(
658 "finalParagraph", 669 "finalParagraph",
659 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH)); 670 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH));
660 671
661 PopulateExtendedReportingOption(load_time_data); 672 PopulateExtendedReportingOption(load_time_data);
662 } 673 }
663 674
664 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData( 675 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData(
665 base::DictionaryValue* load_time_data) { 676 base::DictionaryValue* load_time_data) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 } else { 723 } else {
713 load_time_data->SetString( 724 load_time_data->SetString(
714 "finalParagraph", 725 "finalParagraph",
715 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); 726 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH));
716 } 727 }
717 728
718 PopulateExtendedReportingOption(load_time_data); 729 PopulateExtendedReportingOption(load_time_data);
719 } 730 }
720 731
721 } // namespace safe_browsing 732 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698