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

Side by Side Diff: content/browser/ssl/ssl_manager.cc

Issue 2869103002: [Android WebView] Propagate Java exceptions thrown in OnReceivedSslError (Closed)
Patch Set: Add comments to ssl_manager.h as well. Created 3 years, 7 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 "content/browser/ssl/ssl_manager.h" 5 #include "content/browser/ssl/ssl_manager.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 90
91 std::set<SSLManager*>& get() { return set_; } 91 std::set<SSLManager*>& get() { return set_; }
92 92
93 private: 93 private:
94 std::set<SSLManager*> set_; 94 std::set<SSLManager*> set_;
95 95
96 DISALLOW_COPY_AND_ASSIGN(SSLManagerSet); 96 DISALLOW_COPY_AND_ASSIGN(SSLManagerSet);
97 }; 97 };
98 98
99 // On Android, HandleSSLErrorOnUI can cause a Java exception to be thrown - in
100 // such a case we cannot allow calls back into Java afterwards. Make sure that
101 // nothing calls into Java after calling this method - the easiest way to do so
102 // is to post this as a separate task.
99 void HandleSSLErrorOnUI( 103 void HandleSSLErrorOnUI(
100 const base::Callback<WebContents*(void)>& web_contents_getter, 104 const base::Callback<WebContents*(void)>& web_contents_getter,
101 const base::WeakPtr<SSLErrorHandler::Delegate>& delegate, 105 const base::WeakPtr<SSLErrorHandler::Delegate>& delegate,
102 const ResourceType resource_type, 106 const ResourceType resource_type,
103 const GURL& url, 107 const GURL& url,
104 const net::SSLInfo& ssl_info, 108 const net::SSLInfo& ssl_info,
105 bool fatal) { 109 bool fatal) {
106 content::WebContents* web_contents = web_contents_getter.Run(); 110 content::WebContents* web_contents = web_contents_getter.Run();
107 std::unique_ptr<SSLErrorHandler> handler(new SSLErrorHandler( 111 std::unique_ptr<SSLErrorHandler> handler(new SSLErrorHandler(
108 web_contents, delegate, resource_type, url, ssl_info, fatal)); 112 web_contents, delegate, resource_type, url, ssl_info, fatal));
109 113
110 if (!web_contents) { 114 if (!web_contents) {
111 // Requests can fail to dispatch because they don't have a WebContents. See 115 // Requests can fail to dispatch because they don't have a WebContents. See
112 // https://crbug.com/86537. In this case we have to make a decision in this 116 // https://crbug.com/86537. In this case we have to make a decision in this
113 // function, so we ignore revocation check failures. 117 // function, so we ignore revocation check failures.
114 if (net::IsCertStatusMinorError(ssl_info.cert_status)) { 118 if (net::IsCertStatusMinorError(ssl_info.cert_status)) {
115 handler->ContinueRequest(); 119 handler->ContinueRequest();
116 } else { 120 } else {
117 handler->CancelRequest(); 121 handler->CancelRequest();
118 } 122 }
119 return; 123 return;
120 } 124 }
121 125
122 NavigationControllerImpl* controller = 126 NavigationControllerImpl* controller =
123 static_cast<NavigationControllerImpl*>(&web_contents->GetController()); 127 static_cast<NavigationControllerImpl*>(&web_contents->GetController());
124 controller->SetPendingNavigationSSLError(true); 128 controller->SetPendingNavigationSSLError(true);
125 129
126 SSLManager* manager = controller->ssl_manager(); 130 SSLManager* manager = controller->ssl_manager();
127 manager->OnCertError(std::move(handler)); 131 manager->OnCertError(std::move(handler));
132 // On Android, OnCertError can cause a Java exception to be thrown - in such a
133 // case we cannot allow calls back into Java here. If adding any additional
134 // code here, make sure it cannot call into Java.
128 } 135 }
129 136
130 } // namespace 137 } // namespace
131 138
132 // static 139 // static
133 void SSLManager::OnSSLCertificateError( 140 void SSLManager::OnSSLCertificateError(
134 const base::WeakPtr<SSLErrorHandler::Delegate>& delegate, 141 const base::WeakPtr<SSLErrorHandler::Delegate>& delegate,
135 const ResourceType resource_type, 142 const ResourceType resource_type,
136 const GURL& url, 143 const GURL& url,
137 const base::Callback<WebContents*(void)>& web_contents_getter, 144 const base::Callback<WebContents*(void)>& web_contents_getter,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 case net::ERR_CERT_NAME_CONSTRAINT_VIOLATION: 310 case net::ERR_CERT_NAME_CONSTRAINT_VIOLATION:
304 case net::ERR_CERT_VALIDITY_TOO_LONG: 311 case net::ERR_CERT_VALIDITY_TOO_LONG:
305 case net::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED: 312 case net::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED:
306 if (!handler->fatal()) 313 if (!handler->fatal())
307 options_mask |= OVERRIDABLE; 314 options_mask |= OVERRIDABLE;
308 else 315 else
309 options_mask |= STRICT_ENFORCEMENT; 316 options_mask |= STRICT_ENFORCEMENT;
310 if (expired_previous_decision) 317 if (expired_previous_decision)
311 options_mask |= EXPIRED_PREVIOUS_DECISION; 318 options_mask |= EXPIRED_PREVIOUS_DECISION;
312 OnCertErrorInternal(std::move(handler), options_mask); 319 OnCertErrorInternal(std::move(handler), options_mask);
320 // On Android, OnCertErrorInternal can cause a Java exception to be thrown
321 // - in such a case we cannot allow calls back into Java here. If adding
322 // any additional code here, make sure it cannot call into Java.
313 break; 323 break;
314 case net::ERR_CERT_NO_REVOCATION_MECHANISM: 324 case net::ERR_CERT_NO_REVOCATION_MECHANISM:
315 // Ignore this error. 325 // Ignore this error.
316 handler->ContinueRequest(); 326 handler->ContinueRequest();
317 break; 327 break;
318 case net::ERR_CERT_UNABLE_TO_CHECK_REVOCATION: 328 case net::ERR_CERT_UNABLE_TO_CHECK_REVOCATION:
319 // We ignore this error but will show a warning status in the location 329 // We ignore this error but will show a warning status in the location
320 // bar. 330 // bar.
321 handler->ContinueRequest(); 331 handler->ContinueRequest();
322 break; 332 break;
323 case net::ERR_CERT_CONTAINS_ERRORS: 333 case net::ERR_CERT_CONTAINS_ERRORS:
324 case net::ERR_CERT_REVOKED: 334 case net::ERR_CERT_REVOKED:
325 case net::ERR_CERT_INVALID: 335 case net::ERR_CERT_INVALID:
326 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY: 336 case net::ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
327 case net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN: 337 case net::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN:
328 if (handler->fatal()) 338 if (handler->fatal())
329 options_mask |= STRICT_ENFORCEMENT; 339 options_mask |= STRICT_ENFORCEMENT;
330 if (expired_previous_decision) 340 if (expired_previous_decision)
331 options_mask |= EXPIRED_PREVIOUS_DECISION; 341 options_mask |= EXPIRED_PREVIOUS_DECISION;
332 OnCertErrorInternal(std::move(handler), options_mask); 342 OnCertErrorInternal(std::move(handler), options_mask);
343 // On Android, OnCertErrorInternal can cause a Java exception to be thrown
344 // - in such a case we cannot allow calls back into Java here. If adding
345 // any additional code here, make sure it cannot call into Java.
333 break; 346 break;
334 default: 347 default:
335 NOTREACHED(); 348 NOTREACHED();
336 handler->CancelRequest(); 349 handler->CancelRequest();
337 break; 350 break;
338 } 351 }
339 } 352 }
340 353
341 void SSLManager::DidStartResourceResponse(const GURL& url, 354 void SSLManager::DidStartResourceResponse(const GURL& url,
342 bool has_certificate, 355 bool has_certificate,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 callback))) { 405 callback))) {
393 return; 406 return;
394 } 407 }
395 } 408 }
396 } 409 }
397 410
398 GetContentClient()->browser()->AllowCertificateError( 411 GetContentClient()->browser()->AllowCertificateError(
399 web_contents, cert_error, ssl_info, request_url, resource_type, 412 web_contents, cert_error, ssl_info, request_url, resource_type,
400 overridable, strict_enforcement, expired_previous_decision, 413 overridable, strict_enforcement, expired_previous_decision,
401 base::Bind(&OnAllowCertificateWithRecordDecision, true, callback)); 414 base::Bind(&OnAllowCertificateWithRecordDecision, true, callback));
415 // On Android, AllowCertificateError can cause a Java exception to be thrown
416 // - in such a case we cannot allow calls back into Java here. If adding any
417 // additional code here, make sure it cannot call into Java.
402 } 418 }
403 419
404 void SSLManager::UpdateEntry(NavigationEntryImpl* entry, 420 void SSLManager::UpdateEntry(NavigationEntryImpl* entry,
405 int add_content_status_flags, 421 int add_content_status_flags,
406 int remove_content_status_flags) { 422 int remove_content_status_flags) {
407 // We don't always have a navigation entry to update, for example in the 423 // We don't always have a navigation entry to update, for example in the
408 // case of the Web Inspector. 424 // case of the Web Inspector.
409 if (!entry) 425 if (!entry)
410 return; 426 return;
411 427
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 SSLManagerSet* managers = 475 SSLManagerSet* managers =
460 static_cast<SSLManagerSet*>(context->GetUserData(kSSLManagerKeyName)); 476 static_cast<SSLManagerSet*>(context->GetUserData(kSSLManagerKeyName));
461 477
462 for (std::set<SSLManager*>::iterator i = managers->get().begin(); 478 for (std::set<SSLManager*>::iterator i = managers->get().begin();
463 i != managers->get().end(); ++i) { 479 i != managers->get().end(); ++i) {
464 (*i)->UpdateEntry((*i)->controller()->GetLastCommittedEntry(), 0, 0); 480 (*i)->UpdateEntry((*i)->controller()->GetLastCommittedEntry(), 0, 0);
465 } 481 }
466 } 482 }
467 483
468 } // namespace content 484 } // namespace content
OLDNEW
« android_webview/browser/aw_contents_client_bridge.cc ('K') | « content/browser/ssl/ssl_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698