| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/interstitials/chrome_controller_client.h" | |
| 21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/renderer_preferences_util.h" | 21 #include "chrome/browser/renderer_preferences_util.h" |
| 23 #include "chrome/browser/safe_browsing/threat_details.h" | 22 #include "chrome/browser/safe_browsing/threat_details.h" |
| 24 #include "chrome/browser/safe_browsing/ui_manager.h" | 23 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 25 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" |
| 26 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 27 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 27 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
| 28 #include "components/security_interstitials/content/security_interstitial_contro
ller_client.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/interstitial_page.h" | 30 #include "content/public/browser/interstitial_page.h" |
| 30 #include "content/public/browser/navigation_entry.h" | 31 #include "content/public/browser/navigation_entry.h" |
| 31 #include "content/public/browser/user_metrics.h" | 32 #include "content/public/browser/user_metrics.h" |
| 32 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 33 | 34 |
| 34 using base::UserMetricsAction; | 35 using base::UserMetricsAction; |
| 35 using content::BrowserThread; | 36 using content::BrowserThread; |
| 36 using content::InterstitialPage; | 37 using content::InterstitialPage; |
| 37 using content::WebContents; | 38 using content::WebContents; |
| 38 using security_interstitials::SafeBrowsingErrorUI; | 39 using security_interstitials::SafeBrowsingErrorUI; |
| 40 using security_interstitials::SecurityInterstitialControllerClient; |
| 39 | 41 |
| 40 namespace safe_browsing { | 42 namespace safe_browsing { |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 // After a safe browsing interstitial where the user opted-in to the report | 46 // After a safe browsing interstitial where the user opted-in to the report |
| 45 // but clicked "proceed anyway", we delay the call to | 47 // but clicked "proceed anyway", we delay the call to |
| 46 // ThreatDetails::FinishCollection() by this much time (in | 48 // ThreatDetails::FinishCollection() by this much time (in |
| 47 // milliseconds). | 49 // milliseconds). |
| 48 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; | 50 const int64_t kThreatDetailsProceedDelayMilliSeconds = 3000; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 &SafeBrowsingBlockingPage::kTypeForTesting; | 96 &SafeBrowsingBlockingPage::kTypeForTesting; |
| 95 | 97 |
| 96 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( | 98 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( |
| 97 SafeBrowsingUIManager* ui_manager, | 99 SafeBrowsingUIManager* ui_manager, |
| 98 WebContents* web_contents, | 100 WebContents* web_contents, |
| 99 const GURL& main_frame_url, | 101 const GURL& main_frame_url, |
| 100 const UnsafeResourceList& unsafe_resources) | 102 const UnsafeResourceList& unsafe_resources) |
| 101 : SecurityInterstitialPage( | 103 : SecurityInterstitialPage( |
| 102 web_contents, | 104 web_contents, |
| 103 unsafe_resources[0].url, | 105 unsafe_resources[0].url, |
| 104 CreateMetricsHelper(web_contents, unsafe_resources)), | 106 CreateControllerClient(web_contents, unsafe_resources)), |
| 105 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds), | 107 threat_details_proceed_delay_ms_(kThreatDetailsProceedDelayMilliSeconds), |
| 106 ui_manager_(ui_manager), | 108 ui_manager_(ui_manager), |
| 107 main_frame_url_(main_frame_url), | 109 main_frame_url_(main_frame_url), |
| 108 unsafe_resources_(unsafe_resources), | 110 unsafe_resources_(unsafe_resources), |
| 109 proceeded_(false) { | 111 proceeded_(false) { |
| 110 // Computes display options based on user profile and blocked resource. | 112 // Computes display options based on user profile and blocked resource. |
| 111 bool is_main_frame_load_blocked = IsMainPageLoadBlocked(unsafe_resources); | 113 bool is_main_frame_load_blocked = IsMainPageLoadBlocked(unsafe_resources); |
| 112 bool can_show_extended_reporting_option = CanShowExtendedReportingOption(); | |
| 113 SafeBrowsingErrorUI::SBErrorDisplayOptions display_options( | 114 SafeBrowsingErrorUI::SBErrorDisplayOptions display_options( |
| 114 is_main_frame_load_blocked, can_show_extended_reporting_option, | 115 is_main_frame_load_blocked, |
| 115 IsExtendedReportingEnabled(*profile()->GetPrefs()), | 116 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed), |
| 116 IsScout(*profile()->GetPrefs()), | 117 web_contents->GetBrowserContext()->IsOffTheRecord(), |
| 118 IsExtendedReportingEnabled(*controller()->GetPrefService()), |
| 119 IsScout(*controller()->GetPrefService()), |
| 117 IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); | 120 IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); |
| 118 sb_error_ui_ = base::MakeUnique<SafeBrowsingErrorUI>( | 121 sb_error_ui_ = base::MakeUnique<SafeBrowsingErrorUI>( |
| 119 unsafe_resources[0].url, main_frame_url_, | 122 unsafe_resources[0].url, main_frame_url_, |
| 120 GetInterstitialReason(unsafe_resources), display_options, | 123 GetInterstitialReason(unsafe_resources), display_options, |
| 121 g_browser_process->GetApplicationLocale(), | 124 g_browser_process->GetApplicationLocale(), |
| 122 base::Time::NowFromSystemTime(), controller()); | 125 base::Time::NowFromSystemTime(), controller()); |
| 123 | 126 |
| 124 if (!is_main_frame_load_blocked) { | 127 if (!is_main_frame_load_blocked) { |
| 125 navigation_entry_index_to_remove_ = | 128 navigation_entry_index_to_remove_ = |
| 126 web_contents->GetController().GetLastCommittedEntryIndex(); | 129 web_contents->GetController().GetLastCommittedEntryIndex(); |
| 127 } else { | 130 } else { |
| 128 navigation_entry_index_to_remove_ = -1; | 131 navigation_entry_index_to_remove_ = -1; |
| 129 } | 132 } |
| 130 | 133 |
| 131 // Start computing threat details. They will be sent only | 134 // Start computing threat details. They will be sent only |
| 132 // if the user opts-in on the blocking page later. | 135 // if the user opts-in on the blocking page later. |
| 133 // If there's more than one malicious resources, it means the user | 136 // If there's more than one malicious resources, it means the user |
| 134 // clicked through the first warning, so we don't prepare additional | 137 // clicked through the first warning, so we don't prepare additional |
| 135 // reports. | 138 // reports. |
| 136 if (unsafe_resources.size() == 1 && | 139 if (unsafe_resources.size() == 1 && |
| 137 ShouldReportThreatDetails(unsafe_resources[0].threat_type) && | 140 ShouldReportThreatDetails(unsafe_resources[0].threat_type) && |
| 138 threat_details_.get() == NULL && can_show_extended_reporting_option) { | 141 threat_details_.get() == NULL && |
| 142 sb_error_ui_->CanShowExtendedReportingOption()) { |
| 139 threat_details_ = ThreatDetails::NewThreatDetails(ui_manager_, web_contents, | 143 threat_details_ = ThreatDetails::NewThreatDetails(ui_manager_, web_contents, |
| 140 unsafe_resources[0]); | 144 unsafe_resources[0]); |
| 141 } | 145 } |
| 142 } | 146 } |
| 143 | 147 |
| 144 bool SafeBrowsingBlockingPage::ShouldReportThreatDetails( | 148 bool SafeBrowsingBlockingPage::ShouldReportThreatDetails( |
| 145 SBThreatType threat_type) { | 149 SBThreatType threat_type) { |
| 146 return threat_type == SB_THREAT_TYPE_URL_PHISHING || | 150 return threat_type == SB_THREAT_TYPE_URL_PHISHING || |
| 147 threat_type == SB_THREAT_TYPE_URL_MALWARE || | 151 threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 148 threat_type == SB_THREAT_TYPE_URL_UNWANTED || | 152 threat_type == SB_THREAT_TYPE_URL_UNWANTED || |
| 149 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || | 153 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || |
| 150 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; | 154 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; |
| 151 } | 155 } |
| 152 | 156 |
| 153 bool SafeBrowsingBlockingPage::CanShowExtendedReportingOption() { | |
| 154 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && | |
| 155 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); | |
| 156 } | |
| 157 | |
| 158 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 157 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
| 159 } | 158 } |
| 160 | 159 |
| 161 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) { | 160 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) { |
| 162 if (page_cmd == "\"pageLoadComplete\"") { | 161 if (page_cmd == "\"pageLoadComplete\"") { |
| 163 // content::WaitForRenderFrameReady sends this message when the page | 162 // content::WaitForRenderFrameReady sends this message when the page |
| 164 // load completes. Ignore it. | 163 // load completes. Ignore it. |
| 165 return; | 164 return; |
| 166 } | 165 } |
| 167 | 166 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { | 221 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const { |
| 223 return sb_error_ui_->is_main_frame_load_blocked(); | 222 return sb_error_ui_->is_main_frame_load_blocked(); |
| 224 } | 223 } |
| 225 | 224 |
| 226 void SafeBrowsingBlockingPage::OnDontProceed() { | 225 void SafeBrowsingBlockingPage::OnDontProceed() { |
| 227 // We could have already called Proceed(), in which case we must not notify | 226 // We could have already called Proceed(), in which case we must not notify |
| 228 // the SafeBrowsingUIManager again, as the client has been deleted. | 227 // the SafeBrowsingUIManager again, as the client has been deleted. |
| 229 if (proceeded_) | 228 if (proceeded_) |
| 230 return; | 229 return; |
| 231 | 230 |
| 232 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 231 if (!sb_error_ui_->is_proceed_anyway_disabled()) { |
| 233 controller()->metrics_helper()->RecordUserDecision( | 232 controller()->metrics_helper()->RecordUserDecision( |
| 234 security_interstitials::MetricsHelper::DONT_PROCEED); | 233 security_interstitials::MetricsHelper::DONT_PROCEED); |
| 235 } | 234 } |
| 236 | 235 |
| 237 // Send the malware details, if we opted to. | 236 // Send the malware details, if we opted to. |
| 238 FinishThreatDetails(0, false /* did_proceed */, | 237 FinishThreatDetails(0, false /* did_proceed */, |
| 239 controller()->metrics_helper()->NumVisits()); // No delay | 238 controller()->metrics_helper()->NumVisits()); // No delay |
| 240 | 239 |
| 241 ui_manager_->OnBlockingPageDone(unsafe_resources_, false, web_contents(), | 240 ui_manager_->OnBlockingPageDone(unsafe_resources_, false, web_contents(), |
| 242 main_frame_url_); | 241 main_frame_url_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 267 } | 266 } |
| 268 } | 267 } |
| 269 | 268 |
| 270 void SafeBrowsingBlockingPage::FinishThreatDetails(int64_t delay_ms, | 269 void SafeBrowsingBlockingPage::FinishThreatDetails(int64_t delay_ms, |
| 271 bool did_proceed, | 270 bool did_proceed, |
| 272 int num_visits) { | 271 int num_visits) { |
| 273 if (threat_details_.get() == NULL) | 272 if (threat_details_.get() == NULL) |
| 274 return; // Not all interstitials have threat details (eg., incognito mode). | 273 return; // Not all interstitials have threat details (eg., incognito mode). |
| 275 | 274 |
| 276 const bool enabled = | 275 const bool enabled = |
| 277 IsExtendedReportingEnabled(*profile()->GetPrefs()) && | 276 sb_error_ui_->is_extended_reporting_enabled() && |
| 278 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed); | 277 sb_error_ui_->is_extended_reporting_opt_in_allowed(); |
| 279 if (!enabled) | 278 if (!enabled) |
| 280 return; | 279 return; |
| 281 | 280 |
| 282 controller()->metrics_helper()->RecordUserInteraction( | 281 controller()->metrics_helper()->RecordUserInteraction( |
| 283 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); | 282 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); |
| 284 // Finish the malware details collection, send it over. | 283 // Finish the malware details collection, send it over. |
| 285 BrowserThread::PostDelayedTask( | 284 BrowserThread::PostDelayedTask( |
| 286 BrowserThread::IO, FROM_HERE, | 285 BrowserThread::IO, FROM_HERE, |
| 287 base::Bind(&ThreatDetails::FinishCollection, threat_details_, | 286 base::Bind(&ThreatDetails::FinishCollection, threat_details_, |
| 288 did_proceed, num_visits), | 287 did_proceed, num_visits), |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 435 } |
| 437 DCHECK(phishing || malware || harmful); | 436 DCHECK(phishing || malware || harmful); |
| 438 if (malware) | 437 if (malware) |
| 439 return SafeBrowsingErrorUI::SB_REASON_MALWARE; | 438 return SafeBrowsingErrorUI::SB_REASON_MALWARE; |
| 440 else if (harmful) | 439 else if (harmful) |
| 441 return SafeBrowsingErrorUI::SB_REASON_HARMFUL; | 440 return SafeBrowsingErrorUI::SB_REASON_HARMFUL; |
| 442 return SafeBrowsingErrorUI::SB_REASON_PHISHING; | 441 return SafeBrowsingErrorUI::SB_REASON_PHISHING; |
| 443 } | 442 } |
| 444 | 443 |
| 445 // static | 444 // static |
| 446 std::unique_ptr<ChromeMetricsHelper> | 445 std::unique_ptr<security_interstitials::SecurityInterstitialControllerClient> |
| 447 SafeBrowsingBlockingPage::CreateMetricsHelper( | 446 SafeBrowsingBlockingPage::CreateControllerClient( |
| 448 WebContents* web_contents, | 447 WebContents* web_contents, |
| 449 const UnsafeResourceList& unsafe_resources) { | 448 const UnsafeResourceList& unsafe_resources) { |
| 450 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = | 449 SafeBrowsingErrorUI::SBInterstitialReason interstitial_reason = |
| 451 GetInterstitialReason(unsafe_resources); | 450 GetInterstitialReason(unsafe_resources); |
| 452 GURL request_url(unsafe_resources[0].url); | 451 GURL request_url(unsafe_resources[0].url); |
| 453 security_interstitials::MetricsHelper::ReportDetails reporting_info; | 452 security_interstitials::MetricsHelper::ReportDetails reporting_info; |
| 454 reporting_info.metric_prefix = | 453 reporting_info.metric_prefix = |
| 455 GetMetricPrefix(unsafe_resources, interstitial_reason); | 454 GetMetricPrefix(unsafe_resources, interstitial_reason); |
| 456 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); | 455 reporting_info.extra_suffix = GetExtraMetricsSuffix(unsafe_resources); |
| 457 return std::unique_ptr<ChromeMetricsHelper>( | 456 |
| 458 new ChromeMetricsHelper(web_contents, request_url, reporting_info, | 457 std::unique_ptr<ChromeMetricsHelper> metrics_helper = |
| 459 GetSamplingEventName(interstitial_reason))); | 458 base::MakeUnique<ChromeMetricsHelper>( |
| 459 web_contents, request_url, reporting_info, |
| 460 GetSamplingEventName(interstitial_reason)); |
| 461 |
| 462 Profile* profile = Profile::FromBrowserContext( |
| 463 web_contents->GetBrowserContext()); |
| 464 DCHECK(profile); |
| 465 |
| 466 return base::MakeUnique< |
| 467 security_interstitials::SecurityInterstitialControllerClient>( |
| 468 web_contents, |
| 469 std::move(metrics_helper), |
| 470 profile->GetPrefs(), |
| 471 g_browser_process->GetApplicationLocale(), |
| 472 GURL(chrome::kChromeUINewTabURL)); |
| 460 } | 473 } |
| 461 | 474 |
| 462 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( | 475 void SafeBrowsingBlockingPage::PopulateInterstitialStrings( |
| 463 base::DictionaryValue* load_time_data) { | 476 base::DictionaryValue* load_time_data) { |
| 464 sb_error_ui_->PopulateStringsForHTML(load_time_data); | 477 sb_error_ui_->PopulateStringsForHTML(load_time_data); |
| 465 } | 478 } |
| 466 | 479 |
| 467 } // namespace safe_browsing | 480 } // namespace safe_browsing |
| OLD | NEW |