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

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

Issue 318213002: Add custom interstitial for captive portals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Const all the things Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ssl/ssl_error_handler.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/time/time.h"
9 #include "base/timer/timer.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ssl/captive_portal_blocking_page.h"
12 #include "chrome/browser/ssl/ssl_blocking_page.h"
13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/notification_source.h"
15 #include "content/public/browser/web_contents.h"
16
17 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
18 #include "chrome/browser/captive_portal/captive_portal_service.h"
19 #include "chrome/browser/captive_portal/captive_portal_service_factory.h"
20 #endif
21
22 namespace {
23 // The delay before displaying the SSL interstitial, during which we wait for a
24 // captive portal result.
25 const int kDefaultSSLInterstitialDisplayDelay = 2;
26
27 // Events for UMA.
28 enum SSLErrorHandlerEvent {
29 HANDLE_ALL,
30 CAPTIVE_PORTAL_CHECK,
31 CAPTIVE_PORTAL_RESULT_ALREADY_HANDLED,
32 CAPTIVE_PORTAL_RESULT_BEFORE_TIMER,
33 SSL_WARNING_ALREADY_HANDLED,
34 SHOW_CAPTIVE_PORTAL_INTERSTITIAL,
35 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE,
36 SHOW_SSL_INTERSTITIAL,
37 SHOW_SSL_INTERSTITIAL_OVERRIDABLE,
38 SHOW_SSL_INTERSTITIAL_WITHOUT_CAPTIVE_PORTAL_CHECK,
39 SHOW_SSL_INTERSTITIAL_WITHOUT_CAPTIVE_PORTAL_CHECK_OVERRIDABLE,
40 SSL_ERROR_HANDLER_EVENT_COUNT
41 };
42
43 void RecordUMA(SSLErrorHandlerEvent event) {
44 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_handler",
45 event,
46 SSL_ERROR_HANDLER_EVENT_COUNT);
47 }
48
49 } // namespace
50
51 SSLErrorHandler::SSLErrorHandler(content::WebContents* web_contents,
52 int cert_error,
53 const net::SSLInfo& ssl_info,
54 const GURL& request_url,
55 bool overridable,
56 bool strict_enforcement,
57 const base::Callback<void(bool)>& callback)
58 : content::WebContentsObserver(web_contents),
59 web_contents_(web_contents),
60 cert_error_(cert_error),
61 ssl_info_(ssl_info),
62 request_url_(request_url),
63 overridable_(overridable),
64 strict_enforcement_(strict_enforcement),
65 callback_(callback),
66 handled_(false),
67 ssl_interstitial_display_delay_(
68 base::TimeDelta::FromSeconds(kDefaultSSLInterstitialDisplayDelay)) {
69 }
70
71 SSLErrorHandler::~SSLErrorHandler() {
72 }
73
74 void SSLErrorHandler::Handle() {
75 RecordUMA(HANDLE_ALL);
76 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
77 CheckForCaptivePortal();
78 timer_.Start(FROM_HERE, ssl_interstitial_display_delay_,
79 base::Bind(&SSLErrorHandler::OnTimerExpired,
80 base::Unretained(this)));
81 #else
82 RecordUMA(overridable_ && !strict_enforcement_ ?
83 SHOW_SSL_INTERSTITIAL_WITHOUT_CAPTIVE_PORTAL_CHECK_OVERRIDABLE :
84 SHOW_SSL_INTERSTITIAL_WITHOUT_CAPTIVE_PORTAL_CHECK);
85 ShowSSLInterstitial();
86 handled_ = true;
87 #endif
88 }
89
90 void SSLErrorHandler::CheckForCaptivePortal() {
91 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
92 RecordUMA(CAPTIVE_PORTAL_CHECK);
93 Profile* profile = Profile::FromBrowserContext(
94 web_contents_->GetBrowserContext());
95 CaptivePortalService* captive_portal_service =
96 CaptivePortalServiceFactory::GetForProfile(profile);
97 captive_portal_service->DetectCaptivePortal();
98 registrar_.Add(this,
99 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
100 content::Source<Profile>(profile));
101 #endif
102 }
103
104 void SSLErrorHandler::Observe(
105 int type,
106 const content::NotificationSource& source,
107 const content::NotificationDetails& details) {
108 // TODO(meacer): Refactor this method in SSLBlockingPage.
109 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
110 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) {
111 CaptivePortalService::Results* results =
112 content::Details<CaptivePortalService::Results>(details).ptr();
113 if (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL)
114 OnCaptivePortalResult();
115 }
116 #endif
117 }
118
119 void SSLErrorHandler::OnCaptivePortalResult() {
120 if (!timer_.IsRunning()) {
mmenke 2014/06/24 18:09:26 Could theoretically get results from captive porta
121 RecordUMA(CAPTIVE_PORTAL_RESULT_BEFORE_TIMER);
mmenke 2014/06/24 18:09:27 Shouldn't this be CAPTIVE_PORTAL_RESULT_AFTER_TIME
122 return;
123 }
124 if (handled_) {
125 RecordUMA(CAPTIVE_PORTAL_RESULT_ALREADY_HANDLED);
126 return;
127 }
128 timer_.Stop();
129 ShowCaptivePortalInterstitial();
130 handled_ = true;
131 }
132
133 void SSLErrorHandler::OnTimerExpired() {
134 if (handled_) {
135 RecordUMA(SSL_WARNING_ALREADY_HANDLED);
mmenke 2014/06/24 18:09:27 Is this UMA useful? Seems like we don't care if t
meacer 2014/10/22 23:04:29 Removed.
136 return;
137 }
138 ShowSSLInterstitial();
139 handled_ = true;
140 }
141
142 void SSLErrorHandler::ShowCaptivePortalInterstitial() {
143 // Show captive portal blocking page. The interstitial owns the blocking page.
144 RecordUMA(overridable_ && !strict_enforcement_ ?
145 SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE :
146 SHOW_CAPTIVE_PORTAL_INTERSTITIAL);
147 new CaptivePortalBlockingPage(web_contents_, request_url_);
148 }
149
150 void SSLErrorHandler::ShowSSLInterstitial() {
151 // Show SSL blocking page. The interstitial owns the blocking page.
152 RecordUMA(overridable_ && !strict_enforcement_ ?
153 SHOW_SSL_INTERSTITIAL_OVERRIDABLE :
154 SHOW_SSL_INTERSTITIAL);
155 new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_,
156 overridable_, strict_enforcement_, callback_);
157 }
158
159 void SSLErrorHandler::DidStopLoading(
160 content::RenderViewHost* render_view_host) {
161 delete this;
162 }
163
164 void SSLErrorHandler::WebContentsDestroyed() {
165 delete this;
166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698