Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page.cc

Issue 399773002: Experience sampling insturmentation for SSL and Safe Browsing interstitials (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sampling-api
Patch Set: Clean up experience sampling header file changes Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
40 #include "grit/browser_resources.h" 40 #include "grit/browser_resources.h"
41 #include "grit/chromium_strings.h" 41 #include "grit/chromium_strings.h"
42 #include "grit/generated_resources.h" 42 #include "grit/generated_resources.h"
43 #include "grit/locale_settings.h" 43 #include "grit/locale_settings.h"
44 #include "net/base/escape.h" 44 #include "net/base/escape.h"
45 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
46 #include "ui/base/resource/resource_bundle.h" 46 #include "ui/base/resource/resource_bundle.h"
47 #include "ui/base/webui/jstemplate_builder.h" 47 #include "ui/base/webui/jstemplate_builder.h"
48 #include "ui/base/webui/web_ui_util.h" 48 #include "ui/base/webui/web_ui_util.h"
49 49
50 #if defined(ENABLE_EXTENSIONS)
51 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
52 #endif
53
50 using base::UserMetricsAction; 54 using base::UserMetricsAction;
51 using content::BrowserThread; 55 using content::BrowserThread;
52 using content::InterstitialPage; 56 using content::InterstitialPage;
53 using content::OpenURLParams; 57 using content::OpenURLParams;
54 using content::Referrer; 58 using content::Referrer;
55 using content::WebContents; 59 using content::WebContents;
56 60
61 #if defined(ENABLE_EXTENSIONS)
62 using extensions::ExperienceSamplingEvent;
63 #endif
64
57 namespace { 65 namespace {
58 66
59 // For malware interstitial pages, we link the problematic URL to Google's 67 // For malware interstitial pages, we link the problematic URL to Google's
60 // diagnostic page. 68 // diagnostic page.
61 #if defined(GOOGLE_CHROME_BUILD) 69 #if defined(GOOGLE_CHROME_BUILD)
62 const char* const kSbDiagnosticUrl = 70 const char* const kSbDiagnosticUrl =
63 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=googlechrome"; 71 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=googlechrome";
64 #else 72 #else
65 const char* const kSbDiagnosticUrl = 73 const char* const kSbDiagnosticUrl =
66 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=chromium"; 74 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=chromium";
(...skipping 30 matching lines...) Expand all
97 const char kTakeMeBackCommand[] = "takeMeBack"; 105 const char kTakeMeBackCommand[] = "takeMeBack";
98 // Special command that we use when the user navigated away from the 106 // Special command that we use when the user navigated away from the
99 // page. E.g., closed the tab or the window. This is only used by 107 // page. E.g., closed the tab or the window. This is only used by
100 // RecordUserReactionTime. 108 // RecordUserReactionTime.
101 const char kNavigatedAwayMetaCommand[] = "closed"; 109 const char kNavigatedAwayMetaCommand[] = "closed";
102 110
103 // Other constants used to communicate with the JavaScript. 111 // Other constants used to communicate with the JavaScript.
104 const char kBoxChecked[] = "boxchecked"; 112 const char kBoxChecked[] = "boxchecked";
105 const char kDisplayCheckBox[] = "displaycheckbox"; 113 const char kDisplayCheckBox[] = "displaycheckbox";
106 114
115 // Constants for the Experience Sampling instrumentation.
116 #if defined(ENABLE_EXTENSIONS)
117 const char kEventNameMalware[] = "safebrowsing_interstitial_";
118 const char kEventNamePhishing[] = "phishing_interstitial_";
119 const char kEventNameMalwareAndPhishing[] =
120 "malware_and_phishing_interstitial_";
121 const char kEventNameOther[] = "safebrowsing_other_interstitial_";
122 #endif
123
107 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> 124 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap>
108 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; 125 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER;
109 126
110 // This enum is used for a histogram. Don't reorder, delete, or insert 127 // This enum is used for a histogram. Don't reorder, delete, or insert
111 // elements. New elements should be added before MAX_ACTION only. 128 // elements. New elements should be added before MAX_ACTION only.
112 enum DetailedDecision { 129 enum DetailedDecision {
113 MALWARE_SHOW_NEW_SITE = 0, 130 MALWARE_SHOW_NEW_SITE = 0,
114 MALWARE_PROCEED_NEW_SITE, 131 MALWARE_PROCEED_NEW_SITE,
115 MALWARE_SHOW_CROSS_SITE, 132 MALWARE_SHOW_CROSS_SITE,
116 MALWARE_PROCEED_CROSS_SITE, 133 MALWARE_PROCEED_CROSS_SITE,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // if the user opts-in on the blocking page later. 305 // if the user opts-in on the blocking page later.
289 // If there's more than one malicious resources, it means the user 306 // If there's more than one malicious resources, it means the user
290 // clicked through the first warning, so we don't prepare additional 307 // clicked through the first warning, so we don't prepare additional
291 // reports. 308 // reports.
292 if (unsafe_resources.size() == 1 && 309 if (unsafe_resources.size() == 1 &&
293 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE && 310 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE &&
294 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) { 311 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) {
295 malware_details_ = MalwareDetails::NewMalwareDetails( 312 malware_details_ = MalwareDetails::NewMalwareDetails(
296 ui_manager_, web_contents, unsafe_resources[0]); 313 ui_manager_, web_contents, unsafe_resources[0]);
297 } 314 }
315
316 #if defined(ENABLE_EXTENSIONS)
317 // ExperienceSampling: Set up new sampling event for this interstitial.
318 // This needs to handle all types of warnings this interstitial can show.
319 std::string event_name;
320 switch (interstitial_type_) {
321 case TYPE_MALWARE_AND_PHISHING:
322 event_name = kEventNameMalwareAndPhishing;
323 break;
324 case TYPE_MALWARE:
325 event_name = kEventNameMalware;
326 break;
327 case TYPE_PHISHING:
328 event_name = kEventNamePhishing;
329 break;
330 default:
331 event_name = kEventNameOther;
332 break;
333 }
334 sampling_event_.reset(new ExperienceSamplingEvent(
335 event_name,
336 url_,
337 web_contents_->GetLastCommittedURL(),
338 web_contents_->GetBrowserContext()));
339 #endif
340
298 // Creating interstitial_page_ without showing it leaks memory, so don't 341 // Creating interstitial_page_ without showing it leaks memory, so don't
299 // create it here. 342 // create it here.
300 } 343 }
301 344
302 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { 345 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() {
303 return (!web_contents_->GetBrowserContext()->IsOffTheRecord() && 346 return (!web_contents_->GetBrowserContext()->IsOffTheRecord() &&
304 web_contents_->GetURL().SchemeIs(url::kHttpScheme)); 347 web_contents_->GetURL().SchemeIs(url::kHttpScheme));
305 } 348 }
306 349
307 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { 350 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() {
(...skipping 13 matching lines...) Expand all
321 364
322 if (command == kDontReportCommand) { 365 if (command == kDontReportCommand) {
323 SetReportingPreference(false); 366 SetReportingPreference(false);
324 return; 367 return;
325 } 368 }
326 369
327 if (command == kLearnMoreCommand) { 370 if (command == kLearnMoreCommand) {
328 // User pressed "Learn more". 371 // User pressed "Learn more".
329 GURL url(interstitial_type_ == TYPE_PHISHING ? 372 GURL url(interstitial_type_ == TYPE_PHISHING ?
330 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); 373 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2);
374 #if defined(ENABLE_EXTENSIONS)
375 if (sampling_event_.get())
376 sampling_event_->set_has_viewed_learn_more(true);
377 #endif
331 OpenURLParams params( 378 OpenURLParams params(
332 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); 379 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false);
333 web_contents_->OpenURL(params); 380 web_contents_->OpenURL(params);
334 return; 381 return;
335 } 382 }
336 383
337 if (command == kShowPrivacyCommand) { 384 if (command == kShowPrivacyCommand) {
338 // User pressed "Safe Browsing privacy policy". 385 // User pressed "Safe Browsing privacy policy".
339 GURL url(l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); 386 GURL url(l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL));
340 OpenURLParams params( 387 OpenURLParams params(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 diagnostic_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, 481 diagnostic_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK,
435 false); 482 false);
436 web_contents_->OpenURL(params); 483 web_contents_->OpenURL(params);
437 return; 484 return;
438 } 485 }
439 486
440 if (command == kExpandedSeeMoreCommand) { 487 if (command == kExpandedSeeMoreCommand) {
441 // User expanded the "see more info" section of the page. We don't actually 488 // User expanded the "see more info" section of the page. We don't actually
442 // do any action based on this, it's just so that RecordUserReactionTime can 489 // do any action based on this, it's just so that RecordUserReactionTime can
443 // track it. 490 // track it.
491
492 #if defined(ENABLE_EXTENSIONS)
493 // ExperienceSampling: We track that the user expanded the details.
494 if (sampling_event_.get())
495 sampling_event_->set_has_viewed_details(true);
496 #endif
444 return; 497 return;
445 } 498 }
446 499
447 NOTREACHED() << "Unexpected command: " << command; 500 NOTREACHED() << "Unexpected command: " << command;
448 } 501 }
449 502
450 void SafeBrowsingBlockingPage::OverrideRendererPrefs( 503 void SafeBrowsingBlockingPage::OverrideRendererPrefs(
451 content::RendererPreferences* prefs) { 504 content::RendererPreferences* prefs) {
452 Profile* profile = Profile::FromBrowserContext( 505 Profile* profile = Profile::FromBrowserContext(
453 web_contents_->GetBrowserContext()); 506 web_contents_->GetBrowserContext());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 SafeBrowsingBlockingPage* blocking_page = NULL; 550 SafeBrowsingBlockingPage* blocking_page = NULL;
498 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { 551 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
499 // Build an interstitial for all the unsafe resources notifications. 552 // Build an interstitial for all the unsafe resources notifications.
500 // Don't show it now as showing an interstitial while an interstitial is 553 // Don't show it now as showing an interstitial while an interstitial is
501 // already showing would cause DontProceed() to be invoked. 554 // already showing would cause DontProceed() to be invoked.
502 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_, web_contents_, 555 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_, web_contents_,
503 iter->second); 556 iter->second);
504 unsafe_resource_map->erase(iter); 557 unsafe_resource_map->erase(iter);
505 } 558 }
506 559
560 #if defined(ENABLE_EXTENSIONS)
561 // ExperienceSampling: Notify that user decided to proceed.
562 if (sampling_event_.get())
563 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed);
564 #endif
565
507 // Now that this interstitial is gone, we can show the new one. 566 // Now that this interstitial is gone, we can show the new one.
508 if (blocking_page) 567 if (blocking_page)
509 blocking_page->Show(); 568 blocking_page->Show();
510 } 569 }
511 570
512 void SafeBrowsingBlockingPage::DontCreateViewForTesting() { 571 void SafeBrowsingBlockingPage::DontCreateViewForTesting() {
513 create_view_ = false; 572 create_view_ = false;
514 } 573 }
515 574
516 void SafeBrowsingBlockingPage::Show() { 575 void SafeBrowsingBlockingPage::Show() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 // that had a subresource warning. 612 // that had a subresource warning.
554 int last_committed_index = 613 int last_committed_index =
555 web_contents_->GetController().GetLastCommittedEntryIndex(); 614 web_contents_->GetController().GetLastCommittedEntryIndex();
556 if (navigation_entry_index_to_remove_ != -1 && 615 if (navigation_entry_index_to_remove_ != -1 &&
557 navigation_entry_index_to_remove_ != last_committed_index && 616 navigation_entry_index_to_remove_ != last_committed_index &&
558 !web_contents_->IsBeingDestroyed()) { 617 !web_contents_->IsBeingDestroyed()) {
559 CHECK(web_contents_->GetController().RemoveEntryAtIndex( 618 CHECK(web_contents_->GetController().RemoveEntryAtIndex(
560 navigation_entry_index_to_remove_)); 619 navigation_entry_index_to_remove_));
561 navigation_entry_index_to_remove_ = -1; 620 navigation_entry_index_to_remove_ = -1;
562 } 621 }
622
623 #if defined(ENABLE_EXTENSIONS)
624 // ExperienceSampling: Notify that user decided to go back.
625 // This also occurs if the user navigates away or closes the tab.
626 if (sampling_event_.get())
627 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny);
628 #endif
563 } 629 }
564 630
565 void SafeBrowsingBlockingPage::OnGotHistoryCount(bool success, 631 void SafeBrowsingBlockingPage::OnGotHistoryCount(bool success,
566 int num_visits, 632 int num_visits,
567 base::Time first_visit) { 633 base::Time first_visit) {
568 if (success) 634 if (success)
569 num_visits_ = num_visits; 635 num_visits_ = num_visits;
570 } 636 }
571 637
572 void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) { 638 void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) {
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 IDS_PHISHING_V3_PRIMARY_PARAGRAPH, 1279 IDS_PHISHING_V3_PRIMARY_PARAGRAPH,
1214 base::UTF8ToUTF16(url_.host()))); 1280 base::UTF8ToUTF16(url_.host())));
1215 load_time_data->SetString( 1281 load_time_data->SetString(
1216 "explanationParagraph", 1282 "explanationParagraph",
1217 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, 1283 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH,
1218 base::UTF8ToUTF16(url_.host()))); 1284 base::UTF8ToUTF16(url_.host())));
1219 load_time_data->SetString( 1285 load_time_data->SetString(
1220 "finalParagraph", 1286 "finalParagraph",
1221 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); 1287 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH));
1222 } 1288 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.h ('k') | chrome/browser/ssl/ssl_blocking_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698