diff options
Diffstat (limited to 'chrome/browser/ssl/ssl_manager.cc')
-rw-r--r-- | chrome/browser/ssl/ssl_manager.cc | 278 |
1 files changed, 28 insertions, 250 deletions
diff --git a/chrome/browser/ssl/ssl_manager.cc b/chrome/browser/ssl/ssl_manager.cc index 0510810..c46a20b 100644 --- a/chrome/browser/ssl/ssl_manager.cc +++ b/chrome/browser/ssl/ssl_manager.cc @@ -12,9 +12,13 @@ #include "chrome/browser/load_from_memory_cache_details.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/resource_request_details.h" +#include "chrome/browser/ssl/ssl_cert_error_handler.h" #include "chrome/browser/ssl/ssl_error_info.h" +#include "chrome/browser/ssl/ssl_error_handler.h" #include "chrome/browser/ssl/ssl_host_state.h" +#include "chrome/browser/ssl/ssl_mixed_content_handler.h" #include "chrome/browser/ssl/ssl_policy.h" +#include "chrome/browser/ssl/ssl_request_info.h" #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" @@ -90,9 +94,6 @@ class SSLInfoBarDelegate : public ConfirmInfoBarDelegate { DISALLOW_COPY_AND_ASSIGN(SSLInfoBarDelegate); }; -//////////////////////////////////////////////////////////////////////////////// -// SSLManager - // static void SSLManager::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterIntegerPref(prefs::kMixedContentFiltering, @@ -231,230 +232,6 @@ bool SSLManager::ProcessedSSLErrorFromRequest() const { return net::IsCertStatusError(entry->ssl().cert_status()); } -//////////////////////////////////////////////////////////////////////////////// -// ErrorHandler - -SSLManager::ErrorHandler::ErrorHandler(ResourceDispatcherHost* rdh, - URLRequest* request, - ResourceType::Type resource_type, - const std::string& frame_origin, - const std::string& main_frame_origin, - MessageLoop* ui_loop) - : ui_loop_(ui_loop), - io_loop_(MessageLoop::current()), - manager_(NULL), - request_id_(0, 0), - resource_dispatcher_host_(rdh), - request_url_(request->url()), - resource_type_(resource_type), - frame_origin_(frame_origin), - main_frame_origin_(main_frame_origin), - request_has_been_notified_(false) { - DCHECK(MessageLoop::current() != ui_loop); - - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); - request_id_.process_id = info->process_id; - request_id_.request_id = info->request_id; - - if (!tab_util::GetTabContentsID(request, - &render_process_host_id_, - &tab_contents_id_)) - NOTREACHED(); - - // This makes sure we don't disappear on the IO thread until we've given an - // answer to the URLRequest. - // - // Release in CompleteCancelRequest, CompleteContinueRequest, - // CompleteStartRequest or CompleteTakeNoAction. - AddRef(); -} - -void SSLManager::ErrorHandler::Dispatch() { - DCHECK(MessageLoop::current() == ui_loop_); - - TabContents* tab_contents = - tab_util::GetTabContentsByID(render_process_host_id_, tab_contents_id_); - - if (!tab_contents) { - // We arrived on the UI thread, but the tab we're looking for is no longer - // here. - OnDispatchFailed(); - return; - } - - // Hand ourselves off to the SSLManager. - manager_ = tab_contents->controller().ssl_manager(); - OnDispatched(); -} - -TabContents* SSLManager::ErrorHandler::GetTabContents() { - return tab_util::GetTabContentsByID(render_process_host_id_, - tab_contents_id_); -} - -void SSLManager::ErrorHandler::CancelRequest() { - DCHECK(MessageLoop::current() == ui_loop_); - - // We need to complete this task on the IO thread. - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SSLManager::ErrorHandler::CompleteCancelRequest, - net::ERR_ABORTED)); -} - -void SSLManager::ErrorHandler::DenyRequest() { - DCHECK(MessageLoop::current() == ui_loop_); - - // We need to complete this task on the IO thread. - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SSLManager::ErrorHandler::CompleteCancelRequest, - net::ERR_INSECURE_RESPONSE)); -} - -void SSLManager::ErrorHandler::ContinueRequest() { - DCHECK(MessageLoop::current() == ui_loop_); - - // We need to complete this task on the IO thread. - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SSLManager::ErrorHandler::CompleteContinueRequest)); -} - -void SSLManager::ErrorHandler::StartRequest(FilterPolicy::Type filter_policy) { - DCHECK(MessageLoop::current() == ui_loop_); - - // We need to complete this task on the IO thread. - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SSLManager::ErrorHandler::CompleteStartRequest, filter_policy)); -} - -void SSLManager::ErrorHandler::TakeNoAction() { - DCHECK(MessageLoop::current() == ui_loop_); - - // We need to complete this task on the IO thread. - io_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &SSLManager::ErrorHandler::CompleteTakeNoAction)); -} - -void SSLManager::ErrorHandler::CompleteCancelRequest(int error) { - DCHECK(MessageLoop::current() == io_loop_); - - // It is important that we notify the URLRequest only once. If we try to - // notify the request twice, it may no longer exist and |this| might have - // already have been deleted. - DCHECK(!request_has_been_notified_); - - if (!request_has_been_notified_) { - 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). - DLOG(INFO) << "CompleteCancelRequest() url: " << request->url().spec(); - SSLManager::CertError* cert_error = AsCertError(); - if (cert_error) - request->SimulateSSLError(error, cert_error->ssl_info()); - else - request->SimulateError(error); - } - request_has_been_notified_ = true; - - // We're done with this object on the IO thread. - Release(); - } -} - -void SSLManager::ErrorHandler::CompleteContinueRequest() { - DCHECK(MessageLoop::current() == io_loop_); - - // It is important that we notify the URLRequest only once. If we try to - // notify the request twice, it may no longer exist and |this| might have - // already have been deleted. - DCHECK(!request_has_been_notified_); - - if (!request_has_been_notified_) { - 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). - DLOG(INFO) << "CompleteContinueRequest() url: " << request->url().spec(); - request->ContinueDespiteLastError(); - } - request_has_been_notified_ = true; - - // We're done with this object on the IO thread. - Release(); - } -} - -void SSLManager::ErrorHandler::CompleteStartRequest( - FilterPolicy::Type filter_policy) { - DCHECK(MessageLoop::current() == io_loop_); - - // It is important that we notify the URLRequest only once. If we try to - // notify the request twice, it may no longer exist and |this| might have - // already have been deleted. - DCHECK(!request_has_been_notified_); - - if (request_has_been_notified_) - return; - - 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). - DLOG(INFO) << "CompleteStartRequest() url: " << request->url().spec(); - // The request should not have been started (SUCCESS is the initial state). - DCHECK(request->status().status() == URLRequestStatus::SUCCESS); - ResourceDispatcherHost::ExtraRequestInfo* info = - ResourceDispatcherHost::ExtraInfoForRequest(request); - info->filter_policy = filter_policy; - request->Start(); - } - request_has_been_notified_ = true; - - // We're done with this object on the IO thread. - Release(); -} - -void SSLManager::ErrorHandler::CompleteTakeNoAction() { - DCHECK(MessageLoop::current() == io_loop_); - - // It is important that we notify the URLRequest only once. If we try to - // notify the request twice, it may no longer exist and |this| might have - // already have been deleted. - DCHECK(!request_has_been_notified_); - - if (!request_has_been_notified_) { - request_has_been_notified_ = true; - - // We're done with this object on the IO thread. - Release(); - } -} - - -//////////////////////////////////////////////////////////////////////////////// -// CertError - -SSLManager::CertError::CertError( - ResourceDispatcherHost* rdh, - URLRequest* request, - ResourceType::Type resource_type, - const std::string& frame_origin, - const std::string& main_frame_origin, - int cert_error, - net::X509Certificate* cert, - MessageLoop* ui_loop) - : ErrorHandler(rdh, request, resource_type, frame_origin, - main_frame_origin, ui_loop), - cert_error_(cert_error) { - DCHECK(request == resource_dispatcher_host_->GetURLRequest(request_id_)); - - // We cannot use the request->ssl_info(), it's not been initialized yet, so - // we have to set the fields manually. - ssl_info_.cert = cert; - ssl_info_.SetCertError(cert_error); -} - // static void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, URLRequest* request, @@ -468,18 +245,18 @@ void SSLManager::OnSSLCertificateError(ResourceDispatcherHost* rdh, ResourceDispatcherHost::ExtraInfoForRequest(request); DCHECK(info); - // A certificate error occurred. Construct a CertError object and hand it - // over to the UI thread for processing. + // A certificate error occurred. Construct a SSLCertErrorHandler object and + // hand it over to the UI thread for processing. ui_loop->PostTask(FROM_HERE, - NewRunnableMethod(new CertError(rdh, - request, - info->resource_type, - info->frame_origin, - info->main_frame_origin, - cert_error, - cert, - ui_loop), - &CertError::Dispatch)); + NewRunnableMethod(new SSLCertErrorHandler(rdh, + request, + info->resource_type, + info->frame_origin, + info->main_frame_origin, + cert_error, + cert, + ui_loop), + &SSLCertErrorHandler::Dispatch)); } // static @@ -500,21 +277,22 @@ bool SSLManager::ShouldStartRequest(ResourceDispatcherHost* rdh, ui_loop->PostTask(FROM_HERE, - NewRunnableMethod(new MixedContentHandler(rdh, request, - info->resource_type, - info->frame_origin, - info->main_frame_origin, - info->process_id, - ui_loop), - &MixedContentHandler::Dispatch)); + NewRunnableMethod(new SSLMixedContentHandler(rdh, + request, + info->resource_type, + info->frame_origin, + info->main_frame_origin, + info->process_id, + ui_loop), + &SSLMixedContentHandler::Dispatch)); return false; } -void SSLManager::OnCertError(CertError* error) { - delegate()->OnCertError(error); +void SSLManager::OnCertError(SSLCertErrorHandler* handler) { + delegate()->OnCertError(handler); } -void SSLManager::OnMixedContent(MixedContentHandler* handler) { +void SSLManager::OnMixedContent(SSLMixedContentHandler* handler) { delegate()->OnMixedContent(handler); } @@ -582,7 +360,7 @@ void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) { // caches sub-resources. // This resource must have been loaded with FilterPolicy::DONT_FILTER because // filtered resouces aren't cachable. - scoped_refptr<RequestInfo> info = new RequestInfo( + scoped_refptr<SSLRequestInfo> info = new SSLRequestInfo( this, details->url(), ResourceType::SUB_RESOURCE, @@ -646,7 +424,7 @@ void SSLManager::DidFailProvisionalLoadWithError( void SSLManager::DidStartResourceResponse(ResourceRequestDetails* details) { DCHECK(details); - scoped_refptr<RequestInfo> info = new RequestInfo( + scoped_refptr<SSLRequestInfo> info = new SSLRequestInfo( this, details->url(), details->resource_type(), |