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

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(OS_WIN) 49 #if defined(OS_WIN)
55 #include "base/base_paths_win.h" 50 #include "base/base_paths_win.h"
56 #include "base/path_service.h" 51 #include "base/path_service.h"
57 #include "base/strings/string16.h" 52 #include "base/strings/string16.h"
58 #include "base/win/windows_version.h" 53 #include "base/win/windows_version.h"
59 #endif 54 #endif
60 55
61 #if defined(OS_CHROMEOS) 56 #if defined(OS_CHROMEOS)
62 #include "chrome/browser/profiles/profile_manager.h" 57 #include "chrome/browser/profiles/profile_manager.h"
63 #include "chrome/browser/ui/chrome_pages.h" 58 #include "chrome/browser/ui/chrome_pages.h"
(...skipping 20 matching lines...) Expand all
84 DONT_PROCEED_NAME, 79 DONT_PROCEED_NAME,
85 DONT_PROCEED_DATE, 80 DONT_PROCEED_DATE,
86 DONT_PROCEED_AUTHORITY, 81 DONT_PROCEED_AUTHORITY,
87 MORE, 82 MORE,
88 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated. 83 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated.
89 SHOW_INTERNAL_HOSTNAME, 84 SHOW_INTERNAL_HOSTNAME,
90 PROCEED_INTERNAL_HOSTNAME, 85 PROCEED_INTERNAL_HOSTNAME,
91 SHOW_NEW_SITE, 86 SHOW_NEW_SITE,
92 PROCEED_NEW_SITE, 87 PROCEED_NEW_SITE,
93 PROCEED_MANUAL_NONOVERRIDABLE, 88 PROCEED_MANUAL_NONOVERRIDABLE,
94 CAPTIVE_PORTAL_DETECTION_ENABLED, 89 // Captive Portal errors moved to ssl_error_classification.
95 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, 90 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED,
96 CAPTIVE_PORTAL_PROBE_COMPLETED, 91 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE,
97 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, 92 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED,
98 CAPTIVE_PORTAL_NO_RESPONSE, 93 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE,
99 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, 94 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE,
100 CAPTIVE_PORTAL_DETECTED, 95 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE,
101 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, 96 DEPRECATED_CAPTIVE_PORTAL_DETECTED,
97 DEPRECATED_CAPTIVE_PORTAL_DETECTED_OVERRIDABLE,
102 UNUSED_BLOCKING_PAGE_EVENT, 98 UNUSED_BLOCKING_PAGE_EVENT,
103 }; 99 };
104 100
105 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { 101 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) {
106 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", 102 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl",
107 event, 103 event,
108 UNUSED_BLOCKING_PAGE_EVENT); 104 UNUSED_BLOCKING_PAGE_EVENT);
109 } 105 }
110 106
111 void RecordSSLBlockingPageDetailedStats( 107 void RecordSSLBlockingPageDetailedStats(
112 bool proceed, 108 bool proceed,
113 int cert_error, 109 int cert_error,
114 bool overridable, 110 bool overridable,
115 bool internal, 111 bool internal,
116 int num_visits, 112 int num_visits) {
117 bool captive_portal_detection_enabled,
118 bool captive_portal_probe_completed,
119 bool captive_portal_no_response,
120 bool captive_portal_detected) {
121 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", 113 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type",
122 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); 114 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM);
123 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
124 if (captive_portal_detection_enabled)
125 RecordSSLBlockingPageEventStats(
126 overridable ?
127 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE :
128 CAPTIVE_PORTAL_DETECTION_ENABLED);
129 if (captive_portal_probe_completed)
130 RecordSSLBlockingPageEventStats(
131 overridable ?
132 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE :
133 CAPTIVE_PORTAL_PROBE_COMPLETED);
134 // Log only one of portal detected and no response results.
135 if (captive_portal_detected)
136 RecordSSLBlockingPageEventStats(
137 overridable ?
138 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE :
139 CAPTIVE_PORTAL_DETECTED);
140 else if (captive_portal_no_response)
141 RecordSSLBlockingPageEventStats(
142 overridable ?
143 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE :
144 CAPTIVE_PORTAL_NO_RESPONSE);
145 #endif
146 if (!overridable) { 115 if (!overridable) {
147 if (proceed) { 116 if (proceed) {
148 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE); 117 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE);
149 } 118 }
150 // Overridable is false if the user didn't have any option except to turn 119 // Overridable is false if the user didn't have any option except to turn
151 // back. If that's the case, don't record some of the metrics. 120 // back. If that's the case, don't record some of the metrics.
152 return; 121 return;
153 } 122 }
154 if (num_visits == 0) 123 if (num_visits == 0)
155 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); 124 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 const base::Callback<void(bool)>& callback) 248 const base::Callback<void(bool)>& callback)
280 : callback_(callback), 249 : callback_(callback),
281 web_contents_(web_contents), 250 web_contents_(web_contents),
282 cert_error_(cert_error), 251 cert_error_(cert_error),
283 ssl_info_(ssl_info), 252 ssl_info_(ssl_info),
284 request_url_(request_url), 253 request_url_(request_url),
285 overridable_(overridable), 254 overridable_(overridable),
286 strict_enforcement_(strict_enforcement), 255 strict_enforcement_(strict_enforcement),
287 interstitial_page_(NULL), 256 interstitial_page_(NULL),
288 internal_(false), 257 internal_(false),
289 num_visits_(-1), 258 num_visits_(-1) {
290 captive_portal_detection_enabled_(false),
291 captive_portal_probe_completed_(false),
292 captive_portal_no_response_(false),
293 captive_portal_detected_(false) {
294 Profile* profile = Profile::FromBrowserContext( 259 Profile* profile = Profile::FromBrowserContext(
295 web_contents->GetBrowserContext()); 260 web_contents->GetBrowserContext());
296 // For UMA stats. 261 // For UMA stats.
297 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) 262 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets()))
298 internal_ = true; 263 internal_ = true;
299 RecordSSLBlockingPageEventStats(SHOW_ALL); 264 RecordSSLBlockingPageEventStats(SHOW_ALL);
300 if (overridable_ && !strict_enforcement_) { 265 if (overridable_ && !strict_enforcement_) {
301 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); 266 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE);
302 if (internal_) 267 if (internal_)
303 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); 268 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME);
304 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 269 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
305 profile, Profile::EXPLICIT_ACCESS); 270 profile, Profile::EXPLICIT_ACCESS);
306 if (history_service) { 271 if (history_service) {
307 history_service->GetVisibleVisitCountToHost( 272 history_service->GetVisibleVisitCountToHost(
308 request_url_, 273 request_url_,
309 base::Bind(&SSLBlockingPage::OnGotHistoryCount, 274 base::Bind(&SSLBlockingPage::OnGotHistoryCount,
310 base::Unretained(this)), 275 base::Unretained(this)),
311 &request_tracker_); 276 &request_tracker_);
312 } 277 }
313 } 278 }
314 279
315 SSLErrorClassification ssl_error_classification( 280 SSLErrorClassification ssl_error_classification(
281 web_contents_,
316 base::Time::NowFromSystemTime(), 282 base::Time::NowFromSystemTime(),
317 request_url_, 283 request_url_,
284 cert_error_,
318 *ssl_info_.cert.get()); 285 *ssl_info_.cert.get());
319 ssl_error_classification.RecordUMAStatistics( 286 ssl_error_classification.RecordUMAStatistics(
320 overridable_ && !strict_enforcement_, cert_error_); 287 overridable_ && !strict_enforcement_);
321 288
322 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 289 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
323 CaptivePortalService* captive_portal_service = 290 ssl_error_classification.RecordCaptivePortalUMAStatistics(
324 CaptivePortalServiceFactory::GetForProfile(profile); 291 overridable_ && !strict_enforcement_);
325 captive_portal_detection_enabled_ = captive_portal_service ->enabled();
326 captive_portal_service ->DetectCaptivePortal();
327 registrar_.Add(this,
328 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
329 content::Source<Profile>(profile));
330 #endif 292 #endif
331 293
332 // Creating an interstitial without showing (e.g. from chrome://interstitials) 294 // Creating an interstitial without showing (e.g. from chrome://interstitials)
333 // it leaks memory, so don't create it here. 295 // it leaks memory, so don't create it here.
334 } 296 }
335 297
336 SSLBlockingPage::~SSLBlockingPage() { 298 SSLBlockingPage::~SSLBlockingPage() {
299 // InvalidCommonNameSeverityScore() and InvalidDateSeverityScore() are in the
300 // destructor because they depend on knowing whether captive portal detection
301 // happened before the user made a decision.
302 SSLErrorClassification ssl_error_classification(
303 web_contents_,
304 base::Time::NowFromSystemTime(),
305 request_url_,
306 cert_error_,
307 *ssl_info_.cert.get());
308 SSLErrorInfo::ErrorType type =
309 SSLErrorInfo::NetErrorToErrorType(cert_error_);
310 switch (type) {
311 case SSLErrorInfo::CERT_DATE_INVALID: {
312 ssl_error_classification.InvalidDateSeverityScore();
313 break;
314 }
315 case SSLErrorInfo::CERT_AUTHORITY_INVALID: {
316 ssl_error_classification.InvalidCommonNameSeverityScore();
317 break;
318 }
319 default:
320 break;
321 }
322
337 if (!callback_.is_null()) { 323 if (!callback_.is_null()) {
338 RecordSSLBlockingPageDetailedStats(false, 324 RecordSSLBlockingPageDetailedStats(false,
339 cert_error_, 325 cert_error_,
340 overridable_ && !strict_enforcement_, 326 overridable_ && !strict_enforcement_,
341 internal_, 327 internal_,
342 num_visits_, 328 num_visits_);
343 captive_portal_detection_enabled_,
344 captive_portal_probe_completed_,
345 captive_portal_no_response_,
346 captive_portal_detected_);
347 // The page is closed without the user having chosen what to do, default to 329 // The page is closed without the user having chosen what to do, default to
348 // deny. 330 // deny.
349 NotifyDenyCertificate(); 331 NotifyDenyCertificate();
350 } 332 }
351 } 333 }
352 334
353 void SSLBlockingPage::Show() { 335 void SSLBlockingPage::Show() {
354 DCHECK(!interstitial_page_); 336 DCHECK(!interstitial_page_);
355 interstitial_page_ = InterstitialPage::Create( 337 interstitial_page_ = InterstitialPage::Create(
356 web_contents_, true, request_url_, this); 338 web_contents_, true, request_url_, this);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 Profile* profile = Profile::FromBrowserContext( 496 Profile* profile = Profile::FromBrowserContext(
515 web_contents_->GetBrowserContext()); 497 web_contents_->GetBrowserContext());
516 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); 498 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile);
517 } 499 }
518 500
519 void SSLBlockingPage::OnProceed() { 501 void SSLBlockingPage::OnProceed() {
520 RecordSSLBlockingPageDetailedStats(true, 502 RecordSSLBlockingPageDetailedStats(true,
521 cert_error_, 503 cert_error_,
522 overridable_ && !strict_enforcement_, 504 overridable_ && !strict_enforcement_,
523 internal_, 505 internal_,
524 num_visits_, 506 num_visits_);
525 captive_portal_detection_enabled_,
526 captive_portal_probe_completed_,
527 captive_portal_no_response_,
528 captive_portal_detected_);
529 // Accepting the certificate resumes the loading of the page. 507 // Accepting the certificate resumes the loading of the page.
530 NotifyAllowCertificate(); 508 NotifyAllowCertificate();
531 } 509 }
532 510
533 void SSLBlockingPage::OnDontProceed() { 511 void SSLBlockingPage::OnDontProceed() {
534 RecordSSLBlockingPageDetailedStats(false, 512 RecordSSLBlockingPageDetailedStats(false,
535 cert_error_, 513 cert_error_,
536 overridable_ && !strict_enforcement_, 514 overridable_ && !strict_enforcement_,
537 internal_, 515 internal_,
538 num_visits_, 516 num_visits_);
539 captive_portal_detection_enabled_,
540 captive_portal_probe_completed_,
541 captive_portal_no_response_,
542 captive_portal_detected_);
543 NotifyDenyCertificate(); 517 NotifyDenyCertificate();
544 } 518 }
545 519
546 void SSLBlockingPage::NotifyDenyCertificate() { 520 void SSLBlockingPage::NotifyDenyCertificate() {
547 // It's possible that callback_ may not exist if the user clicks "Proceed" 521 // It's possible that callback_ may not exist if the user clicks "Proceed"
548 // followed by pressing the back button before the interstitial is hidden. 522 // followed by pressing the back button before the interstitial is hidden.
549 // In that case the certificate will still be treated as allowed. 523 // In that case the certificate will still be treated as allowed.
550 if (callback_.is_null()) 524 if (callback_.is_null())
551 return; 525 return;
552 526
(...skipping 23 matching lines...) Expand all
576 for (; i < 5; i++) { 550 for (; i < 5; i++) {
577 strings->SetString(keys[i], std::string()); 551 strings->SetString(keys[i], std::string());
578 } 552 }
579 } 553 }
580 554
581 void SSLBlockingPage::OnGotHistoryCount(bool success, 555 void SSLBlockingPage::OnGotHistoryCount(bool success,
582 int num_visits, 556 int num_visits,
583 base::Time first_visit) { 557 base::Time first_visit) {
584 num_visits_ = num_visits; 558 num_visits_ = num_visits;
585 } 559 }
586
587 void SSLBlockingPage::Observe(
588 int type,
589 const content::NotificationSource& source,
590 const content::NotificationDetails& details) {
591 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
592 // When detection is disabled, captive portal service always sends
593 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case.
594 if (!captive_portal_detection_enabled_)
595 return;
596 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) {
597 captive_portal_probe_completed_ = true;
598 CaptivePortalService::Results* results =
599 content::Details<CaptivePortalService::Results>(
600 details).ptr();
601 // If a captive portal was detected at any point when the interstitial was
602 // displayed, assume that the interstitial was caused by a captive portal.
603 // Example scenario:
604 // 1- Interstitial displayed and captive portal detected, setting the flag.
605 // 2- Captive portal detection automatically opens portal login page.
606 // 3- User logs in on the portal login page.
607 // A notification will be received here for RESULT_INTERNET_CONNECTED. Make
608 // sure we don't clear the captive portal flag, since the interstitial was
609 // potentially caused by the captive portal.
610 captive_portal_detected_ = captive_portal_detected_ ||
611 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL);
612 // Also keep track of non-HTTP portals and error cases.
613 captive_portal_no_response_ = captive_portal_no_response_ ||
614 (results->result == captive_portal::RESULT_NO_RESPONSE);
615 }
616 #endif
617 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698