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_CLIENT_SIDE_PHISHING_URL || |
| 215 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; |
| 216 } |
| 217 |
| 218 bool SafeBrowsingBlockingPage::CanShowThreatDetailsOption() { |
210 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && | 219 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() && |
211 web_contents()->GetURL().SchemeIs(url::kHttpScheme) && | 220 web_contents()->GetURL().SchemeIs(url::kHttpScheme) && |
212 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); | 221 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); |
213 } | 222 } |
214 | 223 |
215 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 224 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
216 } | 225 } |
217 | 226 |
218 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) { | 227 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) { |
219 if (page_cmd == "\"pageLoadComplete\"") { | 228 if (page_cmd == "\"pageLoadComplete\"") { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 void SafeBrowsingBlockingPage::OverrideRendererPrefs( | 350 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
342 content::RendererPreferences* prefs) { | 351 content::RendererPreferences* prefs) { |
343 Profile* profile = Profile::FromBrowserContext( | 352 Profile* profile = Profile::FromBrowserContext( |
344 web_contents()->GetBrowserContext()); | 353 web_contents()->GetBrowserContext()); |
345 renderer_preferences_util::UpdateFromSystemSettings( | 354 renderer_preferences_util::UpdateFromSystemSettings( |
346 prefs, profile, web_contents()); | 355 prefs, profile, web_contents()); |
347 } | 356 } |
348 | 357 |
349 void SafeBrowsingBlockingPage::OnProceed() { | 358 void SafeBrowsingBlockingPage::OnProceed() { |
350 proceeded_ = true; | 359 proceeded_ = true; |
351 // Send the malware details, if we opted to. | 360 // Send the threat details, if we opted to. |
352 FinishThreatDetails(malware_details_proceed_delay_ms_, true, /* did_proceed */ | 361 FinishThreatDetails(malware_details_proceed_delay_ms_, true, /* did_proceed */ |
353 metrics_helper()->NumVisits()); | 362 metrics_helper()->NumVisits()); |
354 | 363 |
355 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); | 364 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); |
356 | 365 |
357 // Check to see if some new notifications of unsafe resources have been | 366 // Check to see if some new notifications of unsafe resources have been |
358 // received while we were showing the interstitial. | 367 // received while we were showing the interstitial. |
359 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 368 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
360 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); | 369 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents()); |
361 SafeBrowsingBlockingPage* blocking_page = NULL; | 370 SafeBrowsingBlockingPage* blocking_page = NULL; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 CHECK(web_contents()->GetController().RemoveEntryAtIndex( | 431 CHECK(web_contents()->GetController().RemoveEntryAtIndex( |
423 navigation_entry_index_to_remove_)); | 432 navigation_entry_index_to_remove_)); |
424 navigation_entry_index_to_remove_ = -1; | 433 navigation_entry_index_to_remove_ = -1; |
425 } | 434 } |
426 } | 435 } |
427 | 436 |
428 void SafeBrowsingBlockingPage::FinishThreatDetails(int64 delay_ms, | 437 void SafeBrowsingBlockingPage::FinishThreatDetails(int64 delay_ms, |
429 bool did_proceed, | 438 bool did_proceed, |
430 int num_visits) { | 439 int num_visits) { |
431 if (threat_details_.get() == NULL) | 440 if (threat_details_.get() == NULL) |
432 return; // Not all interstitials have malware details (eg phishing). | 441 return; // Not all interstitials have threat details (eg., incognito mode). |
433 DCHECK_EQ(interstitial_reason_, SB_REASON_MALWARE); | |
434 | 442 |
435 const bool enabled = | 443 const bool enabled = |
436 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled) && | 444 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled) && |
437 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed); | 445 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed); |
438 if (!enabled) | 446 if (!enabled) |
439 return; | 447 return; |
440 | 448 |
441 metrics_helper()->RecordUserInteraction( | 449 metrics_helper()->RecordUserInteraction( |
442 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); | 450 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED); |
443 // Finish the malware details collection, send it over. | 451 // Finish the malware details collection, send it over. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 break; | 617 break; |
610 case SB_REASON_PHISHING: | 618 case SB_REASON_PHISHING: |
611 PopulatePhishingLoadTimeData(load_time_data); | 619 PopulatePhishingLoadTimeData(load_time_data); |
612 break; | 620 break; |
613 } | 621 } |
614 } | 622 } |
615 | 623 |
616 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( | 624 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption( |
617 base::DictionaryValue* load_time_data) { | 625 base::DictionaryValue* load_time_data) { |
618 // Only show checkbox if !(HTTPS || incognito-mode). | 626 // Only show checkbox if !(HTTPS || incognito-mode). |
619 const bool show = CanShowMalwareDetailsOption(); | 627 const bool show = CanShowThreatDetailsOption(); |
620 load_time_data->SetBoolean(interstitials::kDisplayCheckBox, show); | 628 load_time_data->SetBoolean(interstitials::kDisplayCheckBox, show); |
621 if (!show) | 629 if (!show) |
622 return; | 630 return; |
623 | 631 |
624 const std::string privacy_link = base::StringPrintf( | 632 const std::string privacy_link = base::StringPrintf( |
625 interstitials::kPrivacyLinkHtml, CMD_OPEN_REPORTING_PRIVACY, | 633 interstitials::kPrivacyLinkHtml, CMD_OPEN_REPORTING_PRIVACY, |
626 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); | 634 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); |
627 load_time_data->SetString( | 635 load_time_data->SetString( |
628 interstitials::kOptInLink, | 636 interstitials::kOptInLink, |
629 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, | 637 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( | 717 "finalParagraph", l10n_util::GetStringUTF16( |
710 IDS_PHISHING_V4_PROCEED_AND_REPORT_PARAGRAPH)); | 718 IDS_PHISHING_V4_PROCEED_AND_REPORT_PARAGRAPH)); |
711 } else { | 719 } else { |
712 load_time_data->SetString( | 720 load_time_data->SetString( |
713 "finalParagraph", | 721 "finalParagraph", |
714 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 722 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
715 } | 723 } |
716 | 724 |
717 PopulateExtendedReportingOption(load_time_data); | 725 PopulateExtendedReportingOption(load_time_data); |
718 } | 726 } |
OLD | NEW |