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