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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
23 #include "base/values.h" | 23 #include "base/values.h" |
24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" | |
25 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/renderer_preferences_util.h" | 28 #include "chrome/browser/renderer_preferences_util.h" |
28 #include "chrome/browser/safe_browsing/malware_details.h" | 29 #include "chrome/browser/safe_browsing/malware_details.h" |
29 #include "chrome/browser/safe_browsing/ui_manager.h" | 30 #include "chrome/browser/safe_browsing/ui_manager.h" |
30 #include "chrome/browser/tab_contents/tab_util.h" | 31 #include "chrome/browser/tab_contents/tab_util.h" |
31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
34 #include "components/google/core/browser/google_util.h" | 35 #include "components/google/core/browser/google_util.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
46 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
47 #include "ui/base/webui/jstemplate_builder.h" | 48 #include "ui/base/webui/jstemplate_builder.h" |
48 #include "ui/base/webui/web_ui_util.h" | 49 #include "ui/base/webui/web_ui_util.h" |
49 | 50 |
50 using base::UserMetricsAction; | 51 using base::UserMetricsAction; |
51 using content::BrowserThread; | 52 using content::BrowserThread; |
52 using content::InterstitialPage; | 53 using content::InterstitialPage; |
53 using content::OpenURLParams; | 54 using content::OpenURLParams; |
54 using content::Referrer; | 55 using content::Referrer; |
55 using content::WebContents; | 56 using content::WebContents; |
57 using extensions::SamplingEvent; | |
56 | 58 |
57 namespace { | 59 namespace { |
58 | 60 |
59 // For malware interstitial pages, we link the problematic URL to Google's | 61 // For malware interstitial pages, we link the problematic URL to Google's |
60 // diagnostic page. | 62 // diagnostic page. |
61 #if defined(GOOGLE_CHROME_BUILD) | 63 #if defined(GOOGLE_CHROME_BUILD) |
62 const char* const kSbDiagnosticUrl = | 64 const char* const kSbDiagnosticUrl = |
63 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=googlechrome"; | 65 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=googlechrome"; |
64 #else | 66 #else |
65 const char* const kSbDiagnosticUrl = | 67 const char* const kSbDiagnosticUrl = |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 // If there's more than one malicious resources, it means the user | 305 // If there's more than one malicious resources, it means the user |
304 // clicked through the first warning, so we don't prepare additional | 306 // clicked through the first warning, so we don't prepare additional |
305 // reports. | 307 // reports. |
306 if (unsafe_resources.size() == 1 && | 308 if (unsafe_resources.size() == 1 && |
307 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE && | 309 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE && |
308 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) { | 310 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) { |
309 malware_details_ = MalwareDetails::NewMalwareDetails( | 311 malware_details_ = MalwareDetails::NewMalwareDetails( |
310 ui_manager_, web_contents, unsafe_resources[0]); | 312 ui_manager_, web_contents, unsafe_resources[0]); |
311 } | 313 } |
312 | 314 |
315 // ExperienceSampling: Set up new sampling event for this interstitial. | |
316 // This needs to handle all types of warnings this insterstitial can show. | |
317 std::string event_name; | |
318 if (interstitial_type_ == TYPE_MALWARE_AND_PHISHING) | |
319 event_name = "malware_and_phishing_interstitial"; | |
felt
2014/07/18 21:13:59
use a switch statement for this, and also put stri
Chris Thompson
2014/07/23 22:45:38
Done.
| |
320 else if (interstitial_type_ == TYPE_MALWARE) | |
321 event_name = "malware_interstitial"; | |
322 else if (interstitial_type_ == TYPE_PHISHING) | |
323 event_name = "phishing_interstitial"; | |
324 else | |
325 event_name = "other_safe_browsing_interstitial"; | |
326 | |
327 sampling_event_ = make_scoped_ptr(new SamplingEvent( | |
328 event_name, | |
329 url_.possibly_invalid_spec(), | |
330 web_contents_->GetLastCommittedURL().possibly_invalid_spec(), | |
331 web_contents_->GetBrowserContext())); | |
332 | |
313 interstitial_page_ = InterstitialPage::Create( | 333 interstitial_page_ = InterstitialPage::Create( |
314 web_contents, IsMainPageLoadBlocked(unsafe_resources), url_, this); | 334 web_contents, IsMainPageLoadBlocked(unsafe_resources), url_, this); |
315 } | 335 } |
316 | 336 |
317 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { | 337 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { |
318 return (!web_contents_->GetBrowserContext()->IsOffTheRecord() && | 338 return (!web_contents_->GetBrowserContext()->IsOffTheRecord() && |
319 web_contents_->GetURL().SchemeIs(url::kHttpScheme)); | 339 web_contents_->GetURL().SchemeIs(url::kHttpScheme)); |
320 } | 340 } |
321 | 341 |
322 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 342 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 SafeBrowsingBlockingPage* blocking_page = NULL; | 562 SafeBrowsingBlockingPage* blocking_page = NULL; |
543 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 563 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
544 // Build an interstitial for all the unsafe resources notifications. | 564 // Build an interstitial for all the unsafe resources notifications. |
545 // Don't show it now as showing an interstitial while an interstitial is | 565 // Don't show it now as showing an interstitial while an interstitial is |
546 // already showing would cause DontProceed() to be invoked. | 566 // already showing would cause DontProceed() to be invoked. |
547 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_, web_contents_, | 567 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_, web_contents_, |
548 iter->second); | 568 iter->second); |
549 unsafe_resource_map->erase(iter); | 569 unsafe_resource_map->erase(iter); |
550 } | 570 } |
551 | 571 |
572 // ExperienceSampling: Notify that user decided to proceed. | |
573 sampling_event_->CreateUserDecisionEvent("proceed"); | |
574 | |
552 // Now that this interstitial is gone, we can show the new one. | 575 // Now that this interstitial is gone, we can show the new one. |
553 if (blocking_page) | 576 if (blocking_page) |
554 blocking_page->interstitial_page_->Show(); | 577 blocking_page->interstitial_page_->Show(); |
555 } | 578 } |
556 | 579 |
557 void SafeBrowsingBlockingPage::OnDontProceed() { | 580 void SafeBrowsingBlockingPage::OnDontProceed() { |
558 // Calling this method twice will not double-count. | 581 // Calling this method twice will not double-count. |
559 RecordUserReactionTime(kNavigatedAwayMetaCommand); | 582 RecordUserReactionTime(kNavigatedAwayMetaCommand); |
560 // We could have already called Proceed(), in which case we must not notify | 583 // We could have already called Proceed(), in which case we must not notify |
561 // the SafeBrowsingUIManager again, as the client has been deleted. | 584 // the SafeBrowsingUIManager again, as the client has been deleted. |
(...skipping 23 matching lines...) Expand all Loading... | |
585 // that had a subresource warning. | 608 // that had a subresource warning. |
586 int last_committed_index = | 609 int last_committed_index = |
587 web_contents_->GetController().GetLastCommittedEntryIndex(); | 610 web_contents_->GetController().GetLastCommittedEntryIndex(); |
588 if (navigation_entry_index_to_remove_ != -1 && | 611 if (navigation_entry_index_to_remove_ != -1 && |
589 navigation_entry_index_to_remove_ != last_committed_index && | 612 navigation_entry_index_to_remove_ != last_committed_index && |
590 !web_contents_->IsBeingDestroyed()) { | 613 !web_contents_->IsBeingDestroyed()) { |
591 CHECK(web_contents_->GetController().RemoveEntryAtIndex( | 614 CHECK(web_contents_->GetController().RemoveEntryAtIndex( |
592 navigation_entry_index_to_remove_)); | 615 navigation_entry_index_to_remove_)); |
593 navigation_entry_index_to_remove_ = -1; | 616 navigation_entry_index_to_remove_ = -1; |
594 } | 617 } |
618 | |
619 // ExperienceSampling: Notify that user decided to go back. | |
620 // This also occurs if the user navigates away or closes the tab. | |
621 sampling_event_->CreateUserDecisionEvent("deny"); | |
595 } | 622 } |
596 | 623 |
597 void SafeBrowsingBlockingPage::OnGotHistoryCount(bool success, | 624 void SafeBrowsingBlockingPage::OnGotHistoryCount(bool success, |
598 int num_visits, | 625 int num_visits, |
599 base::Time first_visit) { | 626 base::Time first_visit) { |
600 if (success) | 627 if (success) |
601 num_visits_ = num_visits; | 628 num_visits_ = num_visits; |
602 } | 629 } |
603 | 630 |
604 void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) { | 631 void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) { |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1393 IDS_PHISHING_V3_PRIMARY_PARAGRAPH, | 1420 IDS_PHISHING_V3_PRIMARY_PARAGRAPH, |
1394 base::UTF8ToUTF16(url_.host()))); | 1421 base::UTF8ToUTF16(url_.host()))); |
1395 load_time_data->SetString( | 1422 load_time_data->SetString( |
1396 "explanationParagraph", | 1423 "explanationParagraph", |
1397 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, | 1424 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, |
1398 base::UTF8ToUTF16(url_.host()))); | 1425 base::UTF8ToUTF16(url_.host()))); |
1399 load_time_data->SetString( | 1426 load_time_data->SetString( |
1400 "finalParagraph", | 1427 "finalParagraph", |
1401 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); | 1428 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); |
1402 } | 1429 } |
OLD | NEW |