OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 |
11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/browser_thread.h" | 17 #include "chrome/browser/browser_thread.h" |
18 #include "chrome/browser/dom_operation_notification_details.h" | 18 #include "chrome/browser/dom_operation_notification_details.h" |
19 #include "chrome/browser/dom_ui/new_tab_ui.h" | 19 #include "chrome/browser/dom_ui/new_tab_ui.h" |
20 #include "chrome/browser/google/google_util.h" | 20 #include "chrome/browser/google/google_util.h" |
21 #include "chrome/browser/metrics/user_metrics.h" | 21 #include "chrome/browser/metrics/user_metrics.h" |
22 #include "chrome/browser/profile.h" | |
23 #include "chrome/browser/prefs/pref_service.h" | |
22 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 24 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
25 #include "chrome/browser/safe_browsing/malware_report.h" | |
23 #include "chrome/browser/tab_contents/navigation_controller.h" | 26 #include "chrome/browser/tab_contents/navigation_controller.h" |
24 #include "chrome/browser/tab_contents/navigation_entry.h" | 27 #include "chrome/browser/tab_contents/navigation_entry.h" |
25 #include "chrome/browser/tab_contents/tab_util.h" | 28 #include "chrome/browser/tab_contents/tab_util.h" |
26 #include "chrome/browser/tab_contents/tab_contents.h" | 29 #include "chrome/browser/tab_contents/tab_contents.h" |
27 #include "chrome/common/jstemplate_builder.h" | 30 #include "chrome/common/jstemplate_builder.h" |
31 #include "chrome/common/pref_names.h" | |
28 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
29 #include "grit/browser_resources.h" | 33 #include "grit/browser_resources.h" |
30 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
31 #include "grit/locale_settings.h" | 35 #include "grit/locale_settings.h" |
32 #include "net/base/escape.h" | 36 #include "net/base/escape.h" |
33 | 37 |
34 // For malware interstitial pages, we link the problematic URL to Google's | 38 // For malware interstitial pages, we link the problematic URL to Google's |
35 // diagnostic page. | 39 // diagnostic page. |
36 #if defined(GOOGLE_CHROME_BUILD) | 40 #if defined(GOOGLE_CHROME_BUILD) |
37 static const char* const kSbDiagnosticUrl = | 41 static const char* const kSbDiagnosticUrl = |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 | 98 |
95 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( | 99 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( |
96 SafeBrowsingService* sb_service, | 100 SafeBrowsingService* sb_service, |
97 TabContents* tab_contents, | 101 TabContents* tab_contents, |
98 const UnsafeResourceList& unsafe_resources) | 102 const UnsafeResourceList& unsafe_resources) |
99 : InterstitialPage(tab_contents, | 103 : InterstitialPage(tab_contents, |
100 IsMainPage(unsafe_resources), | 104 IsMainPage(unsafe_resources), |
101 unsafe_resources[0].url), | 105 unsafe_resources[0].url), |
102 sb_service_(sb_service), | 106 sb_service_(sb_service), |
103 is_main_frame_(IsMainPage(unsafe_resources)), | 107 is_main_frame_(IsMainPage(unsafe_resources)), |
104 unsafe_resources_(unsafe_resources) { | 108 unsafe_resources_(unsafe_resources), |
109 malware_report_(NULL) { | |
105 RecordUserAction(SHOW); | 110 RecordUserAction(SHOW); |
106 if (!is_main_frame_) { | 111 if (!is_main_frame_) { |
107 navigation_entry_index_to_remove_ = | 112 navigation_entry_index_to_remove_ = |
108 tab()->controller().last_committed_entry_index(); | 113 tab()->controller().last_committed_entry_index(); |
109 } else { | 114 } else { |
110 navigation_entry_index_to_remove_ = -1; | 115 navigation_entry_index_to_remove_ = -1; |
111 } | 116 } |
117 | |
118 // Start computing an advanced malware report. It will be sent only | |
119 // if the user opts-in on the blocking page later. | |
120 if (unsafe_resources.size() == 1 && | |
121 unsafe_resources[0].threat_type == SafeBrowsingService::URL_MALWARE && | |
122 malware_report_ == NULL && | |
123 !tab()->profile()->IsOffTheRecord()) { | |
124 malware_report_ = new SafeBrowsingMalwareReport(tab(), unsafe_resources[0]); | |
125 } | |
112 } | 126 } |
113 | 127 |
114 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 128 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
115 } | 129 } |
116 | 130 |
117 std::string SafeBrowsingBlockingPage::GetHTMLContents() { | 131 std::string SafeBrowsingBlockingPage::GetHTMLContents() { |
118 // Load the HTML page and create the template components. | 132 // Load the HTML page and create the template components. |
119 DictionaryValue strings; | 133 DictionaryValue strings; |
120 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 134 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
121 std::string html; | 135 std::string html; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 SafeBrowsingService::URL_MALWARE); | 397 SafeBrowsingService::URL_MALWARE); |
384 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 398 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
385 return; | 399 return; |
386 } | 400 } |
387 | 401 |
388 NOTREACHED() << "Unexpected command: " << command; | 402 NOTREACHED() << "Unexpected command: " << command; |
389 } | 403 } |
390 | 404 |
391 void SafeBrowsingBlockingPage::Proceed() { | 405 void SafeBrowsingBlockingPage::Proceed() { |
392 RecordUserAction(PROCEED); | 406 RecordUserAction(PROCEED); |
407 FinishMalwareReport(); // Send the malware report, if we opted to. | |
393 | 408 |
394 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); | 409 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); |
395 | 410 |
396 // Check to see if some new notifications of unsafe resources have been | 411 // Check to see if some new notifications of unsafe resources have been |
397 // received while we were showing the interstitial. | 412 // received while we were showing the interstitial. |
398 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 413 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
399 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 414 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); |
400 SafeBrowsingBlockingPage* blocking_page = NULL; | 415 SafeBrowsingBlockingPage* blocking_page = NULL; |
401 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 416 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
402 // Build an interstitial for all the unsafe resources notifications. | 417 // Build an interstitial for all the unsafe resources notifications. |
(...skipping 17 matching lines...) Expand all Loading... | |
420 // We could have already called Proceed(), in which case we must not notify | 435 // We could have already called Proceed(), in which case we must not notify |
421 // the SafeBrowsingService again, as the client has been deleted. | 436 // the SafeBrowsingService again, as the client has been deleted. |
422 if (action_taken() == PROCEED_ACTION) { | 437 if (action_taken() == PROCEED_ACTION) { |
423 // We still want to hide the interstitial page. | 438 // We still want to hide the interstitial page. |
424 InterstitialPage::DontProceed(); | 439 InterstitialPage::DontProceed(); |
425 // We are now deleted. | 440 // We are now deleted. |
426 return; | 441 return; |
427 } | 442 } |
428 | 443 |
429 RecordUserAction(DONT_PROCEED); | 444 RecordUserAction(DONT_PROCEED); |
445 FinishMalwareReport(); // Send the malware report, if we opted to. | |
430 | 446 |
431 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); | 447 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); |
432 | 448 |
433 // The user does not want to proceed, clear the queued unsafe resources | 449 // The user does not want to proceed, clear the queued unsafe resources |
434 // notifications we received while the interstitial was showing. | 450 // notifications we received while the interstitial was showing. |
435 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 451 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
436 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 452 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); |
437 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 453 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
438 NotifySafeBrowsingService(sb_service_, iter->second, false); | 454 NotifySafeBrowsingService(sb_service_, iter->second, false); |
439 unsafe_resource_map->erase(iter); | 455 unsafe_resource_map->erase(iter); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 case DONT_PROCEED: | 501 case DONT_PROCEED: |
486 action.append("DontProceed"); | 502 action.append("DontProceed"); |
487 break; | 503 break; |
488 default: | 504 default: |
489 NOTREACHED() << "Unexpected event: " << event; | 505 NOTREACHED() << "Unexpected event: " << event; |
490 } | 506 } |
491 | 507 |
492 UserMetrics::RecordComputedAction(action); | 508 UserMetrics::RecordComputedAction(action); |
493 } | 509 } |
494 | 510 |
511 void SafeBrowsingBlockingPage::FinishMalwareReport() { | |
512 if (malware_report_ == NULL) { | |
513 // Not all interstitials have reports (eg phishing). | |
514 return; | |
515 } | |
516 | |
517 // Q: Reading from the preference -- should it happen in another thread? | |
lzheng
2010/11/16 00:18:12
It has to be called on the same thread where pref
panayiotis
2010/11/18 22:04:37
thanks.
| |
518 const PrefService::Preference* pref = | |
519 tab()->profile()->GetPrefs()->FindPreference( | |
520 prefs::kSafeBrowsingMalwareReportsEnabled); | |
521 | |
522 bool value; | |
523 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { | |
524 // Give the report object to the service class, so it can send it. | |
525 BrowserThread::PostTask( | |
526 BrowserThread::IO, FROM_HERE, | |
527 NewRunnableMethod( | |
528 sb_service_, &SafeBrowsingService::SendMalwareReport, | |
529 malware_report_)); | |
530 } | |
531 } | |
532 | |
495 // static | 533 // static |
496 void SafeBrowsingBlockingPage::NotifySafeBrowsingService( | 534 void SafeBrowsingBlockingPage::NotifySafeBrowsingService( |
497 SafeBrowsingService* sb_service, | 535 SafeBrowsingService* sb_service, |
498 const UnsafeResourceList& unsafe_resources, | 536 const UnsafeResourceList& unsafe_resources, |
499 bool proceed) { | 537 bool proceed) { |
500 BrowserThread::PostTask( | 538 BrowserThread::PostTask( |
501 BrowserThread::IO, FROM_HERE, | 539 BrowserThread::IO, FROM_HERE, |
502 NewRunnableMethod( | 540 NewRunnableMethod( |
503 sb_service, &SafeBrowsingService::OnBlockingPageDone, | 541 sb_service, &SafeBrowsingService::OnBlockingPageDone, |
504 unsafe_resources, proceed)); | 542 unsafe_resources, proceed)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 585 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
548 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); | 586 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); |
549 } | 587 } |
550 | 588 |
551 // static | 589 // static |
552 bool SafeBrowsingBlockingPage::IsMainPage( | 590 bool SafeBrowsingBlockingPage::IsMainPage( |
553 const UnsafeResourceList& unsafe_resources) { | 591 const UnsafeResourceList& unsafe_resources) { |
554 return unsafe_resources.size() == 1 && | 592 return unsafe_resources.size() == 1 && |
555 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; | 593 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; |
556 } | 594 } |
OLD | NEW |