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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 security_interstitials::MetricsHelper::PROCEEDING_DISABLED); | 186 security_interstitials::MetricsHelper::PROCEEDING_DISABLED); |
187 } | 187 } |
188 | 188 |
189 if (!is_main_frame_load_blocked_) { | 189 if (!is_main_frame_load_blocked_) { |
190 navigation_entry_index_to_remove_ = | 190 navigation_entry_index_to_remove_ = |
191 web_contents->GetController().GetLastCommittedEntryIndex(); | 191 web_contents->GetController().GetLastCommittedEntryIndex(); |
192 } else { | 192 } else { |
193 navigation_entry_index_to_remove_ = -1; | 193 navigation_entry_index_to_remove_ = -1; |
194 } | 194 } |
195 | 195 |
196 // Start computing malware details. They will be sent only | 196 // Start computing threat details. They will be sent only |
197 // if the user opts-in on the blocking page later. | 197 // if the user opts-in on the blocking page later. |
198 // If there's more than one malicious resources, it means the user | 198 // If there's more than one malicious resources, it means the user |
199 // clicked through the first warning, so we don't prepare additional | 199 // clicked through the first warning, so we don't prepare additional |
200 // reports. | 200 // reports. |
201 if (unsafe_resources.size() == 1 && | 201 if (unsafe_resources.size() == 1 && |
202 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE && | 202 ShouldReportThreatDetails(unsafe_resources[0].threat_type) && |
203 threat_details_.get() == NULL && CanShowMalwareDetailsOption()) { | 203 threat_details_.get() == NULL && CanShowThreatDetailsOption()) { |
204 threat_details_ = ThreatDetails::NewThreatDetails(ui_manager_, web_contents, | 204 threat_details_ = ThreatDetails::NewThreatDetails(ui_manager_, web_contents, |
205 unsafe_resources[0]); | 205 unsafe_resources[0]); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { | 209 bool SafeBrowsingBlockingPage::ShouldReportThreatDetails( |
| 210 SBThreatType threat_type) { |
| 211 return threat_type == SB_THREAT_TYPE_URL_PHISHING || |
| 212 threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 213 threat_type == SB_THREAT_TYPE_URL_UNWANTED || |
| 214 threat_type == SB_THREAT_TYPE_BINARY_MALWARE_URL || |
| 215 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || |
| 216 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; |
| 217 } |
| 218 |
| 219 bool SafeBrowsingBlockingPage::CanShowThreatDetailsOption() { |
210 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && | 220 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && |
211 web_contents()->GetURL().SchemeIs(url::kHttpScheme) && | 221 web_contents()->GetURL().SchemeIs(url::kHttpScheme) && |
212 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); | 222 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); |
213 } | 223 } |
214 | 224 |
215 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 225 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
216 } | 226 } |
217 | 227 |
218 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) { | 228 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) { |
219 if (page_cmd == "\"pageLoadComplete\"") { | 229 if (page_cmd == "\"pageLoadComplete\"") { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 void SafeBrowsingBlockingPage::OverrideRendererPrefs( | 351 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
342 content::RendererPreferences* prefs) { | 352 content::RendererPreferences* prefs) { |
343 Profile* profile = Profile::FromBrowserContext( | 353 Profile* profile = Profile::FromBrowserContext( |
344 web_contents()->GetBrowserContext()); | 354 web_contents()->GetBrowserContext()); |
345 renderer_preferences_util::UpdateFromSystemSettings( | 355 renderer_preferences_util::UpdateFromSystemSettings( |
346 prefs, profile, web_contents()); | 356 prefs, profile, web_contents()); |
347 } | 357 } |
348 | 358 |
349 void SafeBrowsingBlockingPage::OnProceed() { | 359 void SafeBrowsingBlockingPage::OnProceed() { |
350 proceeded_ = true; | 360 proceeded_ = true; |
351 // Send the malware details, if we opted to. | 361 // Send the threat details, if we opted to. |
352 FinishThreatDetails(malware_details_proceed_delay_ms_, true, /* did_proceed */ | 362 FinishThreatDetails(malware_details_proceed_delay_ms_, true, /* did_proceed */ |
353 metrics_helper()->NumVisits()); | 363 metrics_helper()->NumVisits()); |
354 | 364 |
355 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); | 365 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); |
356 | 366 |
357 // Check to see if some new notifications of unsafe resources have been | 367 // Check to see if some new notifications of unsafe resources have been |
358 // received while we were showing the interstitial. | 368 // received while we were showing the interstitial. |
359 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 369 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
360 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); | 370 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); |
361 SafeBrowsingBlockingPage* blocking_page = NULL; | 371 SafeBrowsingBlockingPage* blocking_page = NULL; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 CHECK(web_contents()->GetController().RemoveEntryAtIndex( | 432 CHECK(web_contents()->GetController().RemoveEntryAtIndex( |
423 navigation_entry_index_to_remove_)); | 433 navigation_entry_index_to_remove_)); |
424 navigation_entry_index_to_remove_ = -1; | 434 navigation_entry_index_to_remove_ = -1; |
425 } | 435 } |
426 } | 436 } |
427 | 437 |
428 void SafeBrowsingBlockingPage::FinishThreatDetails(int64 delay_ms, | 438 void SafeBrowsingBlockingPage::FinishThreatDetails(int64 delay_ms, |
429 bool did_proceed, | 439 bool did_proceed, |
430 int num_visits) { | 440 int num_visits) { |
431 if (threat_details_.get() == NULL) | 441 if (threat_details_.get() == NULL) |
432 return; // Not all interstitials have malware details (eg phishing). | 442 return; // Not all interstitials have threat details (eg., incognito mode). |
433 DCHECK_EQ(interstitial_reason_, SB_REASON_MALWARE); | |
434 | 443 |
435 const bool enabled = | 444 const bool enabled = |
436 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled) && | 445 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled) && |
437 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed); | 446 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed); |
438 if (!enabled) | 447 if (!enabled) |
439 return; | 448 return; |
440 | 449 |
441 metrics_helper()->RecordUserInteraction( | 450 metrics_helper()->RecordUserInteraction( |
442 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); | 451 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); |
443 // Finish the malware details collection, send it over. | 452 // Finish the malware details collection, send it over. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 break; | 618 break; |
610 case SB_REASON_PHISHING: | 619 case SB_REASON_PHISHING: |
611 PopulatePhishingLoadTimeData(load_time_data); | 620 PopulatePhishingLoadTimeData(load_time_data); |
612 break; | 621 break; |
613 } | 622 } |
614 } | 623 } |
615 | 624 |
616 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( | 625 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( |
617 base::DictionaryValue* load_time_data) { | 626 base::DictionaryValue* load_time_data) { |
618 // Only show checkbox if !(HTTPS || incognito-mode). | 627 // Only show checkbox if !(HTTPS || incognito-mode). |
619 const bool show = CanShowMalwareDetailsOption(); | 628 const bool show = CanShowThreatDetailsOption(); |
620 load_time_data->SetBoolean(interstitials::kDisplayCheckBox, show); | 629 load_time_data->SetBoolean(interstitials::kDisplayCheckBox, show); |
621 if (!show) | 630 if (!show) |
622 return; | 631 return; |
623 | 632 |
624 const std::string privacy_link = base::StringPrintf( | 633 const std::string privacy_link = base::StringPrintf( |
625 interstitials::kPrivacyLinkHtml, CMD_OPEN_REPORTING_PRIVACY, | 634 interstitials::kPrivacyLinkHtml, CMD_OPEN_REPORTING_PRIVACY, |
626 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); | 635 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); |
627 load_time_data->SetString( | 636 load_time_data->SetString( |
628 interstitials::kOptInLink, | 637 interstitials::kOptInLink, |
629 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, | 638 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 "finalParagraph", l10n_util::GetStringUTF16( | 718 "finalParagraph", l10n_util::GetStringUTF16( |
710 IDS_PHISHING_V4_PROCEED_AND_REPORT_PARAGRAPH)); | 719 IDS_PHISHING_V4_PROCEED_AND_REPORT_PARAGRAPH)); |
711 } else { | 720 } else { |
712 load_time_data->SetString( | 721 load_time_data->SetString( |
713 "finalParagraph", | 722 "finalParagraph", |
714 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 723 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
715 } | 724 } |
716 | 725 |
717 PopulateExtendedReportingOption(load_time_data); | 726 PopulateExtendedReportingOption(load_time_data); |
718 } | 727 } |
OLD | NEW |