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

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

Issue 935663004: Add checkbox for reporting invalid TLS/SSL cert chains (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use SecurityInterstitialMetricsHelper for extended reporting events Created 5 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_error_handler.h" 5 #include "chrome/browser/ssl/ssl_error_handler.h"
6 6
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/safe_browsing/ui_manager.h"
11 #include "chrome/browser/ssl/ssl_blocking_page.h" 12 #include "chrome/browser/ssl/ssl_blocking_page.h"
12 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_source.h" 14 #include "content/public/browser/notification_source.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 16
16 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 17 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
17 #include "chrome/browser/captive_portal/captive_portal_service.h" 18 #include "chrome/browser/captive_portal/captive_portal_service.h"
18 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" 19 #include "chrome/browser/captive_portal/captive_portal_service_factory.h"
19 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" 20 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
20 #include "chrome/browser/ssl/captive_portal_blocking_page.h" 21 #include "chrome/browser/ssl/captive_portal_blocking_page.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } // namespace 82 } // namespace
82 83
83 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler); 84 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler);
84 85
85 void SSLErrorHandler::HandleSSLError( 86 void SSLErrorHandler::HandleSSLError(
86 content::WebContents* web_contents, 87 content::WebContents* web_contents,
87 int cert_error, 88 int cert_error,
88 const net::SSLInfo& ssl_info, 89 const net::SSLInfo& ssl_info,
89 const GURL& request_url, 90 const GURL& request_url,
90 int options_mask, 91 int options_mask,
92 SafeBrowsingUIManager* safe_browsing_ui_manager,
91 const base::Callback<void(bool)>& callback) { 93 const base::Callback<void(bool)>& callback) {
92 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 94 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
93 CaptivePortalTabHelper* captive_portal_tab_helper = 95 CaptivePortalTabHelper* captive_portal_tab_helper =
94 CaptivePortalTabHelper::FromWebContents(web_contents); 96 CaptivePortalTabHelper::FromWebContents(web_contents);
95 if (captive_portal_tab_helper) { 97 if (captive_portal_tab_helper) {
96 captive_portal_tab_helper->OnSSLCertError(ssl_info); 98 captive_portal_tab_helper->OnSSLCertError(ssl_info);
97 } 99 }
98 #endif 100 #endif
99 DCHECK(!FromWebContents(web_contents)); 101 DCHECK(!FromWebContents(web_contents));
100 web_contents->SetUserData(UserDataKey(), 102 web_contents->SetUserData(
101 new SSLErrorHandler(web_contents, cert_error, 103 UserDataKey(),
102 ssl_info, request_url, 104 new SSLErrorHandler(web_contents, cert_error, ssl_info, request_url,
103 options_mask, callback)); 105 options_mask, safe_browsing_ui_manager, callback));
104 106
105 SSLErrorHandler* error_handler = 107 SSLErrorHandler* error_handler =
106 SSLErrorHandler::FromWebContents(web_contents); 108 SSLErrorHandler::FromWebContents(web_contents);
107 error_handler->StartHandlingError(); 109 error_handler->StartHandlingError();
108 } 110 }
109 111
110 // static 112 // static
111 void SSLErrorHandler::SetInterstitialDelayTypeForTest( 113 void SSLErrorHandler::SetInterstitialDelayTypeForTest(
112 SSLErrorHandler::InterstitialDelayType delay) { 114 SSLErrorHandler::InterstitialDelayType delay) {
113 g_interstitial_delay_type = delay; 115 g_interstitial_delay_type = delay;
114 } 116 }
115 117
116 // static 118 // static
117 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest( 119 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(
118 TimerStartedCallback* callback) { 120 TimerStartedCallback* callback) {
119 DCHECK(!callback || !callback->is_null()); 121 DCHECK(!callback || !callback->is_null());
120 g_timer_started_callback = callback; 122 g_timer_started_callback = callback;
121 } 123 }
122 124
123 SSLErrorHandler::SSLErrorHandler(content::WebContents* web_contents, 125 SSLErrorHandler::SSLErrorHandler(
124 int cert_error, 126 content::WebContents* web_contents,
125 const net::SSLInfo& ssl_info, 127 int cert_error,
126 const GURL& request_url, 128 const net::SSLInfo& ssl_info,
127 int options_mask, 129 const GURL& request_url,
128 const base::Callback<void(bool)>& callback) 130 int options_mask,
131 SafeBrowsingUIManager* safe_browsing_ui_manager,
132 const base::Callback<void(bool)>& callback)
129 : web_contents_(web_contents), 133 : web_contents_(web_contents),
130 cert_error_(cert_error), 134 cert_error_(cert_error),
131 ssl_info_(ssl_info), 135 ssl_info_(ssl_info),
132 request_url_(request_url), 136 request_url_(request_url),
133 options_mask_(options_mask), 137 options_mask_(options_mask),
134 callback_(callback) { 138 callback_(callback),
139 safe_browsing_ui_manager_(safe_browsing_ui_manager) {
135 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 140 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
136 Profile* profile = Profile::FromBrowserContext( 141 Profile* profile = Profile::FromBrowserContext(
137 web_contents->GetBrowserContext()); 142 web_contents->GetBrowserContext());
138 registrar_.Add(this, 143 registrar_.Add(this,
139 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, 144 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
140 content::Source<Profile>(profile)); 145 content::Source<Profile>(profile));
141 #endif 146 #endif
142 } 147 }
143 148
144 SSLErrorHandler::~SSLErrorHandler() { 149 SSLErrorHandler::~SSLErrorHandler() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 #endif 199 #endif
195 } 200 }
196 201
197 void SSLErrorHandler::ShowSSLInterstitial() { 202 void SSLErrorHandler::ShowSSLInterstitial() {
198 // Show SSL blocking page. The interstitial owns the blocking page. 203 // Show SSL blocking page. The interstitial owns the blocking page.
199 RecordUMA(SSLBlockingPage::IsOptionsOverridable(options_mask_) ? 204 RecordUMA(SSLBlockingPage::IsOptionsOverridable(options_mask_) ?
200 SHOW_SSL_INTERSTITIAL_OVERRIDABLE : 205 SHOW_SSL_INTERSTITIAL_OVERRIDABLE :
201 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE); 206 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE);
202 (new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_, 207 (new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_,
203 options_mask_, base::Time::NowFromSystemTime(), 208 options_mask_, base::Time::NowFromSystemTime(),
204 callback_))->Show(); 209 safe_browsing_ui_manager_, callback_))->Show();
205 // Once an interstitial is displayed, no need to keep the handler around. 210 // Once an interstitial is displayed, no need to keep the handler around.
206 // This is the equivalent of "delete this". 211 // This is the equivalent of "delete this".
207 web_contents_->RemoveUserData(UserDataKey()); 212 web_contents_->RemoveUserData(UserDataKey());
208 } 213 }
209 214
210 void SSLErrorHandler::Observe( 215 void SSLErrorHandler::Observe(
211 int type, 216 int type,
212 const content::NotificationSource& source, 217 const content::NotificationSource& source,
213 const content::NotificationDetails& details) { 218 const content::NotificationDetails& details) {
214 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 219 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
215 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) { 220 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) {
216 timer_.Stop(); 221 timer_.Stop();
217 CaptivePortalService::Results* results = 222 CaptivePortalService::Results* results =
218 content::Details<CaptivePortalService::Results>(details).ptr(); 223 content::Details<CaptivePortalService::Results>(details).ptr();
219 if (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL) 224 if (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL)
220 ShowCaptivePortalInterstitial(results->landing_url); 225 ShowCaptivePortalInterstitial(results->landing_url);
221 else 226 else
222 ShowSSLInterstitial(); 227 ShowSSLInterstitial();
223 } 228 }
224 #endif 229 #endif
225 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698