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

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: Removed arguments from functions 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 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED, // Captive Portal errors moved
95 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, 90 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, // to
96 CAPTIVE_PORTAL_PROBE_COMPLETED, 91 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED, // ssl_error_classification.
97 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, 92 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE,
98 CAPTIVE_PORTAL_NO_RESPONSE, 93 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE,
99 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, 94 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE,
100 CAPTIVE_PORTAL_DETECTED, 95 DEPRECATED_CAPTIVE_PORTAL_DETECTED,
101 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, 96 DEPRECATED_CAPTIVE_PORTAL_DETECTED_OVERRIDABLE,
102 UNUSED_BLOCKING_PAGE_EVENT, 97 UNUSED_BLOCKING_PAGE_EVENT,
103 }; 98 };
104 99
105 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { 100 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) {
106 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", 101 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl",
107 event, 102 event,
108 UNUSED_BLOCKING_PAGE_EVENT); 103 UNUSED_BLOCKING_PAGE_EVENT);
109 } 104 }
110 105
111 void RecordSSLBlockingPageDetailedStats( 106 void RecordSSLBlockingPageDetailedStats(
112 bool proceed, 107 bool proceed,
113 int cert_error, 108 int cert_error,
114 bool overridable, 109 bool overridable,
115 bool internal, 110 bool internal,
116 int num_visits, 111 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", 112 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type",
122 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); 113 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) { 114 if (!overridable) {
147 if (proceed) { 115 if (proceed) {
148 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE); 116 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE);
149 } 117 }
150 // Overridable is false if the user didn't have any option except to turn 118 // 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. 119 // back. If that's the case, don't record some of the metrics.
152 return; 120 return;
153 } 121 }
154 if (num_visits == 0) 122 if (num_visits == 0)
155 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); 123 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 const base::Callback<void(bool)>& callback) 247 const base::Callback<void(bool)>& callback)
280 : callback_(callback), 248 : callback_(callback),
281 web_contents_(web_contents), 249 web_contents_(web_contents),
282 cert_error_(cert_error), 250 cert_error_(cert_error),
283 ssl_info_(ssl_info), 251 ssl_info_(ssl_info),
284 request_url_(request_url), 252 request_url_(request_url),
285 overridable_(overridable), 253 overridable_(overridable),
286 strict_enforcement_(strict_enforcement), 254 strict_enforcement_(strict_enforcement),
287 interstitial_page_(NULL), 255 interstitial_page_(NULL),
288 internal_(false), 256 internal_(false),
289 num_visits_(-1), 257 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( 258 Profile* profile = Profile::FromBrowserContext(
295 web_contents->GetBrowserContext()); 259 web_contents->GetBrowserContext());
296 // For UMA stats. 260 // For UMA stats.
297 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) 261 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets()))
298 internal_ = true; 262 internal_ = true;
299 RecordSSLBlockingPageEventStats(SHOW_ALL); 263 RecordSSLBlockingPageEventStats(SHOW_ALL);
300 if (overridable_ && !strict_enforcement_) { 264 if (overridable_ && !strict_enforcement_) {
301 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); 265 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE);
302 if (internal_) 266 if (internal_)
303 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); 267 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME);
304 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 268 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
305 profile, Profile::EXPLICIT_ACCESS); 269 profile, Profile::EXPLICIT_ACCESS);
306 if (history_service) { 270 if (history_service) {
307 history_service->GetVisibleVisitCountToHost( 271 history_service->GetVisibleVisitCountToHost(
308 request_url_, 272 request_url_,
309 base::Bind(&SSLBlockingPage::OnGotHistoryCount, 273 base::Bind(&SSLBlockingPage::OnGotHistoryCount,
310 base::Unretained(this)), 274 base::Unretained(this)),
311 &request_tracker_); 275 &request_tracker_);
312 } 276 }
313 } 277 }
314 278
315 SSLErrorClassification ssl_error_classification( 279 SSLErrorClassification ssl_error_classification(
280 web_contents_,
316 base::Time::NowFromSystemTime(), 281 base::Time::NowFromSystemTime(),
317 request_url_, 282 request_url_,
283 cert_error_,
318 *ssl_info_.cert.get()); 284 *ssl_info_.cert.get());
319 ssl_error_classification.RecordUMAStatistics( 285 ssl_error_classification.RecordUMAStatistics(
320 overridable_ && !strict_enforcement_, cert_error_); 286 overridable_ && !strict_enforcement_);
321 287
322 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 288 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
323 CaptivePortalService* captive_portal_service = 289 ssl_error_classification.RecordCaptivePortalUMAStatistics(
324 CaptivePortalServiceFactory::GetForProfile(profile); 290 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 291 #endif
331 292
332 // Creating an interstitial without showing (e.g. from chrome://interstitials) 293 // Creating an interstitial without showing (e.g. from chrome://interstitials)
333 // it leaks memory, so don't create it here. 294 // it leaks memory, so don't create it here.
334 } 295 }
335 296
336 SSLBlockingPage::~SSLBlockingPage() { 297 SSLBlockingPage::~SSLBlockingPage() {
298 SSLErrorClassification ssl_error_classification(
299 web_contents_,
300 base::Time::NowFromSystemTime(),
301 request_url_,
302 cert_error_,
303 *ssl_info_.cert.get());
304 SSLErrorInfo::ErrorType type =
305 SSLErrorInfo::NetErrorToErrorType(cert_error_);
306 switch (type) {
307 case SSLErrorInfo::CERT_DATE_INVALID: {
308 ssl_error_classification.InvalidDateSeverityScore();
felt 2014/08/07 23:17:10 It would make sense to specify in a comment that t
radhikabhar 2014/08/07 23:25:22 Done.
309 break;
felt 2014/08/07 23:17:10 With that being said, does it make sense to factor
radhikabhar 2014/08/07 23:25:22 No it doesn't. I just added it here for consistenc
felt 2014/08/07 23:31:12 I suppose it doesn't hurt.
310 }
311 case SSLErrorInfo::CERT_AUTHORITY_INVALID: {
312 ssl_error_classification.InvalidCommonNameSeverityScore();
313 break;
314 }
315 default:
316 break;
317 }
318
337 if (!callback_.is_null()) { 319 if (!callback_.is_null()) {
338 RecordSSLBlockingPageDetailedStats(false, 320 RecordSSLBlockingPageDetailedStats(false,
339 cert_error_, 321 cert_error_,
340 overridable_ && !strict_enforcement_, 322 overridable_ && !strict_enforcement_,
341 internal_, 323 internal_,
342 num_visits_, 324 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 325 // The page is closed without the user having chosen what to do, default to
348 // deny. 326 // deny.
349 NotifyDenyCertificate(); 327 NotifyDenyCertificate();
350 } 328 }
351 } 329 }
352 330
353 void SSLBlockingPage::Show() { 331 void SSLBlockingPage::Show() {
354 DCHECK(!interstitial_page_); 332 DCHECK(!interstitial_page_);
355 interstitial_page_ = InterstitialPage::Create( 333 interstitial_page_ = InterstitialPage::Create(
356 web_contents_, true, request_url_, this); 334 web_contents_, true, request_url_, this);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 Profile* profile = Profile::FromBrowserContext( 492 Profile* profile = Profile::FromBrowserContext(
515 web_contents_->GetBrowserContext()); 493 web_contents_->GetBrowserContext());
516 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); 494 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile);
517 } 495 }
518 496
519 void SSLBlockingPage::OnProceed() { 497 void SSLBlockingPage::OnProceed() {
520 RecordSSLBlockingPageDetailedStats(true, 498 RecordSSLBlockingPageDetailedStats(true,
521 cert_error_, 499 cert_error_,
522 overridable_ && !strict_enforcement_, 500 overridable_ && !strict_enforcement_,
523 internal_, 501 internal_,
524 num_visits_, 502 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. 503 // Accepting the certificate resumes the loading of the page.
530 NotifyAllowCertificate(); 504 NotifyAllowCertificate();
531 } 505 }
532 506
533 void SSLBlockingPage::OnDontProceed() { 507 void SSLBlockingPage::OnDontProceed() {
534 RecordSSLBlockingPageDetailedStats(false, 508 RecordSSLBlockingPageDetailedStats(false,
535 cert_error_, 509 cert_error_,
536 overridable_ && !strict_enforcement_, 510 overridable_ && !strict_enforcement_,
537 internal_, 511 internal_,
538 num_visits_, 512 num_visits_);
539 captive_portal_detection_enabled_,
540 captive_portal_probe_completed_,
541 captive_portal_no_response_,
542 captive_portal_detected_);
543 NotifyDenyCertificate(); 513 NotifyDenyCertificate();
544 } 514 }
545 515
546 void SSLBlockingPage::NotifyDenyCertificate() { 516 void SSLBlockingPage::NotifyDenyCertificate() {
547 // It's possible that callback_ may not exist if the user clicks "Proceed" 517 // 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. 518 // followed by pressing the back button before the interstitial is hidden.
549 // In that case the certificate will still be treated as allowed. 519 // In that case the certificate will still be treated as allowed.
550 if (callback_.is_null()) 520 if (callback_.is_null())
551 return; 521 return;
552 522
(...skipping 23 matching lines...) Expand all
576 for (; i < 5; i++) { 546 for (; i < 5; i++) {
577 strings->SetString(keys[i], std::string()); 547 strings->SetString(keys[i], std::string());
578 } 548 }
579 } 549 }
580 550
581 void SSLBlockingPage::OnGotHistoryCount(bool success, 551 void SSLBlockingPage::OnGotHistoryCount(bool success,
582 int num_visits, 552 int num_visits,
583 base::Time first_visit) { 553 base::Time first_visit) {
584 num_visits_ = num_visits; 554 num_visits_ = num_visits;
585 } 555 }
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