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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 const string16& title, | 224 const string16& title, |
225 const string16& headline, | 225 const string16& headline, |
226 const string16& description1, | 226 const string16& description1, |
227 const string16& description2, | 227 const string16& description2, |
228 const string16& description3) { | 228 const string16& description3) { |
229 strings->SetString("title", title); | 229 strings->SetString("title", title); |
230 strings->SetString("headLine", headline); | 230 strings->SetString("headLine", headline); |
231 strings->SetString("description1", description1); | 231 strings->SetString("description1", description1); |
232 strings->SetString("description2", description2); | 232 strings->SetString("description2", description2); |
233 strings->SetString("description3", description3); | 233 strings->SetString("description3", description3); |
234 strings->SetBoolean("proceedDisabled", | |
235 IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); | |
234 } | 236 } |
235 | 237 |
236 void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( | 238 void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( |
237 DictionaryValue* strings) { | 239 DictionaryValue* strings) { |
238 bool malware = false; | 240 bool malware = false; |
239 bool phishing = false; | 241 bool phishing = false; |
240 | 242 |
241 string16 malware_label = | 243 string16 malware_label = |
242 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LABEL); | 244 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LABEL); |
243 string16 malware_link = | 245 string16 malware_link = |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 | 375 |
374 std::string privacy_link = base::StringPrintf( | 376 std::string privacy_link = base::StringPrintf( |
375 kPrivacyLinkHtml, | 377 kPrivacyLinkHtml, |
376 l10n_util::GetStringUTF8( | 378 l10n_util::GetStringUTF8( |
377 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); | 379 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); |
378 | 380 |
379 strings->SetString("confirm_text", | 381 strings->SetString("confirm_text", |
380 l10n_util::GetStringFUTF16( | 382 l10n_util::GetStringFUTF16( |
381 IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, | 383 IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, |
382 UTF8ToUTF16(privacy_link))); | 384 UTF8ToUTF16(privacy_link))); |
383 | 385 if (IsPrefEnabled(prefs::kSafeBrowsingReportingEnabled)) |
384 Profile* profile = Profile::FromBrowserContext( | |
385 web_contents_->GetBrowserContext()); | |
386 const PrefService::Preference* pref = | |
387 profile->GetPrefs()->FindPreference( | |
388 prefs::kSafeBrowsingReportingEnabled); | |
389 | |
390 bool value; | |
391 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { | |
392 strings->SetString(kBoxChecked, "yes"); | 386 strings->SetString(kBoxChecked, "yes"); |
393 } else { | 387 else |
394 strings->SetString(kBoxChecked, ""); | 388 strings->SetString(kBoxChecked, ""); |
395 } | |
396 } | 389 } |
397 } | 390 } |
398 | 391 |
399 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( | 392 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( |
400 DictionaryValue* strings) { | 393 DictionaryValue* strings) { |
401 std::string proceed_link = base::StringPrintf( | 394 std::string proceed_link = base::StringPrintf( |
402 kPLinkHtml, | 395 kPLinkHtml, |
403 l10n_util::GetStringUTF8( | 396 l10n_util::GetStringUTF8( |
404 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); | 397 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); |
405 string16 description3 = l10n_util::GetStringFUTF16( | 398 string16 description3 = l10n_util::GetStringFUTF16( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 | 454 |
462 if (command == kShowPrivacyCommand) { | 455 if (command == kShowPrivacyCommand) { |
463 // User pressed "Safe Browsing privacy policy". | 456 // User pressed "Safe Browsing privacy policy". |
464 GURL url(kSbPrivacyPolicyUrl); | 457 GURL url(kSbPrivacyPolicyUrl); |
465 OpenURLParams params( | 458 OpenURLParams params( |
466 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | 459 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); |
467 web_contents_->OpenURL(params); | 460 web_contents_->OpenURL(params); |
468 return; | 461 return; |
469 } | 462 } |
470 | 463 |
464 bool proceed_blocked = false; | |
471 if (command == kProceedCommand) { | 465 if (command == kProceedCommand) { |
472 interstitial_page_->Proceed(); | 466 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { |
473 // We are deleted after this. | 467 proceed_blocked = true; |
474 return; | 468 } else { |
469 interstitial_page_->Proceed(); | |
470 // |this| has been deleted after Proceed() returns. | |
471 return; | |
472 } | |
475 } | 473 } |
476 | 474 |
477 if (command == kTakeMeBackCommand) { | 475 if (command == kTakeMeBackCommand || proceed_blocked) { |
478 if (is_main_frame_load_blocked_) { | 476 if (is_main_frame_load_blocked_) { |
479 // If the load is blocked, we want to close the interstitial and discard | 477 // If the load is blocked, we want to close the interstitial and discard |
480 // the pending entry. | 478 // the pending entry. |
481 interstitial_page_->DontProceed(); | 479 interstitial_page_->DontProceed(); |
482 // We are deleted after this. | 480 // |this| has been deleted after DontProceed() returns. |
483 return; | 481 return; |
484 } | 482 } |
485 | 483 |
486 // Otherwise the offending entry has committed, and we need to go back or | 484 // Otherwise the offending entry has committed, and we need to go back or |
487 // to a safe page. We will close the interstitial when that page commits. | 485 // to a safe page. We will close the interstitial when that page commits. |
488 if (web_contents_->GetController().CanGoBack()) { | 486 if (web_contents_->GetController().CanGoBack()) { |
489 web_contents_->GetController().GoBack(); | 487 web_contents_->GetController().GoBack(); |
490 } else { | 488 } else { |
491 web_contents_->GetController().LoadURL( | 489 web_contents_->GetController().LoadURL( |
492 GURL(chrome::kChromeUINewTabURL), | 490 GURL(chrome::kChromeUINewTabURL), |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 if (blocking_page) | 594 if (blocking_page) |
597 blocking_page->interstitial_page_->Show(); | 595 blocking_page->interstitial_page_->Show(); |
598 } | 596 } |
599 | 597 |
600 void SafeBrowsingBlockingPage::OnDontProceed() { | 598 void SafeBrowsingBlockingPage::OnDontProceed() { |
601 // We could have already called Proceed(), in which case we must not notify | 599 // We could have already called Proceed(), in which case we must not notify |
602 // the SafeBrowsingService again, as the client has been deleted. | 600 // the SafeBrowsingService again, as the client has been deleted. |
603 if (proceeded_) | 601 if (proceeded_) |
604 return; | 602 return; |
605 | 603 |
606 RecordUserAction(DONT_PROCEED); | 604 RecordUserAction(DONT_PROCEED); |
mattm
2012/07/02 21:47:00
Probably want to split this into two user metrics,
Joao da Silva
2012/07/03 13:39:52
Done. Please have a look at the changes in chrome/
mattm
2012/07/03 19:41:34
Yep, I think that just means someone added some me
| |
607 // Send the malware details, if we opted to. | 605 // Send the malware details, if we opted to. |
608 FinishMalwareDetails(0); // No delay | 606 FinishMalwareDetails(0); // No delay |
609 | 607 |
610 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); | 608 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); |
611 | 609 |
612 // The user does not want to proceed, clear the queued unsafe resources | 610 // The user does not want to proceed, clear the queued unsafe resources |
613 // notifications we received while the interstitial was showing. | 611 // notifications we received while the interstitial was showing. |
614 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 612 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
615 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_); | 613 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_); |
616 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 614 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 NOTREACHED() << "Unexpected event: " << event; | 671 NOTREACHED() << "Unexpected event: " << event; |
674 } | 672 } |
675 | 673 |
676 content::RecordComputedAction(action); | 674 content::RecordComputedAction(action); |
677 } | 675 } |
678 | 676 |
679 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { | 677 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { |
680 if (malware_details_ == NULL) | 678 if (malware_details_ == NULL) |
681 return; // Not all interstitials have malware details (eg phishing). | 679 return; // Not all interstitials have malware details (eg phishing). |
682 | 680 |
683 Profile* profile = Profile::FromBrowserContext( | 681 if (IsPrefEnabled(prefs::kSafeBrowsingReportingEnabled)) { |
684 web_contents_->GetBrowserContext()); | |
685 const PrefService::Preference* pref = | |
686 profile->GetPrefs()->FindPreference(prefs::kSafeBrowsingReportingEnabled); | |
687 | |
688 bool value; | |
689 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { | |
690 // Finish the malware details collection, send it over. | 682 // Finish the malware details collection, send it over. |
691 BrowserThread::PostDelayedTask( | 683 BrowserThread::PostDelayedTask( |
692 BrowserThread::IO, FROM_HERE, | 684 BrowserThread::IO, FROM_HERE, |
693 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), | 685 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), |
694 base::TimeDelta::FromMilliseconds(delay_ms)); | 686 base::TimeDelta::FromMilliseconds(delay_ms)); |
695 } | 687 } |
696 } | 688 } |
697 | 689 |
690 bool SafeBrowsingBlockingPage::IsPrefEnabled(const char* pref) { | |
691 Profile* profile = | |
692 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
693 return profile->GetPrefs()->GetBoolean(pref); | |
694 } | |
695 | |
698 // static | 696 // static |
699 void SafeBrowsingBlockingPage::NotifySafeBrowsingService( | 697 void SafeBrowsingBlockingPage::NotifySafeBrowsingService( |
700 SafeBrowsingService* sb_service, | 698 SafeBrowsingService* sb_service, |
701 const UnsafeResourceList& unsafe_resources, | 699 const UnsafeResourceList& unsafe_resources, |
702 bool proceed) { | 700 bool proceed) { |
703 BrowserThread::PostTask( | 701 BrowserThread::PostTask( |
704 BrowserThread::IO, FROM_HERE, | 702 BrowserThread::IO, FROM_HERE, |
705 base::Bind(&SafeBrowsingService::OnBlockingPageDone, | 703 base::Bind(&SafeBrowsingService::OnBlockingPageDone, |
706 sb_service, unsafe_resources, proceed)); | 704 sb_service, unsafe_resources, proceed)); |
707 } | 705 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 // Client-side phishing detection interstitials never block the main frame | 753 // Client-side phishing detection interstitials never block the main frame |
756 // load, since they happen after the page is finished loading. | 754 // load, since they happen after the page is finished loading. |
757 if (unsafe_resources[0].threat_type == | 755 if (unsafe_resources[0].threat_type == |
758 SafeBrowsingService::CLIENT_SIDE_PHISHING_URL) { | 756 SafeBrowsingService::CLIENT_SIDE_PHISHING_URL) { |
759 return false; | 757 return false; |
760 } | 758 } |
761 | 759 |
762 // Otherwise, check the threat type. | 760 // Otherwise, check the threat type. |
763 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; | 761 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; |
764 } | 762 } |
OLD | NEW |