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

Unified Diff: chrome/browser/ssl/ssl_client_auth_observer.cc

Issue 9384014: Remove knowledge about SSLClientAuthHandler from chrome. Instead a callback is given to the embed... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix aura Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/ssl_client_auth_observer.cc
===================================================================
--- chrome/browser/ssl/ssl_client_auth_observer.cc (revision 121323)
+++ chrome/browser/ssl/ssl_client_auth_observer.cc (working copy)
@@ -1,158 +1,81 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/ssl/ssl_client_auth_handler.h"
+#include "chrome/browser/ssl/ssl_client_auth_observer.h"
+#include <utility>
+
#include "base/bind.h"
-#include "content/browser/renderer_host/resource_dispatcher_host.h"
-#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
-#include "content/browser/ssl/ssl_client_auth_notification_details.h"
+#include "base/logging.h"
+#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/notification_service.h"
+#include "net/base/ssl_cert_request_info.h"
#include "net/base/x509_certificate.h"
-#include "net/http/http_transaction_factory.h"
-#include "net/url_request/url_request.h"
-#include "net/url_request/url_request_context.h"
using content::BrowserThread;
-SSLClientAuthHandler::SSLClientAuthHandler(
- net::URLRequest* request,
- net::SSLCertRequestInfo* cert_request_info)
- : request_(request),
- http_network_session_(
- request_->context()->http_transaction_factory()->GetSession()),
- cert_request_info_(cert_request_info) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-}
+typedef std::pair<net::SSLCertRequestInfo*, net::X509Certificate*> CertDetails;
-SSLClientAuthHandler::~SSLClientAuthHandler() {
- // If we were simply dropped, then act as if we selected no certificate.
- DoCertificateSelected(NULL);
+SSLClientAuthObserver::SSLClientAuthObserver(
+ const net::HttpNetworkSession* network_session,
+ net::SSLCertRequestInfo* cert_request_info,
+ const base::Callback<void(net::X509Certificate*)>& callback)
+ : network_session_(network_session),
+ cert_request_info_(cert_request_info),
+ callback_(callback) {
}
-void SSLClientAuthHandler::OnRequestCancelled() {
- request_ = NULL;
+SSLClientAuthObserver::~SSLClientAuthObserver() {
}
-void SSLClientAuthHandler::SelectCertificate() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+void SSLClientAuthObserver::CertificateSelected(
+ net::X509Certificate* certificate) {
+ if (callback_.is_null())
+ return;
- int render_process_host_id;
- int render_view_host_id;
- if (!ResourceDispatcherHost::RenderViewForRequest(request_,
- &render_process_host_id,
- &render_view_host_id))
- NOTREACHED();
+ // Stop listening right away so we don't get our own notification.
+ StopObserving();
- // If the RVH does not exist by the time this task gets run, then the task
- // will be dropped and the scoped_refptr to SSLClientAuthHandler will go
- // away, so we do not leak anything. The destructor takes care of ensuring
- // the net::URLRequest always gets a response.
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(
- &SSLClientAuthHandler::DoSelectCertificate, this,
- render_process_host_id, render_view_host_id));
-}
-
-// Sends an SSL_CLIENT_AUTH_CERT_SELECTED notification and notifies the IO
-// thread that we have selected a cert.
-void SSLClientAuthHandler::CertificateSelected(net::X509Certificate* cert) {
- VLOG(1) << this << " CertificateSelected " << cert;
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- SSLClientAuthNotificationDetails details(cert_request_info_, this, cert);
+ CertDetails details;
+ details.first = cert_request_info_;
+ details.second = certificate;
content::NotificationService* service =
content::NotificationService::current();
- service->Notify(content::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
- content::Source<net::HttpNetworkSession>(
- http_network_session()),
- content::Details<SSLClientAuthNotificationDetails>(&details));
+ service->Notify(chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
+ content::Source<net::HttpNetworkSession>(network_session_),
+ content::Details<CertDetails>(&details));
- CertificateSelectedNoNotify(cert);
+ callback_.Run(certificate);
+ callback_.Reset();
}
-// Notifies the IO thread that we have selected a cert.
-void SSLClientAuthHandler::CertificateSelectedNoNotify(
- net::X509Certificate* cert) {
- VLOG(1) << this << " CertificateSelectedNoNotify " << cert;
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(
- &SSLClientAuthHandler::DoCertificateSelected, this,
- make_scoped_refptr(cert)));
-}
-
-void SSLClientAuthHandler::DoCertificateSelected(net::X509Certificate* cert) {
- VLOG(1) << this << " DoCertificateSelected " << cert;
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // request_ could have been NULLed if the request was cancelled while the
- // user was choosing a cert, or because we have already responded to the
- // certificate.
- if (request_) {
- request_->ContinueWithCertificate(cert);
-
- ResourceDispatcherHostRequestInfo* info =
- ResourceDispatcherHost::InfoForRequest(request_);
- if (info)
- info->set_ssl_client_auth_handler(NULL);
-
- request_ = NULL;
- }
-}
-
-void SSLClientAuthHandler::DoSelectCertificate(
- int render_process_host_id, int render_view_host_id) {
- content::GetContentClient()->browser()->SelectClientCertificate(
- render_process_host_id, render_view_host_id, this);
-}
-
-SSLClientAuthObserver::SSLClientAuthObserver(
- net::SSLCertRequestInfo* cert_request_info,
- SSLClientAuthHandler* handler)
- : cert_request_info_(cert_request_info), handler_(handler) {
-}
-
-SSLClientAuthObserver::~SSLClientAuthObserver() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-}
-
void SSLClientAuthObserver::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- VLOG(1) << "SSLClientAuthObserver::Observe " << this << " " << handler_.get();
+ VLOG(1) << "SSLClientAuthObserver::Observe " << this;
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(type == content::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED);
+ DCHECK(type == chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED);
- SSLClientAuthNotificationDetails* auth_details =
- content::Details<SSLClientAuthNotificationDetails>(details).ptr();
-
- if (auth_details->IsSameHandler(handler_.get())) {
- VLOG(1) << "got notification from ourself " << handler_.get();
+ CertDetails* cert_details = content::Details<CertDetails>(details).ptr();
+ if (cert_details->first->host_and_port != cert_request_info_->host_and_port)
return;
- }
- if (!auth_details->IsSameHost(cert_request_info_))
- return;
-
- VLOG(1) << this << " got matching notification for "
- << handler_.get() << ", selecting cert "
- << auth_details->selected_cert();
+ VLOG(1) << this << " got matching notification and selecting cert "
+ << cert_details->second;
StopObserving();
- handler_->CertificateSelectedNoNotify(auth_details->selected_cert());
+ callback_.Run(cert_details->second);
+ callback_.Reset();
OnCertSelectedByNotification();
}
void SSLClientAuthObserver::StartObserving() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
notification_registrar_.Add(
- this, content::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
- content::Source<net::HttpNetworkSession>(
- handler_->http_network_session()));
+ this, chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
+ content::Source<net::HttpNetworkSession>(network_session_));
}
void SSLClientAuthObserver::StopObserving() {

Powered by Google App Engine
This is Rietveld 408576698