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

Side by Side Diff: chrome/browser/ssl/ssl_blocking_page.cc

Issue 400323002: Refactor the captive portal code to move from the ssl_blocking_page class to the ssl_error_classific (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Comments 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 #include "chrome/browser/ssl/ssl_blocking_page.h" 5 #include "chrome/browser/ssl/ssl_blocking_page.h"
6 6
7 #include "base/build_time.h" 7 #include "base/build_time.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/i18n/time_formatting.h" 10 #include "base/i18n/time_formatting.h"
(...skipping 28 matching lines...) Expand all
39 #include "grit/chromium_strings.h" 39 #include "grit/chromium_strings.h"
40 #include "grit/generated_resources.h" 40 #include "grit/generated_resources.h"
41 #include "net/base/hash_value.h" 41 #include "net/base/hash_value.h"
42 #include "net/base/net_errors.h" 42 #include "net/base/net_errors.h"
43 #include "net/base/net_util.h" 43 #include "net/base/net_util.h"
44 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
45 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
46 #include "ui/base/webui/jstemplate_builder.h" 46 #include "ui/base/webui/jstemplate_builder.h"
47 #include "ui/base/webui/web_ui_util.h" 47 #include "ui/base/webui/web_ui_util.h"
48 48
49 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
50 #include "chrome/browser/captive_portal/captive_portal_service.h"
51 #include "chrome/browser/captive_portal/captive_portal_service_factory.h"
52 #endif
53
54 #if defined(ENABLE_EXTENSIONS) 49 #if defined(ENABLE_EXTENSIONS)
55 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" 50 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
56 #endif 51 #endif
57 52
58 #if defined(OS_WIN) 53 #if defined(OS_WIN)
59 #include "base/base_paths_win.h" 54 #include "base/base_paths_win.h"
60 #include "base/path_service.h" 55 #include "base/path_service.h"
61 #include "base/strings/string16.h" 56 #include "base/strings/string16.h"
62 #include "base/win/windows_version.h" 57 #include "base/win/windows_version.h"
63 #endif 58 #endif
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 DONT_PROCEED_NAME, 94 DONT_PROCEED_NAME,
100 DONT_PROCEED_DATE, 95 DONT_PROCEED_DATE,
101 DONT_PROCEED_AUTHORITY, 96 DONT_PROCEED_AUTHORITY,
102 MORE, 97 MORE,
103 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated. 98 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated.
104 SHOW_INTERNAL_HOSTNAME, 99 SHOW_INTERNAL_HOSTNAME,
105 PROCEED_INTERNAL_HOSTNAME, 100 PROCEED_INTERNAL_HOSTNAME,
106 SHOW_NEW_SITE, 101 SHOW_NEW_SITE,
107 PROCEED_NEW_SITE, 102 PROCEED_NEW_SITE,
108 PROCEED_MANUAL_NONOVERRIDABLE, 103 PROCEED_MANUAL_NONOVERRIDABLE,
109 CAPTIVE_PORTAL_DETECTION_ENABLED, 104 // Captive Portal errors moved to ssl_error_classification.
110 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, 105 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED,
111 CAPTIVE_PORTAL_PROBE_COMPLETED, 106 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE,
112 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, 107 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED,
113 CAPTIVE_PORTAL_NO_RESPONSE, 108 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE,
114 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, 109 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE,
115 CAPTIVE_PORTAL_DETECTED, 110 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE,
116 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, 111 DEPRECATED_CAPTIVE_PORTAL_DETECTED,
112 DEPRECATED_CAPTIVE_PORTAL_DETECTED_OVERRIDABLE,
117 UNUSED_BLOCKING_PAGE_EVENT, 113 UNUSED_BLOCKING_PAGE_EVENT,
118 }; 114 };
119 115
120 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { 116 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) {
121 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", 117 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl",
122 event, 118 event,
123 UNUSED_BLOCKING_PAGE_EVENT); 119 UNUSED_BLOCKING_PAGE_EVENT);
124 } 120 }
125 121
126 void RecordSSLBlockingPageDetailedStats( 122 void RecordSSLBlockingPageDetailedStats(
127 bool proceed, 123 bool proceed,
128 int cert_error, 124 int cert_error,
129 bool overridable, 125 bool overridable,
130 bool internal, 126 bool internal,
131 int num_visits, 127 int num_visits) {
132 bool captive_portal_detection_enabled,
133 bool captive_portal_probe_completed,
134 bool captive_portal_no_response,
135 bool captive_portal_detected) {
136 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", 128 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type",
137 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); 129 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM);
138 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
139 if (captive_portal_detection_enabled)
140 RecordSSLBlockingPageEventStats(
141 overridable ?
142 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE :
143 CAPTIVE_PORTAL_DETECTION_ENABLED);
144 if (captive_portal_probe_completed)
145 RecordSSLBlockingPageEventStats(
146 overridable ?
147 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE :
148 CAPTIVE_PORTAL_PROBE_COMPLETED);
149 // Log only one of portal detected and no response results.
150 if (captive_portal_detected)
151 RecordSSLBlockingPageEventStats(
152 overridable ?
153 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE :
154 CAPTIVE_PORTAL_DETECTED);
155 else if (captive_portal_no_response)
156 RecordSSLBlockingPageEventStats(
157 overridable ?
158 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE :
159 CAPTIVE_PORTAL_NO_RESPONSE);
160 #endif
161 if (!overridable) { 130 if (!overridable) {
162 if (proceed) { 131 if (proceed) {
163 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE); 132 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE);
164 } 133 }
165 // Overridable is false if the user didn't have any option except to turn 134 // Overridable is false if the user didn't have any option except to turn
166 // back. If that's the case, don't record some of the metrics. 135 // back. If that's the case, don't record some of the metrics.
167 return; 136 return;
168 } 137 }
169 if (num_visits == 0) 138 if (num_visits == 0)
170 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); 139 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 const base::Callback<void(bool)>& callback) 263 const base::Callback<void(bool)>& callback)
295 : callback_(callback), 264 : callback_(callback),
296 web_contents_(web_contents), 265 web_contents_(web_contents),
297 cert_error_(cert_error), 266 cert_error_(cert_error),
298 ssl_info_(ssl_info), 267 ssl_info_(ssl_info),
299 request_url_(request_url), 268 request_url_(request_url),
300 overridable_(overridable), 269 overridable_(overridable),
301 strict_enforcement_(strict_enforcement), 270 strict_enforcement_(strict_enforcement),
302 interstitial_page_(NULL), 271 interstitial_page_(NULL),
303 internal_(false), 272 internal_(false),
304 num_visits_(-1), 273 num_visits_(-1) {
305 captive_portal_detection_enabled_(false),
306 captive_portal_probe_completed_(false),
307 captive_portal_no_response_(false),
308 captive_portal_detected_(false) {
309 Profile* profile = Profile::FromBrowserContext( 274 Profile* profile = Profile::FromBrowserContext(
310 web_contents->GetBrowserContext()); 275 web_contents->GetBrowserContext());
311 if (strict_enforcement_) overridable_ = false; 276 if (strict_enforcement_) overridable_ = false;
312 // For UMA stats. 277 // For UMA stats.
313 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) 278 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets()))
314 internal_ = true; 279 internal_ = true;
315 RecordSSLBlockingPageEventStats(SHOW_ALL); 280 RecordSSLBlockingPageEventStats(SHOW_ALL);
316 if (overridable_) { 281 if (overridable_) {
317 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); 282 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE);
318 if (internal_) 283 if (internal_)
319 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); 284 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME);
320 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 285 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
321 profile, Profile::EXPLICIT_ACCESS); 286 profile, Profile::EXPLICIT_ACCESS);
322 if (history_service) { 287 if (history_service) {
323 history_service->GetVisibleVisitCountToHost( 288 history_service->GetVisibleVisitCountToHost(
324 request_url_, 289 request_url_,
325 base::Bind(&SSLBlockingPage::OnGotHistoryCount, 290 base::Bind(&SSLBlockingPage::OnGotHistoryCount,
326 base::Unretained(this)), 291 base::Unretained(this)),
327 &request_tracker_); 292 &request_tracker_);
328 } 293 }
329 } 294 }
330 295
331 SSLErrorClassification ssl_error_classification( 296 SSLErrorClassification ssl_error_classification(
297 web_contents_,
332 base::Time::NowFromSystemTime(), 298 base::Time::NowFromSystemTime(),
333 request_url_, 299 request_url_,
300 cert_error_,
334 *ssl_info_.cert.get()); 301 *ssl_info_.cert.get());
335 ssl_error_classification.RecordUMAStatistics(overridable_, cert_error_); 302 ssl_error_classification.RecordUMAStatistics(overridable_);
336 303
337 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 304 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
338 CaptivePortalService* captive_portal_service = 305 ssl_error_classification.RecordCaptivePortalUMAStatistics(overridable_);
339 CaptivePortalServiceFactory::GetForProfile(profile);
340 captive_portal_detection_enabled_ = captive_portal_service ->enabled();
341 captive_portal_service ->DetectCaptivePortal();
342 registrar_.Add(this,
343 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
344 content::Source<Profile>(profile));
345 #endif 306 #endif
346 307
347 #if defined(ENABLE_EXTENSIONS) 308 #if defined(ENABLE_EXTENSIONS)
348 // ExperienceSampling: Set up new sampling event for this interstitial. 309 // ExperienceSampling: Set up new sampling event for this interstitial.
349 std::string event_name(kEventNameBase); 310 std::string event_name(kEventNameBase);
350 if (overridable_ && !strict_enforcement_) 311 if (overridable_ && !strict_enforcement_)
351 event_name.append(kEventOverridable); 312 event_name.append(kEventOverridable);
352 else 313 else
353 event_name.append(kEventNotOverridable); 314 event_name.append(kEventNotOverridable);
354 event_name.append(net::ErrorToString(cert_error_)); 315 event_name.append(net::ErrorToString(cert_error_));
355 sampling_event_.reset(new ExperienceSamplingEvent( 316 sampling_event_.reset(new ExperienceSamplingEvent(
356 event_name, 317 event_name,
357 request_url_, 318 request_url_,
358 web_contents_->GetLastCommittedURL(), 319 web_contents_->GetLastCommittedURL(),
359 web_contents_->GetBrowserContext())); 320 web_contents_->GetBrowserContext()));
360 #endif 321 #endif
361 322
362 // Creating an interstitial without showing (e.g. from chrome://interstitials) 323 // Creating an interstitial without showing (e.g. from chrome://interstitials)
363 // it leaks memory, so don't create it here. 324 // it leaks memory, so don't create it here.
364 } 325 }
365 326
366 SSLBlockingPage::~SSLBlockingPage() { 327 SSLBlockingPage::~SSLBlockingPage() {
328 // InvalidCommonNameSeverityScore() and InvalidDateSeverityScore() are in the
329 // destructor because they depend on knowing whether captive portal detection
330 // happened before the user made a decision.
331 SSLErrorClassification ssl_error_classification(
332 web_contents_,
333 base::Time::NowFromSystemTime(),
334 request_url_,
335 cert_error_,
336 *ssl_info_.cert.get());
337 SSLErrorInfo::ErrorType type =
338 SSLErrorInfo::NetErrorToErrorType(cert_error_);
339 switch (type) {
340 case SSLErrorInfo::CERT_DATE_INVALID: {
341 ssl_error_classification.InvalidDateSeverityScore();
342 break;
343 }
344 case SSLErrorInfo::CERT_COMMON_NAME_INVALID: {
345 ssl_error_classification.InvalidCommonNameSeverityScore();
346 break;
347 }
348 default:
349 break;
350 }
367 if (!callback_.is_null()) { 351 if (!callback_.is_null()) {
368 RecordSSLBlockingPageDetailedStats(false, 352 RecordSSLBlockingPageDetailedStats(false,
369 cert_error_, 353 cert_error_,
370 overridable_, 354 overridable_,
371 internal_, 355 internal_,
372 num_visits_, 356 num_visits_);
373 captive_portal_detection_enabled_,
374 captive_portal_probe_completed_,
375 captive_portal_no_response_,
376 captive_portal_detected_);
377 // The page is closed without the user having chosen what to do, default to 357 // The page is closed without the user having chosen what to do, default to
378 // deny. 358 // deny.
379 NotifyDenyCertificate(); 359 NotifyDenyCertificate();
380 } 360 }
381 } 361 }
382 362
383 void SSLBlockingPage::Show() { 363 void SSLBlockingPage::Show() {
384 DCHECK(!interstitial_page_); 364 DCHECK(!interstitial_page_);
385 interstitial_page_ = InterstitialPage::Create( 365 interstitial_page_ = InterstitialPage::Create(
386 web_contents_, true, request_url_, this); 366 web_contents_, true, request_url_, this);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 Profile* profile = Profile::FromBrowserContext( 531 Profile* profile = Profile::FromBrowserContext(
552 web_contents_->GetBrowserContext()); 532 web_contents_->GetBrowserContext());
553 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); 533 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile);
554 } 534 }
555 535
556 void SSLBlockingPage::OnProceed() { 536 void SSLBlockingPage::OnProceed() {
557 RecordSSLBlockingPageDetailedStats(true, 537 RecordSSLBlockingPageDetailedStats(true,
558 cert_error_, 538 cert_error_,
559 overridable_, 539 overridable_,
560 internal_, 540 internal_,
561 num_visits_, 541 num_visits_);
562 captive_portal_detection_enabled_,
563 captive_portal_probe_completed_,
564 captive_portal_no_response_,
565 captive_portal_detected_);
566 #if defined(ENABLE_EXTENSIONS) 542 #if defined(ENABLE_EXTENSIONS)
567 // ExperienceSampling: Notify that user decided to proceed. 543 // ExperienceSampling: Notify that user decided to proceed.
568 if (sampling_event_.get()) 544 if (sampling_event_.get())
569 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); 545 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed);
570 #endif 546 #endif
547
571 // Accepting the certificate resumes the loading of the page. 548 // Accepting the certificate resumes the loading of the page.
572 NotifyAllowCertificate(); 549 NotifyAllowCertificate();
573 } 550 }
574 551
575 void SSLBlockingPage::OnDontProceed() { 552 void SSLBlockingPage::OnDontProceed() {
576 RecordSSLBlockingPageDetailedStats(false, 553 RecordSSLBlockingPageDetailedStats(false,
577 cert_error_, 554 cert_error_,
578 overridable_, 555 overridable_,
579 internal_, 556 internal_,
580 num_visits_, 557 num_visits_);
581 captive_portal_detection_enabled_,
582 captive_portal_probe_completed_,
583 captive_portal_no_response_,
584 captive_portal_detected_);
585 #if defined(ENABLE_EXTENSIONS) 558 #if defined(ENABLE_EXTENSIONS)
586 // ExperienceSampling: Notify that user decided to not proceed. 559 // ExperienceSampling: Notify that user decided to not proceed.
587 // This also occurs if the user navigates away or closes the tab. 560 // This also occurs if the user navigates away or closes the tab.
588 if (sampling_event_.get()) 561 if (sampling_event_.get())
589 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); 562 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny);
590 #endif 563 #endif
591 NotifyDenyCertificate(); 564 NotifyDenyCertificate();
592 } 565 }
593 566
594 void SSLBlockingPage::NotifyDenyCertificate() { 567 void SSLBlockingPage::NotifyDenyCertificate() {
(...skipping 29 matching lines...) Expand all
624 for (; i < 5; i++) { 597 for (; i < 5; i++) {
625 strings->SetString(keys[i], std::string()); 598 strings->SetString(keys[i], std::string());
626 } 599 }
627 } 600 }
628 601
629 void SSLBlockingPage::OnGotHistoryCount(bool success, 602 void SSLBlockingPage::OnGotHistoryCount(bool success,
630 int num_visits, 603 int num_visits,
631 base::Time first_visit) { 604 base::Time first_visit) {
632 num_visits_ = num_visits; 605 num_visits_ = num_visits;
633 } 606 }
634
635 void SSLBlockingPage::Observe(
636 int type,
637 const content::NotificationSource& source,
638 const content::NotificationDetails& details) {
639 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
640 // When detection is disabled, captive portal service always sends
641 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case.
642 if (!captive_portal_detection_enabled_)
643 return;
644 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) {
645 captive_portal_probe_completed_ = true;
646 CaptivePortalService::Results* results =
647 content::Details<CaptivePortalService::Results>(
648 details).ptr();
649 // If a captive portal was detected at any point when the interstitial was
650 // displayed, assume that the interstitial was caused by a captive portal.
651 // Example scenario:
652 // 1- Interstitial displayed and captive portal detected, setting the flag.
653 // 2- Captive portal detection automatically opens portal login page.
654 // 3- User logs in on the portal login page.
655 // A notification will be received here for RESULT_INTERNET_CONNECTED. Make
656 // sure we don't clear the captive portal flag, since the interstitial was
657 // potentially caused by the captive portal.
658 captive_portal_detected_ = captive_portal_detected_ ||
659 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL);
660 // Also keep track of non-HTTP portals and error cases.
661 captive_portal_no_response_ = captive_portal_no_response_ ||
662 (results->result == captive_portal::RESULT_NO_RESPONSE);
663 }
664 #endif
665 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698