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_process.h" | |
17 #include "chrome/browser/browser_thread.h" | 18 #include "chrome/browser/browser_thread.h" |
18 #include "chrome/browser/dom_operation_notification_details.h" | 19 #include "chrome/browser/dom_operation_notification_details.h" |
19 #include "chrome/browser/dom_ui/new_tab_ui.h" | 20 #include "chrome/browser/dom_ui/new_tab_ui.h" |
20 #include "chrome/browser/google/google_util.h" | 21 #include "chrome/browser/google/google_util.h" |
21 #include "chrome/browser/metrics/user_metrics.h" | 22 #include "chrome/browser/metrics/user_metrics.h" |
23 #include "chrome/browser/prefs/pref_service.h" | |
24 #include "chrome/browser/profile.h" | |
22 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 25 #include "chrome/browser/safe_browsing/safe_browsing_service.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 22 matching lines...) Loading... | |
60 static const wchar_t* const kPLinkHtml = | 64 static const wchar_t* const kPLinkHtml = |
61 L"<a href=\"\" onclick=\"sendCommand('proceed'); return false;\" " | 65 L"<a href=\"\" onclick=\"sendCommand('proceed'); return false;\" " |
62 L"onmousedown=\"return false;\">%ls</a>"; | 66 L"onmousedown=\"return false;\">%ls</a>"; |
63 | 67 |
64 // The commands returned by the page when the user performs an action. | 68 // The commands returned by the page when the user performs an action. |
65 static const char* const kShowDiagnosticCommand = "showDiagnostic"; | 69 static const char* const kShowDiagnosticCommand = "showDiagnostic"; |
66 static const char* const kReportErrorCommand = "reportError"; | 70 static const char* const kReportErrorCommand = "reportError"; |
67 static const char* const kLearnMoreCommand = "learnMore"; | 71 static const char* const kLearnMoreCommand = "learnMore"; |
68 static const char* const kProceedCommand = "proceed"; | 72 static const char* const kProceedCommand = "proceed"; |
69 static const char* const kTakeMeBackCommand = "takeMeBack"; | 73 static const char* const kTakeMeBackCommand = "takeMeBack"; |
74 static const char* const kDoReportCommand = "doReport"; | |
75 static const char* const kDontReportCommand = "dontReport"; | |
70 | 76 |
71 // static | 77 // static |
72 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 78 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
73 | 79 |
74 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 80 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
75 // don't leak it. | 81 // don't leak it. |
76 class SafeBrowsingBlockingPageFactoryImpl | 82 class SafeBrowsingBlockingPageFactoryImpl |
77 : public SafeBrowsingBlockingPageFactory { | 83 : public SafeBrowsingBlockingPageFactory { |
78 public: | 84 public: |
79 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 85 SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
(...skipping 24 matching lines...) Loading... | |
104 unsafe_resources_(unsafe_resources) { | 110 unsafe_resources_(unsafe_resources) { |
105 RecordUserAction(SHOW); | 111 RecordUserAction(SHOW); |
106 if (!is_main_frame_) { | 112 if (!is_main_frame_) { |
107 navigation_entry_index_to_remove_ = | 113 navigation_entry_index_to_remove_ = |
108 tab()->controller().last_committed_entry_index(); | 114 tab()->controller().last_committed_entry_index(); |
109 } else { | 115 } else { |
110 navigation_entry_index_to_remove_ = -1; | 116 navigation_entry_index_to_remove_ = -1; |
111 } | 117 } |
112 } | 118 } |
113 | 119 |
120 bool SafeBrowsingBlockingPage::CanShowMalwareReportOption() { | |
121 return (!tab()->profile()->IsOffTheRecord() && | |
122 tab()->GetURL().SchemeIs("http")); | |
123 } | |
124 | |
114 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 125 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
115 } | 126 } |
116 | 127 |
117 std::string SafeBrowsingBlockingPage::GetHTMLContents() { | 128 std::string SafeBrowsingBlockingPage::GetHTMLContents() { |
118 // Load the HTML page and create the template components. | 129 // Load the HTML page and create the template components. |
119 DictionaryValue strings; | 130 DictionaryValue strings; |
120 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 131 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
121 std::string html; | 132 std::string html; |
122 | 133 |
123 if (unsafe_resources_.empty()) { | 134 if (unsafe_resources_.empty()) { |
(...skipping 152 matching lines...) Loading... | |
276 | 287 |
277 strings->SetString("back_button", | 288 strings->SetString("back_button", |
278 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); | 289 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); |
279 strings->SetString("more_info_button", | 290 strings->SetString("more_info_button", |
280 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_MORE_INFO_BUTTON)); | 291 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_MORE_INFO_BUTTON)); |
281 strings->SetString("less_info_button", | 292 strings->SetString("less_info_button", |
282 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LESS_INFO_BUTTON)); | 293 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LESS_INFO_BUTTON)); |
283 strings->SetString("proceed_link", | 294 strings->SetString("proceed_link", |
284 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); | 295 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); |
285 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 296 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
297 | |
298 if (!CanShowMalwareReportOption()) { | |
299 strings->SetBoolean("displaycheckbox", false); | |
300 return; | |
301 } | |
302 | |
303 // show the checkbox about sending malware report | |
304 strings->SetBoolean("displaycheckbox", false); | |
lzheng
2010/11/23 01:14:49
nit: How about using a const char for "displaychec
| |
305 strings->SetString("confirm_text", | |
306 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE)); | |
307 | |
308 const PrefService::Preference* pref = | |
309 tab()->profile()->GetPrefs()->FindPreference( | |
310 prefs::kSafeBrowsingReportingEnabled); | |
311 bool value; | |
312 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { | |
313 strings->SetString("boxchecked", "yes"); | |
314 } else { | |
315 strings->SetString("boxchecked", ""); | |
316 } | |
286 } | 317 } |
287 | 318 |
288 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( | 319 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( |
289 DictionaryValue* strings) { | 320 DictionaryValue* strings) { |
290 PopulateStringDictionary( | 321 PopulateStringDictionary( |
291 strings, | 322 strings, |
292 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), | 323 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), |
293 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), | 324 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), |
294 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, | 325 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, |
295 UTF8ToWide(url().host())), | 326 UTF8ToWide(url().host())), |
296 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2, | 327 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2), |
297 UTF8ToWide(url().host())), | |
298 L""); | 328 L""); |
299 | 329 |
300 strings->SetString("continue_button", | 330 strings->SetString("continue_button", |
301 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_PROCEED_BUTTON)); | 331 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_PROCEED_BUTTON)); |
302 strings->SetString("back_button", | 332 strings->SetString("back_button", |
303 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON)); | 333 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON)); |
304 strings->SetString("report_error", | 334 strings->SetString("report_error", |
305 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR)); | 335 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR)); |
306 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 336 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
307 } | 337 } |
308 | 338 |
309 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { | 339 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { |
310 std::string command(cmd); // Make a local copy so we can modify it. | 340 std::string command(cmd); // Make a local copy so we can modify it. |
311 // The Jasonified response has quotes, remove them. | 341 // The Jasonified response has quotes, remove them. |
312 if (command.length() > 1 && command[0] == '"') { | 342 if (command.length() > 1 && command[0] == '"') { |
313 command = command.substr(1, command.length() - 2); | 343 command = command.substr(1, command.length() - 2); |
314 } | 344 } |
315 | 345 |
346 if (command == kDoReportCommand) { | |
347 SetReportingPreference(true); | |
348 return; | |
349 } | |
350 | |
351 if (command == kDontReportCommand) { | |
352 SetReportingPreference(false); | |
353 return; | |
354 } | |
355 | |
316 if (command == kLearnMoreCommand) { | 356 if (command == kLearnMoreCommand) { |
317 // User pressed "Learn more". | 357 // User pressed "Learn more". |
318 GURL url; | 358 GURL url; |
319 if (unsafe_resources_[0].threat_type == SafeBrowsingService::URL_MALWARE) { | 359 if (unsafe_resources_[0].threat_type == SafeBrowsingService::URL_MALWARE) { |
320 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); | 360 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); |
321 } else if (unsafe_resources_[0].threat_type == | 361 } else if (unsafe_resources_[0].threat_type == |
322 SafeBrowsingService::URL_PHISHING) { | 362 SafeBrowsingService::URL_PHISHING) { |
323 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); | 363 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); |
324 } else { | 364 } else { |
325 NOTREACHED(); | 365 NOTREACHED(); |
(...skipping 55 matching lines...) Loading... | |
381 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); | 421 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); |
382 DCHECK(unsafe_resources_[element_index].threat_type == | 422 DCHECK(unsafe_resources_[element_index].threat_type == |
383 SafeBrowsingService::URL_MALWARE); | 423 SafeBrowsingService::URL_MALWARE); |
384 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); | 424 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); |
385 return; | 425 return; |
386 } | 426 } |
387 | 427 |
388 NOTREACHED() << "Unexpected command: " << command; | 428 NOTREACHED() << "Unexpected command: " << command; |
389 } | 429 } |
390 | 430 |
431 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { | |
432 PrefService* pref = tab()->profile()->GetPrefs(); | |
433 pref->SetBoolean(prefs::kSafeBrowsingReportingEnabled, report); | |
434 } | |
435 | |
391 void SafeBrowsingBlockingPage::Proceed() { | 436 void SafeBrowsingBlockingPage::Proceed() { |
392 RecordUserAction(PROCEED); | 437 RecordUserAction(PROCEED); |
393 | 438 |
394 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); | 439 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); |
395 | 440 |
396 // Check to see if some new notifications of unsafe resources have been | 441 // Check to see if some new notifications of unsafe resources have been |
397 // received while we were showing the interstitial. | 442 // received while we were showing the interstitial. |
398 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 443 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
399 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 444 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); |
400 SafeBrowsingBlockingPage* blocking_page = NULL; | 445 SafeBrowsingBlockingPage* blocking_page = NULL; |
(...skipping 146 matching lines...) Loading... | |
547 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 592 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
548 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); | 593 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); |
549 } | 594 } |
550 | 595 |
551 // static | 596 // static |
552 bool SafeBrowsingBlockingPage::IsMainPage( | 597 bool SafeBrowsingBlockingPage::IsMainPage( |
553 const UnsafeResourceList& unsafe_resources) { | 598 const UnsafeResourceList& unsafe_resources) { |
554 return unsafe_resources.size() == 1 && | 599 return unsafe_resources.size() == 1 && |
555 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; | 600 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; |
556 } | 601 } |
OLD | NEW |