diff options
author | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 02:24:34 +0000 |
---|---|---|
committer | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-13 02:24:34 +0000 |
commit | 043cc11910894f4bb2ae1c013d498964c6b84427 (patch) | |
tree | 9319203cad07b9a812a119a573fb775ac7c75631 /content/browser/ssl | |
parent | 97f78dd293f231630da59645af0c561efb2e5364 (diff) | |
download | chromium_src-043cc11910894f4bb2ae1c013d498964c6b84427.zip chromium_src-043cc11910894f4bb2ae1c013d498964c6b84427.tar.gz chromium_src-043cc11910894f4bb2ae1c013d498964c6b84427.tar.bz2 |
Factor out ResourceDispatcherHost dependent code around SSLManager
Because SSLManager must work with not only ResourceDispatcherHost.
BUG=53836
TEST=existing tests will cover this refactoring
Review URL: http://codereview.chromium.org/9406001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126310 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/ssl')
-rw-r--r-- | content/browser/ssl/ssl_cert_error_handler.cc | 12 | ||||
-rw-r--r-- | content/browser/ssl/ssl_cert_error_handler.h | 7 | ||||
-rw-r--r-- | content/browser/ssl/ssl_error_handler.cc | 57 | ||||
-rw-r--r-- | content/browser/ssl/ssl_error_handler.h | 36 | ||||
-rw-r--r-- | content/browser/ssl/ssl_manager.cc | 26 | ||||
-rw-r--r-- | content/browser/ssl/ssl_manager.h | 14 |
6 files changed, 90 insertions, 62 deletions
diff --git a/content/browser/ssl/ssl_cert_error_handler.cc b/content/browser/ssl/ssl_cert_error_handler.cc index 496ac43..2975797 100644 --- a/content/browser/ssl/ssl_cert_error_handler.cc +++ b/content/browser/ssl/ssl_cert_error_handler.cc @@ -5,6 +5,7 @@ #include "content/browser/ssl/ssl_cert_error_handler.h" #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" +#include "content/browser/ssl/ssl_manager.h" #include "content/browser/ssl/ssl_policy.h" #include "net/base/cert_status_flags.h" #include "net/base/x509_certificate.h" @@ -12,16 +13,19 @@ using content::ResourceDispatcherHostImpl; SSLCertErrorHandler::SSLCertErrorHandler( - ResourceDispatcherHostImpl* host, - net::URLRequest* request, + Delegate* delegate, + const content::GlobalRequestID& id, ResourceType::Type resource_type, + const GURL& url, + int render_process_id, + int render_view_id, const net::SSLInfo& ssl_info, bool fatal) - : SSLErrorHandler(host, request, resource_type), + : SSLErrorHandler(delegate, id, resource_type, url, render_process_id, + render_view_id), ssl_info_(ssl_info), cert_error_(net::MapCertStatusToNetError(ssl_info.cert_status)), fatal_(fatal) { - DCHECK(request == resource_dispatcher_host_->GetURLRequest(request_id_)); } SSLCertErrorHandler* SSLCertErrorHandler::AsSSLCertErrorHandler() { diff --git a/content/browser/ssl/ssl_cert_error_handler.h b/content/browser/ssl/ssl_cert_error_handler.h index 0f095a9..ac6a3eb 100644 --- a/content/browser/ssl/ssl_cert_error_handler.h +++ b/content/browser/ssl/ssl_cert_error_handler.h @@ -17,9 +17,12 @@ class SSLCertErrorHandler : public SSLErrorHandler { public: // Construct on the IO thread. - SSLCertErrorHandler(content::ResourceDispatcherHostImpl* host, - net::URLRequest* request, + SSLCertErrorHandler(Delegate* delegate, + const content::GlobalRequestID& id, ResourceType::Type resource_type, + const GURL& url, + int render_process_id, + int render_view_id, const net::SSLInfo& ssl_info, bool fatal); diff --git a/content/browser/ssl/ssl_error_handler.cc b/content/browser/ssl/ssl_error_handler.cc index d818052..a4c1bf6 100644 --- a/content/browser/ssl/ssl_error_handler.cc +++ b/content/browser/ssl/ssl_error_handler.cc @@ -6,7 +6,6 @@ #include "base/bind.h" #include "content/browser/renderer_host/render_view_host_impl.h" -#include "content/browser/renderer_host/resource_dispatcher_host_impl.h" #include "content/browser/ssl/ssl_cert_error_handler.h" #include "content/browser/tab_contents/navigation_controller_impl.h" #include "content/browser/tab_contents/tab_contents.h" @@ -17,27 +16,25 @@ using content::BrowserThread; using content::RenderViewHostImpl; -using content::ResourceDispatcherHostImpl; -using content::ResourceRequestInfo; using content::WebContents; - -SSLErrorHandler::SSLErrorHandler(ResourceDispatcherHostImpl* host, - net::URLRequest* request, - ResourceType::Type resource_type) +using net::SSLInfo; + +SSLErrorHandler::SSLErrorHandler(Delegate* delegate, + const content::GlobalRequestID& id, + ResourceType::Type resource_type, + const GURL& url, + int render_process_id, + int render_view_id) : manager_(NULL), - request_id_(0, 0), - resource_dispatcher_host_(host), - request_url_(request->url()), + request_id_(id), + delegate_(delegate), + render_process_id_(render_process_id), + render_view_id_(render_view_id), + request_url_(url), resource_type_(resource_type), request_has_been_notified_(false) { DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); - - const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); - request_id_.child_id = info->GetChildID(); - request_id_.request_id = info->GetRequestID(); - - if (!info->GetAssociatedRenderView(&render_process_id_, &render_view_id_)) - NOTREACHED(); + DCHECK(delegate); // This makes sure we don't disappear on the IO thread until we've given an // answer to the net::URLRequest. @@ -133,18 +130,11 @@ void SSLErrorHandler::CompleteCancelRequest(int error) { if (request_has_been_notified_) return; - net::URLRequest* request = - resource_dispatcher_host_->GetURLRequest(request_id_); - if (request && request->is_pending()) { - // The request can be NULL if it was cancelled by the renderer (as the - // result of the user navigating to a new page from the location bar). - DVLOG(1) << "CompleteCancelRequest() url: " << request->url().spec(); - SSLCertErrorHandler* cert_error = AsSSLCertErrorHandler(); - if (cert_error) - request->SimulateSSLError(error, cert_error->ssl_info()); - else - request->SimulateError(error); - } + SSLCertErrorHandler* cert_error = AsSSLCertErrorHandler(); + const SSLInfo* ssl_info = NULL; + if (cert_error) + ssl_info = &cert_error->ssl_info(); + delegate_->CancelSSLRequest(request_id_, error, ssl_info); request_has_been_notified_ = true; // We're done with this object on the IO thread. @@ -161,14 +151,7 @@ void SSLErrorHandler::CompleteContinueRequest() { if (request_has_been_notified_) return; - net::URLRequest* request = - resource_dispatcher_host_->GetURLRequest(request_id_); - if (request) { - // The request can be NULL if it was cancelled by the renderer (as the - // result of the user navigating to a new page from the location bar). - DVLOG(1) << "CompleteContinueRequest() url: " << request->url().spec(); - request->ContinueDespiteLastError(); - } + delegate_->ContinueSSLRequest(request_id_); request_has_been_notified_ = true; // We're done with this object on the IO thread. diff --git a/content/browser/ssl/ssl_error_handler.h b/content/browser/ssl/ssl_error_handler.h index eadf89b..15832df 100644 --- a/content/browser/ssl/ssl_error_handler.h +++ b/content/browser/ssl/ssl_error_handler.h @@ -10,19 +10,20 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" -#include "content/browser/ssl/ssl_manager.h" #include "content/common/content_export.h" #include "content/public/browser/global_request_id.h" #include "googleurl/src/gurl.h" #include "webkit/glue/resource_type.h" class SSLCertErrorHandler; +class SSLManager; namespace content { class ResourceDispatcherHostImpl; } namespace net { +class SSLInfo; class URLRequest; } // namespace net @@ -42,6 +43,24 @@ class URLRequest; // class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { public: + // Delegate functions must be called from IO thread. All functions accept + // |id| as the first argument. |id| is a copy of the second argument of + // SSLManager::OnSSLCertificateError() and represents the request. + // Finally, CancelSSLRequest() or ContinueSSLRequest() will be called after + // SSLErrorHandler makes a decision on the SSL error. + class Delegate { + public: + // Called when SSLErrorHandler decides to cancel the request because of + // the SSL error. + virtual void CancelSSLRequest(const content::GlobalRequestID& id, + int error, + const net::SSLInfo* ssl_info) = 0; + + // Called when SSLErrorHandler decides to continue the request despite the + // SSL error. + virtual void ContinueSSLRequest(const content::GlobalRequestID& id) = 0; + }; + virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); // Find the appropriate SSLManager for the net::URLRequest and begin handling @@ -86,9 +105,12 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { friend class base::RefCountedThreadSafe<SSLErrorHandler>; // Construct on the IO thread. - SSLErrorHandler(content::ResourceDispatcherHostImpl* host, - net::URLRequest* request, - ResourceType::Type resource_type); + SSLErrorHandler(Delegate* delegate, + const content::GlobalRequestID& id, + ResourceType::Type resource_type, + const GURL& url, + int render_process_id, + int render_view_id); virtual ~SSLErrorHandler(); @@ -101,12 +123,12 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { // Should only be accessed on the UI thread. SSLManager* manager_; // Our manager. - // The id of the net::URLRequest associated with this object. + // The id of the request associated with this object. // Should only be accessed from the IO thread. content::GlobalRequestID request_id_; - // The ResourceDispatcherHostImpl we are associated with. - content::ResourceDispatcherHostImpl* resource_dispatcher_host_; + // The delegate we are associated with. + Delegate* delegate_; private: // Completes the CancelRequest operation on the IO thread. diff --git a/content/browser/ssl/ssl_manager.cc b/content/browser/ssl/ssl_manager.cc index 0322de0..4a044b0 100644 --- a/content/browser/ssl/ssl_manager.cc +++ b/content/browser/ssl/ssl_manager.cc @@ -33,25 +33,35 @@ using content::SSLStatus; using content::WebContents; // static -void SSLManager::OnSSLCertificateError(net::URLRequest* request, +void SSLManager::OnSSLCertificateError(SSLErrorHandler::Delegate* delegate, + const content::GlobalRequestID& id, + const ResourceType::Type resource_type, + const GURL& url, + int render_process_id, + int render_view_id, const net::SSLInfo& ssl_info, bool fatal) { + DCHECK(delegate); DVLOG(1) << "OnSSLCertificateError() cert_error: " << net::MapCertStatusToNetError(ssl_info.cert_status) - << " url: " << request->url().spec() + << " id: " << id.child_id << "," << id.request_id + << " resource_type: " << resource_type + << " url: " << url.spec() + << " render_process_id: " << render_process_id + << " render_view_id: " << render_view_id << " cert_status: " << std::hex << ssl_info.cert_status; - const ResourceRequestInfoImpl* info = - ResourceRequestInfoImpl::ForRequest(request); - // A certificate error occurred. Construct a SSLCertErrorHandler object and // hand it over to the UI thread for processing. BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, base::Bind(&SSLCertErrorHandler::Dispatch, - new SSLCertErrorHandler(ResourceDispatcherHostImpl::Get(), - request, - info->GetResourceType(), + new SSLCertErrorHandler(delegate, + id, + resource_type, + url, + render_process_id, + render_view_id, ssl_info, fatal))); } diff --git a/content/browser/ssl/ssl_manager.h b/content/browser/ssl/ssl_manager.h index db2b65d..668c3e0 100644 --- a/content/browser/ssl/ssl_manager.h +++ b/content/browser/ssl/ssl_manager.h @@ -11,7 +11,9 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "content/browser/ssl/ssl_policy_backend.h" +#include "content/browser/ssl/ssl_error_handler.h" #include "content/common/content_export.h" +#include "content/public/browser/global_request_id.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "googleurl/src/gurl.h" @@ -30,7 +32,6 @@ class NavigationEntryImpl; namespace net { class SSLInfo; -class URLRequest; } // namespace net // The SSLManager SSLManager controls the SSL UI elements in a TabContents. It @@ -45,11 +46,16 @@ class SSLManager : public content::NotificationObserver { public: // Entry point for SSLCertificateErrors. This function begins the process // of resolving a certificate error during an SSL connection. SSLManager - // will adjust the security UI and either call |Cancel| or - // |ContinueDespiteLastError| on the net::URLRequest. + // will adjust the security UI and either call |CancelSSLRequest| or + // |ContinueSSLRequest| of |delegate| with |id| as the first argument. // // Called on the IO thread. - static void OnSSLCertificateError(net::URLRequest* request, + static void OnSSLCertificateError(SSLErrorHandler::Delegate* delegate, + const content::GlobalRequestID& id, + ResourceType::Type resource_type, + const GURL& url, + int render_process_id, + int render_view_id, const net::SSLInfo& ssl_info, bool fatal); |