| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 metrics_helper()->NumVisits()); | 369 metrics_helper()->NumVisits()); |
| 366 | 370 |
| 367 ui_manager_->OnBlockingPageDone(unsafe_resources_, true); | 371 ui_manager_->OnBlockingPageDone(unsafe_resources_, true); |
| 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()) { |
| 379 // All queued unsafe resources should be for the same page: |
| 380 content::NavigationEntry* entry = |
| 381 iter->second[0].GetNavigationEntryForResource(); |
| 375 // Build an interstitial for all the unsafe resources notifications. | 382 // Build an interstitial for all the unsafe resources notifications. |
| 376 // Don't show it now as showing an interstitial while an interstitial is | 383 // Don't show it now as showing an interstitial while an interstitial is |
| 377 // already showing would cause DontProceed() to be invoked. | 384 // already showing would cause DontProceed() to be invoked. |
| 378 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_, | 385 blocking_page = factory_->CreateSafeBrowsingPage( |
| 379 web_contents(), | 386 ui_manager_, web_contents(), entry ? entry->GetURL() : GURL(), |
| 380 iter->second); | 387 iter->second); |
| 381 unsafe_resource_map->erase(iter); | 388 unsafe_resource_map->erase(iter); |
| 382 } | 389 } |
| 383 | 390 |
| 384 // Now that this interstitial is gone, we can show the new one. | 391 // Now that this interstitial is gone, we can show the new one. |
| 385 if (blocking_page) | 392 if (blocking_page) |
| 386 blocking_page->Show(); | 393 blocking_page->Show(); |
| 387 } | 394 } |
| 388 | 395 |
| 389 content::InterstitialPageDelegate::TypeID | 396 content::InterstitialPageDelegate::TypeID |
| 390 SafeBrowsingBlockingPage::GetTypeForTesting() const { | 397 SafeBrowsingBlockingPage::GetTypeForTesting() const { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 // static | 469 // static |
| 463 SafeBrowsingBlockingPage::UnsafeResourceMap* | 470 SafeBrowsingBlockingPage::UnsafeResourceMap* |
| 464 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() { | 471 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() { |
| 465 return g_unsafe_resource_map.Pointer(); | 472 return g_unsafe_resource_map.Pointer(); |
| 466 } | 473 } |
| 467 | 474 |
| 468 // static | 475 // static |
| 469 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage( | 476 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage( |
| 470 SafeBrowsingUIManager* ui_manager, | 477 SafeBrowsingUIManager* ui_manager, |
| 471 WebContents* web_contents, | 478 WebContents* web_contents, |
| 479 const GURL& main_frame_url, |
| 472 const UnsafeResource& unsafe_resource) { | 480 const UnsafeResource& unsafe_resource) { |
| 473 std::vector<UnsafeResource> resources; | 481 std::vector<UnsafeResource> resources; |
| 474 resources.push_back(unsafe_resource); | 482 resources.push_back(unsafe_resource); |
| 475 // Set up the factory if this has not been done already (tests do that | 483 // Set up the factory if this has not been done already (tests do that |
| 476 // before this method is called). | 484 // before this method is called). |
| 477 if (!factory_) | 485 if (!factory_) |
| 478 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer(); | 486 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer(); |
| 479 return factory_->CreateSafeBrowsingPage(ui_manager, web_contents, resources); | 487 return factory_->CreateSafeBrowsingPage(ui_manager, web_contents, |
| 488 main_frame_url, resources); |
| 480 } | 489 } |
| 481 | 490 |
| 482 // static | 491 // static |
| 483 void SafeBrowsingBlockingPage::ShowBlockingPage( | 492 void SafeBrowsingBlockingPage::ShowBlockingPage( |
| 484 SafeBrowsingUIManager* ui_manager, | 493 SafeBrowsingUIManager* ui_manager, |
| 485 const UnsafeResource& unsafe_resource) { | 494 const UnsafeResource& unsafe_resource) { |
| 486 DVLOG(1) << __FUNCTION__ << " " << unsafe_resource.url.spec(); | 495 DVLOG(1) << __FUNCTION__ << " " << unsafe_resource.url.spec(); |
| 487 WebContents* web_contents = tab_util::GetWebContentsByID( | 496 WebContents* web_contents = tab_util::GetWebContentsByID( |
| 488 unsafe_resource.render_process_host_id, unsafe_resource.render_view_id); | 497 unsafe_resource.render_process_host_id, unsafe_resource.render_view_id); |
| 489 | 498 |
| 490 InterstitialPage* interstitial = | 499 InterstitialPage* interstitial = |
| 491 InterstitialPage::GetInterstitialPage(web_contents); | 500 InterstitialPage::GetInterstitialPage(web_contents); |
| 492 if (interstitial && !unsafe_resource.is_subresource) { | 501 if (interstitial && !unsafe_resource.is_subresource) { |
| 493 // There is already an interstitial showing and we are about to display a | 502 // 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 | 503 // new one for the main frame. Just hide the current one, it is now |
| 495 // irrelevent | 504 // irrelevent |
| 496 interstitial->DontProceed(); | 505 interstitial->DontProceed(); |
| 497 interstitial = NULL; | 506 interstitial = NULL; |
| 498 } | 507 } |
| 499 | 508 |
| 500 if (!interstitial) { | 509 if (!interstitial) { |
| 501 // There are no interstitial currently showing in that tab, go ahead and | 510 // There are no interstitial currently showing in that tab, go ahead and |
| 502 // show this interstitial. | 511 // show this interstitial. |
| 512 content::NavigationEntry* entry = |
| 513 unsafe_resource.GetNavigationEntryForResource(); |
| 503 SafeBrowsingBlockingPage* blocking_page = | 514 SafeBrowsingBlockingPage* blocking_page = |
| 504 CreateBlockingPage(ui_manager, web_contents, unsafe_resource); | 515 CreateBlockingPage(ui_manager, web_contents, |
| 516 entry ? entry->GetURL() : GURL(), unsafe_resource); |
| 505 blocking_page->Show(); | 517 blocking_page->Show(); |
| 506 return; | 518 return; |
| 507 } | 519 } |
| 508 | 520 |
| 509 // This is an interstitial for a page's resource, let's queue it. | 521 // This is an interstitial for a page's resource, let's queue it. |
| 510 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 522 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 511 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); | 523 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); |
| 512 } | 524 } |
| 513 | 525 |
| 514 // static | 526 // static |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 IDS_MALWARE_V3_PRIMARY_PARAGRAPH, | 657 IDS_MALWARE_V3_PRIMARY_PARAGRAPH, |
| 646 GetFormattedHostName())); | 658 GetFormattedHostName())); |
| 647 load_time_data->SetString( | 659 load_time_data->SetString( |
| 648 "explanationParagraph", | 660 "explanationParagraph", |
| 649 is_main_frame_load_blocked_ ? | 661 is_main_frame_load_blocked_ ? |
| 650 l10n_util::GetStringFUTF16( | 662 l10n_util::GetStringFUTF16( |
| 651 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH, | 663 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH, |
| 652 GetFormattedHostName()) : | 664 GetFormattedHostName()) : |
| 653 l10n_util::GetStringFUTF16( | 665 l10n_util::GetStringFUTF16( |
| 654 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE, | 666 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE, |
| 655 base::UTF8ToUTF16(web_contents()->GetURL().host()), | 667 base::UTF8ToUTF16(main_frame_url_.host()), |
| 656 GetFormattedHostName())); | 668 GetFormattedHostName())); |
| 657 load_time_data->SetString( | 669 load_time_data->SetString( |
| 658 "finalParagraph", | 670 "finalParagraph", |
| 659 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH)); | 671 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH)); |
| 660 | 672 |
| 661 PopulateExtendedReportingOption(load_time_data); | 673 PopulateExtendedReportingOption(load_time_data); |
| 662 } | 674 } |
| 663 | 675 |
| 664 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData( | 676 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData( |
| 665 base::DictionaryValue* load_time_data) { | 677 base::DictionaryValue* load_time_data) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 } else { | 724 } else { |
| 713 load_time_data->SetString( | 725 load_time_data->SetString( |
| 714 "finalParagraph", | 726 "finalParagraph", |
| 715 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 727 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
| 716 } | 728 } |
| 717 | 729 |
| 718 PopulateExtendedReportingOption(load_time_data); | 730 PopulateExtendedReportingOption(load_time_data); |
| 719 } | 731 } |
| 720 | 732 |
| 721 } // namespace safe_browsing | 733 } // namespace safe_browsing |
| OLD | NEW |