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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 const string16& title, | 233 const string16& title, |
234 const string16& headline, | 234 const string16& headline, |
235 const string16& description1, | 235 const string16& description1, |
236 const string16& description2, | 236 const string16& description2, |
237 const string16& description3) { | 237 const string16& description3) { |
238 strings->SetString("title", title); | 238 strings->SetString("title", title); |
239 strings->SetString("headLine", headline); | 239 strings->SetString("headLine", headline); |
240 strings->SetString("description1", description1); | 240 strings->SetString("description1", description1); |
241 strings->SetString("description2", description2); | 241 strings->SetString("description2", description2); |
242 strings->SetString("description3", description3); | 242 strings->SetString("description3", description3); |
243 strings->SetBoolean("proceedDisabled", | |
244 IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); | |
245 } | 243 } |
246 | 244 |
247 void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( | 245 void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( |
248 DictionaryValue* strings) { | 246 DictionaryValue* strings) { |
249 bool malware = false; | 247 bool malware = false; |
250 bool phishing = false; | 248 bool phishing = false; |
251 | 249 |
252 string16 malware_label = | 250 string16 malware_label = |
253 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LABEL); | 251 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LABEL); |
254 string16 malware_link = | 252 string16 malware_link = |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 382 |
385 std::string privacy_link = base::StringPrintf( | 383 std::string privacy_link = base::StringPrintf( |
386 kPrivacyLinkHtml, | 384 kPrivacyLinkHtml, |
387 l10n_util::GetStringUTF8( | 385 l10n_util::GetStringUTF8( |
388 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); | 386 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); |
389 | 387 |
390 strings->SetString("confirm_text", | 388 strings->SetString("confirm_text", |
391 l10n_util::GetStringFUTF16( | 389 l10n_util::GetStringFUTF16( |
392 IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, | 390 IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, |
393 UTF8ToUTF16(privacy_link))); | 391 UTF8ToUTF16(privacy_link))); |
394 if (IsPrefEnabled(prefs::kSafeBrowsingReportingEnabled)) | 392 |
| 393 Profile* profile = Profile::FromBrowserContext( |
| 394 web_contents_->GetBrowserContext()); |
| 395 const PrefService::Preference* pref = |
| 396 profile->GetPrefs()->FindPreference( |
| 397 prefs::kSafeBrowsingReportingEnabled); |
| 398 |
| 399 bool value; |
| 400 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { |
395 strings->SetString(kBoxChecked, "yes"); | 401 strings->SetString(kBoxChecked, "yes"); |
396 else | 402 } else { |
397 strings->SetString(kBoxChecked, ""); | 403 strings->SetString(kBoxChecked, ""); |
| 404 } |
398 } | 405 } |
399 } | 406 } |
400 | 407 |
401 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( | 408 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( |
402 DictionaryValue* strings) { | 409 DictionaryValue* strings) { |
403 std::string proceed_link = base::StringPrintf( | 410 std::string proceed_link = base::StringPrintf( |
404 kPLinkHtml, | 411 kPLinkHtml, |
405 l10n_util::GetStringUTF8( | 412 l10n_util::GetStringUTF8( |
406 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); | 413 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); |
407 string16 description3 = l10n_util::GetStringFUTF16( | 414 string16 description3 = l10n_util::GetStringFUTF16( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 470 |
464 if (command == kShowPrivacyCommand) { | 471 if (command == kShowPrivacyCommand) { |
465 // User pressed "Safe Browsing privacy policy". | 472 // User pressed "Safe Browsing privacy policy". |
466 GURL url(kSbPrivacyPolicyUrl); | 473 GURL url(kSbPrivacyPolicyUrl); |
467 OpenURLParams params( | 474 OpenURLParams params( |
468 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | 475 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); |
469 web_contents_->OpenURL(params); | 476 web_contents_->OpenURL(params); |
470 return; | 477 return; |
471 } | 478 } |
472 | 479 |
473 bool proceed_blocked = false; | |
474 if (command == kProceedCommand) { | 480 if (command == kProceedCommand) { |
475 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { | 481 interstitial_page_->Proceed(); |
476 proceed_blocked = true; | 482 // We are deleted after this. |
477 } else { | 483 return; |
478 interstitial_page_->Proceed(); | |
479 // |this| has been deleted after Proceed() returns. | |
480 return; | |
481 } | |
482 } | 484 } |
483 | 485 |
484 if (command == kTakeMeBackCommand || proceed_blocked) { | 486 if (command == kTakeMeBackCommand) { |
485 if (is_main_frame_load_blocked_) { | 487 if (is_main_frame_load_blocked_) { |
486 // If the load is blocked, we want to close the interstitial and discard | 488 // If the load is blocked, we want to close the interstitial and discard |
487 // the pending entry. | 489 // the pending entry. |
488 interstitial_page_->DontProceed(); | 490 interstitial_page_->DontProceed(); |
489 // |this| has been deleted after DontProceed() returns. | 491 // We are deleted after this. |
490 return; | 492 return; |
491 } | 493 } |
492 | 494 |
493 // Otherwise the offending entry has committed, and we need to go back or | 495 // Otherwise the offending entry has committed, and we need to go back or |
494 // to a safe page. We will close the interstitial when that page commits. | 496 // to a safe page. We will close the interstitial when that page commits. |
495 if (web_contents_->GetController().CanGoBack()) { | 497 if (web_contents_->GetController().CanGoBack()) { |
496 web_contents_->GetController().GoBack(); | 498 web_contents_->GetController().GoBack(); |
497 } else { | 499 } else { |
498 web_contents_->GetController().LoadURL( | 500 web_contents_->GetController().LoadURL( |
499 GURL(chrome::kChromeUINewTabURL), | 501 GURL(chrome::kChromeUINewTabURL), |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 } | 671 } |
670 | 672 |
671 switch (event) { | 673 switch (event) { |
672 case SHOW: | 674 case SHOW: |
673 action.append("Show"); | 675 action.append("Show"); |
674 break; | 676 break; |
675 case PROCEED: | 677 case PROCEED: |
676 action.append("Proceed"); | 678 action.append("Proceed"); |
677 break; | 679 break; |
678 case DONT_PROCEED: | 680 case DONT_PROCEED: |
679 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) | 681 action.append("DontProceed"); |
680 action.append("ForcedDontProceed"); | |
681 else | |
682 action.append("DontProceed"); | |
683 break; | 682 break; |
684 default: | 683 default: |
685 NOTREACHED() << "Unexpected event: " << event; | 684 NOTREACHED() << "Unexpected event: " << event; |
686 } | 685 } |
687 | 686 |
688 content::RecordComputedAction(action); | 687 content::RecordComputedAction(action); |
689 } | 688 } |
690 | 689 |
691 void SafeBrowsingBlockingPage::RecordUserReactionTime( | 690 void SafeBrowsingBlockingPage::RecordUserReactionTime( |
692 const std::string& command) { | 691 const std::string& command) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 732 } |
734 } | 733 } |
735 if (recorded) // Making sure we don't double-count reaction times. | 734 if (recorded) // Making sure we don't double-count reaction times. |
736 interstitial_show_time_ = base::TimeTicks(); // Resets the show time. | 735 interstitial_show_time_ = base::TimeTicks(); // Resets the show time. |
737 } | 736 } |
738 | 737 |
739 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { | 738 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { |
740 if (malware_details_ == NULL) | 739 if (malware_details_ == NULL) |
741 return; // Not all interstitials have malware details (eg phishing). | 740 return; // Not all interstitials have malware details (eg phishing). |
742 | 741 |
743 if (IsPrefEnabled(prefs::kSafeBrowsingReportingEnabled)) { | 742 Profile* profile = Profile::FromBrowserContext( |
| 743 web_contents_->GetBrowserContext()); |
| 744 const PrefService::Preference* pref = |
| 745 profile->GetPrefs()->FindPreference(prefs::kSafeBrowsingReportingEnabled); |
| 746 |
| 747 bool value; |
| 748 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { |
744 // Finish the malware details collection, send it over. | 749 // Finish the malware details collection, send it over. |
745 BrowserThread::PostDelayedTask( | 750 BrowserThread::PostDelayedTask( |
746 BrowserThread::IO, FROM_HERE, | 751 BrowserThread::IO, FROM_HERE, |
747 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), | 752 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), |
748 base::TimeDelta::FromMilliseconds(delay_ms)); | 753 base::TimeDelta::FromMilliseconds(delay_ms)); |
749 } | 754 } |
750 } | 755 } |
751 | 756 |
752 bool SafeBrowsingBlockingPage::IsPrefEnabled(const char* pref) { | |
753 Profile* profile = | |
754 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
755 return profile->GetPrefs()->GetBoolean(pref); | |
756 } | |
757 | |
758 // static | 757 // static |
759 void SafeBrowsingBlockingPage::NotifySafeBrowsingService( | 758 void SafeBrowsingBlockingPage::NotifySafeBrowsingService( |
760 SafeBrowsingService* sb_service, | 759 SafeBrowsingService* sb_service, |
761 const UnsafeResourceList& unsafe_resources, | 760 const UnsafeResourceList& unsafe_resources, |
762 bool proceed) { | 761 bool proceed) { |
763 BrowserThread::PostTask( | 762 BrowserThread::PostTask( |
764 BrowserThread::IO, FROM_HERE, | 763 BrowserThread::IO, FROM_HERE, |
765 base::Bind(&SafeBrowsingService::OnBlockingPageDone, | 764 base::Bind(&SafeBrowsingService::OnBlockingPageDone, |
766 sb_service, unsafe_resources, proceed)); | 765 sb_service, unsafe_resources, proceed)); |
767 } | 766 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 // Client-side phishing detection interstitials never block the main frame | 814 // Client-side phishing detection interstitials never block the main frame |
816 // load, since they happen after the page is finished loading. | 815 // load, since they happen after the page is finished loading. |
817 if (unsafe_resources[0].threat_type == | 816 if (unsafe_resources[0].threat_type == |
818 SafeBrowsingService::CLIENT_SIDE_PHISHING_URL) { | 817 SafeBrowsingService::CLIENT_SIDE_PHISHING_URL) { |
819 return false; | 818 return false; |
820 } | 819 } |
821 | 820 |
822 // Otherwise, check the threat type. | 821 // Otherwise, check the threat type. |
823 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; | 822 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; |
824 } | 823 } |
OLD | NEW |