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

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: Added function call Created 6 years, 5 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 DONT_PROCEED_NAME, 114 DONT_PROCEED_NAME,
120 DONT_PROCEED_DATE, 115 DONT_PROCEED_DATE,
121 DONT_PROCEED_AUTHORITY, 116 DONT_PROCEED_AUTHORITY,
122 MORE, 117 MORE,
123 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated. 118 SHOW_UNDERSTAND, // Used by the summer 2013 Finch trial. Deprecated.
124 SHOW_INTERNAL_HOSTNAME, 119 SHOW_INTERNAL_HOSTNAME,
125 PROCEED_INTERNAL_HOSTNAME, 120 PROCEED_INTERNAL_HOSTNAME,
126 SHOW_NEW_SITE, 121 SHOW_NEW_SITE,
127 PROCEED_NEW_SITE, 122 PROCEED_NEW_SITE,
128 PROCEED_MANUAL_NONOVERRIDABLE, 123 PROCEED_MANUAL_NONOVERRIDABLE,
129 CAPTIVE_PORTAL_DETECTION_ENABLED, 124 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED, // Captive Portal errors moved
130 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, 125 DEPRECATED_CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE, // to
131 CAPTIVE_PORTAL_PROBE_COMPLETED, 126 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED, // ssl_error_classification.
132 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE, 127 DEPRECATED_CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE,
133 CAPTIVE_PORTAL_NO_RESPONSE, 128 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE,
134 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE, 129 DEPRECATED_CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE,
135 CAPTIVE_PORTAL_DETECTED, 130 DEPRECATED_CAPTIVE_PORTAL_DETECTED,
136 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE, 131 DEPRECATED_CAPTIVE_PORTAL_DETECTED_OVERRIDABLE,
137 UNUSED_BLOCKING_PAGE_EVENT, 132 UNUSED_BLOCKING_PAGE_EVENT,
138 }; 133 };
139 134
140 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { 135 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) {
141 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", 136 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl",
142 event, 137 event,
143 UNUSED_BLOCKING_PAGE_EVENT); 138 UNUSED_BLOCKING_PAGE_EVENT);
144 } 139 }
145 140
146 void RecordSSLBlockingPageDetailedStats( 141 void RecordSSLBlockingPageDetailedStats(
147 bool proceed, 142 bool proceed,
148 int cert_error, 143 int cert_error,
149 bool overridable, 144 bool overridable,
150 bool internal, 145 bool internal,
151 int num_visits, 146 int num_visits) {
152 bool captive_portal_detection_enabled,
153 bool captive_portal_probe_completed,
154 bool captive_portal_no_response,
155 bool captive_portal_detected) {
156 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", 147 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type",
157 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); 148 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM);
158 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
159 if (captive_portal_detection_enabled)
160 RecordSSLBlockingPageEventStats(
161 overridable ?
162 CAPTIVE_PORTAL_DETECTION_ENABLED_OVERRIDABLE :
163 CAPTIVE_PORTAL_DETECTION_ENABLED);
164 if (captive_portal_probe_completed)
165 RecordSSLBlockingPageEventStats(
166 overridable ?
167 CAPTIVE_PORTAL_PROBE_COMPLETED_OVERRIDABLE :
168 CAPTIVE_PORTAL_PROBE_COMPLETED);
169 // Log only one of portal detected and no response results.
170 if (captive_portal_detected)
171 RecordSSLBlockingPageEventStats(
172 overridable ?
173 CAPTIVE_PORTAL_DETECTED_OVERRIDABLE :
174 CAPTIVE_PORTAL_DETECTED);
175 else if (captive_portal_no_response)
176 RecordSSLBlockingPageEventStats(
177 overridable ?
178 CAPTIVE_PORTAL_NO_RESPONSE_OVERRIDABLE :
179 CAPTIVE_PORTAL_NO_RESPONSE);
180 #endif
181 if (!overridable) { 149 if (!overridable) {
182 if (proceed) { 150 if (proceed) {
183 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE); 151 RecordSSLBlockingPageEventStats(PROCEED_MANUAL_NONOVERRIDABLE);
184 } 152 }
185 // Overridable is false if the user didn't have any option except to turn 153 // Overridable is false if the user didn't have any option except to turn
186 // back. If that's the case, don't record some of the metrics. 154 // back. If that's the case, don't record some of the metrics.
187 return; 155 return;
188 } 156 }
189 if (num_visits == 0) 157 if (num_visits == 0)
190 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); 158 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 const base::Callback<void(bool)>& callback) 282 const base::Callback<void(bool)>& callback)
315 : callback_(callback), 283 : callback_(callback),
316 web_contents_(web_contents), 284 web_contents_(web_contents),
317 cert_error_(cert_error), 285 cert_error_(cert_error),
318 ssl_info_(ssl_info), 286 ssl_info_(ssl_info),
319 request_url_(request_url), 287 request_url_(request_url),
320 overridable_(overridable), 288 overridable_(overridable),
321 strict_enforcement_(strict_enforcement), 289 strict_enforcement_(strict_enforcement),
322 internal_(false), 290 internal_(false),
323 num_visits_(-1), 291 num_visits_(-1),
324 captive_portal_detection_enabled_(false),
325 captive_portal_probe_completed_(false),
326 captive_portal_no_response_(false),
327 captive_portal_detected_(false),
328 trial_condition_(GetTrialCondition()) { 292 trial_condition_(GetTrialCondition()) {
329 Profile* profile = Profile::FromBrowserContext( 293 Profile* profile = Profile::FromBrowserContext(
330 web_contents->GetBrowserContext()); 294 web_contents->GetBrowserContext());
331 // For UMA stats. 295 // For UMA stats.
332 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) 296 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets()))
333 internal_ = true; 297 internal_ = true;
334 RecordSSLBlockingPageEventStats(SHOW_ALL); 298 RecordSSLBlockingPageEventStats(SHOW_ALL);
335 if (overridable_ && !strict_enforcement_) { 299 if (overridable_ && !strict_enforcement_) {
336 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); 300 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE);
337 if (internal_) 301 if (internal_)
338 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); 302 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME);
339 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 303 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
340 profile, Profile::EXPLICIT_ACCESS); 304 profile, Profile::EXPLICIT_ACCESS);
341 if (history_service) { 305 if (history_service) {
342 history_service->GetVisibleVisitCountToHost( 306 history_service->GetVisibleVisitCountToHost(
343 request_url_, 307 request_url_,
344 base::Bind(&SSLBlockingPage::OnGotHistoryCount, 308 base::Bind(&SSLBlockingPage::OnGotHistoryCount,
345 base::Unretained(this)), 309 base::Unretained(this)),
346 &request_tracker_); 310 &request_tracker_);
347 } 311 }
348 } 312 }
313
314 SSLErrorClassification ssl_error_classification(
315 web_contents_,
316 base::Time::NowFromSystemTime(),
317 *ssl_info_.cert.get());
349 if (SSLErrorInfo::NetErrorToErrorType(cert_error_) == 318 if (SSLErrorInfo::NetErrorToErrorType(cert_error_) ==
350 SSLErrorInfo::CERT_DATE_INVALID) { 319 SSLErrorInfo::CERT_DATE_INVALID) {
351 SSLErrorClassification::RecordUMAStatistics(overridable_ && 320 ssl_error_classification.RecordUMAStatistics(
352 !strict_enforcement_); 321 overridable_ && !strict_enforcement_);
353 } 322 }
354 323
355 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 324 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
356 CaptivePortalService* captive_portal_service = 325 ssl_error_classification.RecordCaptivePortalUMAStatistics(
357 CaptivePortalServiceFactory::GetForProfile(profile); 326 overridable_ && !strict_enforcement_);
meacer 2014/07/24 00:46:30 Maybe you can add a public method to SSLErrorClass
358 captive_portal_detection_enabled_ = captive_portal_service ->enabled();
359 captive_portal_service ->DetectCaptivePortal();
360 registrar_.Add(this,
361 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
362 content::Source<Profile>(profile));
363 #endif 327 #endif
364 328
365 interstitial_page_ = InterstitialPage::Create( 329 interstitial_page_ = InterstitialPage::Create(
366 web_contents_, true, request_url, this); 330 web_contents_, true, request_url, this);
367 interstitial_page_->Show(); 331 interstitial_page_->Show();
368 } 332 }
369 333
370 SSLBlockingPage::~SSLBlockingPage() { 334 SSLBlockingPage::~SSLBlockingPage() {
371 if (!callback_.is_null()) { 335 if (!callback_.is_null()) {
372 RecordSSLBlockingPageDetailedStats(false, 336 RecordSSLBlockingPageDetailedStats(false,
373 cert_error_, 337 cert_error_,
374 overridable_ && !strict_enforcement_, 338 overridable_ && !strict_enforcement_,
375 internal_, 339 internal_,
376 num_visits_, 340 num_visits_);
377 captive_portal_detection_enabled_,
378 captive_portal_probe_completed_,
379 captive_portal_no_response_,
380 captive_portal_detected_);
381 // The page is closed without the user having chosen what to do, default to 341 // The page is closed without the user having chosen what to do, default to
382 // deny. 342 // deny.
383 NotifyDenyCertificate(); 343 NotifyDenyCertificate();
384 } 344 }
385 } 345 }
386 346
387 std::string SSLBlockingPage::GetHTMLContents() { 347 std::string SSLBlockingPage::GetHTMLContents() {
388 if (trial_condition_ == kCondV1 || trial_condition_ == kCondV1LayoutV2Text) 348 if (trial_condition_ == kCondV1 || trial_condition_ == kCondV1LayoutV2Text)
389 return GetHTMLContentsV1(); 349 return GetHTMLContentsV1();
390 return GetHTMLContentsV2(); 350 return GetHTMLContentsV2();
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 load_time_data.SetString( 548 load_time_data.SetString(
589 "primaryParagraph", 549 "primaryParagraph",
590 l10n_util::GetStringFUTF16(IDS_SSL_V2_PRIMARY_PARAGRAPH, url)); 550 l10n_util::GetStringFUTF16(IDS_SSL_V2_PRIMARY_PARAGRAPH, url));
591 } 551 }
592 load_time_data.SetString( 552 load_time_data.SetString(
593 "openDetails", 553 "openDetails",
594 l10n_util::GetStringUTF16(IDS_SSL_V2_OPEN_DETAILS_BUTTON)); 554 l10n_util::GetStringUTF16(IDS_SSL_V2_OPEN_DETAILS_BUTTON));
595 load_time_data.SetString( 555 load_time_data.SetString(
596 "closeDetails", 556 "closeDetails",
597 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOSE_DETAILS_BUTTON)); 557 l10n_util::GetStringUTF16(IDS_SSL_V2_CLOSE_DETAILS_BUTTON));
598 load_time_data.SetString("errorCode", net::ErrorToString(cert_error_));
599 558
600 if (overridable_ && !strict_enforcement_) { // Overridable. 559 if (overridable_ && !strict_enforcement_) { // Overridable.
601 SSLErrorInfo error_info = 560 SSLErrorInfo error_info =
602 SSLErrorInfo::CreateError( 561 SSLErrorInfo::CreateError(
603 SSLErrorInfo::NetErrorToErrorType(cert_error_), 562 SSLErrorInfo::NetErrorToErrorType(cert_error_),
604 ssl_info_.cert.get(), 563 ssl_info_.cert.get(),
605 request_url_); 564 request_url_);
606 load_time_data.SetString( 565 load_time_data.SetString(
607 "explanationParagraph", error_info.details()); 566 "explanationParagraph", error_info.details());
608 load_time_data.SetString( 567 load_time_data.SetString(
(...skipping 26 matching lines...) Expand all
635 break; 594 break;
636 case SSLErrorInfo::CERT_INVALID: 595 case SSLErrorInfo::CERT_INVALID:
637 help_string = IDS_SSL_NONOVERRIDABLE_INVALID; 596 help_string = IDS_SSL_NONOVERRIDABLE_INVALID;
638 break; 597 break;
639 default: 598 default:
640 if (strict_enforcement_) 599 if (strict_enforcement_)
641 help_string = IDS_SSL_NONOVERRIDABLE_HSTS; 600 help_string = IDS_SSL_NONOVERRIDABLE_HSTS;
642 } 601 }
643 load_time_data.SetString( 602 load_time_data.SetString(
644 "finalParagraph", l10n_util::GetStringFUTF16(help_string, url)); 603 "finalParagraph", l10n_util::GetStringFUTF16(help_string, url));
604 load_time_data.SetString("errorCode", net::ErrorToString(cert_error_));
645 } 605 }
646 606
647 base::StringPiece html( 607 base::StringPiece html(
648 ResourceBundle::GetSharedInstance().GetRawDataResource( 608 ResourceBundle::GetSharedInstance().GetRawDataResource(
649 IRD_SSL_INTERSTITIAL_V2_HTML)); 609 IRD_SSL_INTERSTITIAL_V2_HTML));
650 webui::UseVersion2 version; 610 webui::UseVersion2 version;
651 return webui::GetI18nTemplateHtml(html, &load_time_data); 611 return webui::GetI18nTemplateHtml(html, &load_time_data);
652 } 612 }
653 613
654 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) { 614 void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 Profile* profile = Profile::FromBrowserContext( 669 Profile* profile = Profile::FromBrowserContext(
710 web_contents_->GetBrowserContext()); 670 web_contents_->GetBrowserContext());
711 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); 671 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile);
712 } 672 }
713 673
714 void SSLBlockingPage::OnProceed() { 674 void SSLBlockingPage::OnProceed() {
715 RecordSSLBlockingPageDetailedStats(true, 675 RecordSSLBlockingPageDetailedStats(true,
716 cert_error_, 676 cert_error_,
717 overridable_ && !strict_enforcement_, 677 overridable_ && !strict_enforcement_,
718 internal_, 678 internal_,
719 num_visits_, 679 num_visits_);
720 captive_portal_detection_enabled_,
721 captive_portal_probe_completed_,
722 captive_portal_no_response_,
723 captive_portal_detected_);
724 // Accepting the certificate resumes the loading of the page. 680 // Accepting the certificate resumes the loading of the page.
725 NotifyAllowCertificate(); 681 NotifyAllowCertificate();
726 } 682 }
727 683
728 void SSLBlockingPage::OnDontProceed() { 684 void SSLBlockingPage::OnDontProceed() {
729 RecordSSLBlockingPageDetailedStats(false, 685 RecordSSLBlockingPageDetailedStats(false,
730 cert_error_, 686 cert_error_,
731 overridable_ && !strict_enforcement_, 687 overridable_ && !strict_enforcement_,
732 internal_, 688 internal_,
733 num_visits_, 689 num_visits_);
734 captive_portal_detection_enabled_,
735 captive_portal_probe_completed_,
736 captive_portal_no_response_,
737 captive_portal_detected_);
738 NotifyDenyCertificate(); 690 NotifyDenyCertificate();
739 } 691 }
740 692
741 void SSLBlockingPage::NotifyDenyCertificate() { 693 void SSLBlockingPage::NotifyDenyCertificate() {
742 // It's possible that callback_ may not exist if the user clicks "Proceed" 694 // It's possible that callback_ may not exist if the user clicks "Proceed"
743 // followed by pressing the back button before the interstitial is hidden. 695 // followed by pressing the back button before the interstitial is hidden.
744 // In that case the certificate will still be treated as allowed. 696 // In that case the certificate will still be treated as allowed.
745 if (callback_.is_null()) 697 if (callback_.is_null())
746 return; 698 return;
747 699
(...skipping 23 matching lines...) Expand all
771 for (; i < 5; i++) { 723 for (; i < 5; i++) {
772 strings->SetString(keys[i], std::string()); 724 strings->SetString(keys[i], std::string());
773 } 725 }
774 } 726 }
775 727
776 void SSLBlockingPage::OnGotHistoryCount(bool success, 728 void SSLBlockingPage::OnGotHistoryCount(bool success,
777 int num_visits, 729 int num_visits,
778 base::Time first_visit) { 730 base::Time first_visit) {
779 num_visits_ = num_visits; 731 num_visits_ = num_visits;
780 } 732 }
781
782 void SSLBlockingPage::Observe(
783 int type,
784 const content::NotificationSource& source,
785 const content::NotificationDetails& details) {
786 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
787 // When detection is disabled, captive portal service always sends
788 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case.
789 if (!captive_portal_detection_enabled_)
790 return;
791 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) {
792 captive_portal_probe_completed_ = true;
793 CaptivePortalService::Results* results =
794 content::Details<CaptivePortalService::Results>(
795 details).ptr();
796 // If a captive portal was detected at any point when the interstitial was
797 // displayed, assume that the interstitial was caused by a captive portal.
798 // Example scenario:
799 // 1- Interstitial displayed and captive portal detected, setting the flag.
800 // 2- Captive portal detection automatically opens portal login page.
801 // 3- User logs in on the portal login page.
802 // A notification will be received here for RESULT_INTERNET_CONNECTED. Make
803 // sure we don't clear the captive portal flag, since the interstitial was
804 // potentially caused by the captive portal.
805 captive_portal_detected_ = captive_portal_detected_ ||
806 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL);
807 // Also keep track of non-HTTP portals and error cases.
808 captive_portal_no_response_ = captive_portal_no_response_ ||
809 (results->result == captive_portal::RESULT_NO_RESPONSE);
810 }
811 #endif
812 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698