diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 05:57:17 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 05:57:17 +0000 |
commit | b377fe8556b64260c99171c1ed9101bd2d621568 (patch) | |
tree | fa94c4eacc4cafa6d7ec9710bedb178828716d3e /chrome | |
parent | dce516200cbac6100f0268c5f036e8dbddf4f8ac (diff) | |
download | chromium_src-b377fe8556b64260c99171c1ed9101bd2d621568.zip chromium_src-b377fe8556b64260c99171c1ed9101bd2d621568.tar.gz chromium_src-b377fe8556b64260c99171c1ed9101bd2d621568.tar.bz2 |
The URLRequestAutomationJob object which needs to route HTTP requests to the host browser for
ChromeFrame's host network stack implementation can register itself as a protocol factory for http/https
instead of using the mechanism to intercept HTTP requests which Gears and the App cache use. This ensures
that Gears works partially with ChromeFrame.
The protocol factory mechanism also has the same limitation as the intercept mechanism, i.e. it does not
support chaining.
Partial fix for http://code.google.com/p/chromium/issues/detail?id=23992
Bug=23992
Review URL: http://codereview.chromium.org/365009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31208 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 63 insertions, 54 deletions
diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc index 9727523..cfadf91 100644 --- a/chrome/browser/automation/automation_provider_win.cc +++ b/chrome/browser/automation/automation_provider_win.cc @@ -346,7 +346,6 @@ void AutomationProvider::CreateExternalTab( if (AddExternalTab(external_tab_container)) { TabContents* tab_contents = external_tab_container->tab_contents(); *tab_handle = external_tab_container->tab_handle(); - external_tab_container->set_tab_handle(*tab_handle); *tab_container_window = external_tab_container->GetNativeView(); *tab_window = tab_contents->GetNativeView(); } else { diff --git a/chrome/browser/automation/automation_resource_message_filter.cc b/chrome/browser/automation/automation_resource_message_filter.cc index eb3edf3..953061e 100644 --- a/chrome/browser/automation/automation_resource_message_filter.cc +++ b/chrome/browser/automation/automation_resource_message_filter.cc @@ -24,7 +24,10 @@ int AutomationResourceMessageFilter::unique_request_id_ = 1; AutomationResourceMessageFilter::AutomationResourceMessageFilter() : channel_(NULL) { - URLRequestAutomationJob::InitializeInterceptor(); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableFunction( + URLRequestAutomationJob::EnsureProtocolFactoryRegistered)); } AutomationResourceMessageFilter::~AutomationResourceMessageFilter() { diff --git a/chrome/browser/automation/url_request_automation_job.cc b/chrome/browser/automation/url_request_automation_job.cc index 7b396f0..715e292 100644 --- a/chrome/browser/automation/url_request_automation_job.cc +++ b/chrome/browser/automation/url_request_automation_job.cc @@ -7,6 +7,7 @@ #include "base/message_loop.h" #include "base/time.h" #include "chrome/browser/automation/automation_resource_message_filter.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" @@ -14,7 +15,6 @@ #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/http/http_util.h" -#include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" using base::Time; @@ -41,51 +41,13 @@ static const char* kFilteredHeaderStrings[] = { "via" }; -// This class manages the interception of network requests for automation. -// It looks at the request, and creates an intercept job if it indicates -// that it should use automation channel. -// NOTE: All methods must be called on the IO thread. -class AutomationRequestInterceptor : public URLRequest::Interceptor { - public: - AutomationRequestInterceptor() { - URLRequest::RegisterRequestInterceptor(this); - } - - virtual ~AutomationRequestInterceptor() { - URLRequest::UnregisterRequestInterceptor(this); - } - - // URLRequest::Interceptor - virtual URLRequestJob* MaybeIntercept(URLRequest* request); - - private: - DISALLOW_COPY_AND_ASSIGN(AutomationRequestInterceptor); -}; - -URLRequestJob* AutomationRequestInterceptor::MaybeIntercept( - URLRequest* request) { - if (request->url().SchemeIs("http") || request->url().SchemeIs("https")) { - ResourceDispatcherHostRequestInfo* request_info = - ResourceDispatcherHost::InfoForRequest(request); - if (request_info) { - AutomationResourceMessageFilter::AutomationDetails details; - if (AutomationResourceMessageFilter::LookupRegisteredRenderView( - request_info->child_id(), request_info->route_id(), &details)) { - URLRequestAutomationJob* job = new URLRequestAutomationJob(request, - details.tab_handle, details.filter); - return job; - } - } - } - - return NULL; -} - -static URLRequest::Interceptor* GetAutomationRequestInterceptor() { - return Singleton<AutomationRequestInterceptor>::get(); -} - int URLRequestAutomationJob::instance_count_ = 0; +bool URLRequestAutomationJob::is_protocol_factory_registered_ = false; + +URLRequest::ProtocolFactory* URLRequestAutomationJob::old_http_factory_ + = NULL; +URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_ + = NULL; URLRequestAutomationJob::URLRequestAutomationJob( URLRequest* request, int tab, AutomationResourceMessageFilter* filter) @@ -105,11 +67,47 @@ URLRequestAutomationJob::~URLRequestAutomationJob() { Cleanup(); } -bool URLRequestAutomationJob::InitializeInterceptor() { - // AutomationRequestInterceptor will register itself when it - // is first created. - URLRequest::Interceptor* interceptor = GetAutomationRequestInterceptor(); - return (interceptor != NULL); +bool URLRequestAutomationJob::EnsureProtocolFactoryRegistered() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + + if (!is_protocol_factory_registered_) { + old_http_factory_ = + URLRequest::RegisterProtocolFactory("http", + &URLRequestAutomationJob::Factory); + old_https_factory_ = + URLRequest::RegisterProtocolFactory("https", + &URLRequestAutomationJob::Factory); + is_protocol_factory_registered_ = true; + } + + return true; +} + +URLRequestJob* URLRequestAutomationJob::Factory(URLRequest* request, + const std::string& scheme) { + bool scheme_is_http = request->url().SchemeIs("http"); + bool scheme_is_https = request->url().SchemeIs("https"); + + // Returning null here just means that the built-in handler will be used. + if (scheme_is_http || scheme_is_https) { + ResourceDispatcherHostRequestInfo* request_info = + ResourceDispatcherHost::InfoForRequest(request); + if (request_info) { + AutomationResourceMessageFilter::AutomationDetails details; + if (AutomationResourceMessageFilter::LookupRegisteredRenderView( + request_info->child_id(), request_info->route_id(), &details)) { + URLRequestAutomationJob* job = new URLRequestAutomationJob(request, + details.tab_handle, details.filter); + return job; + } + } + + if (scheme_is_http && old_http_factory_) + return old_http_factory_(request, scheme); + else if (scheme_is_https && old_https_factory_) + return old_https_factory_(request, scheme); + } + return NULL; } // URLRequestJob Implementation. diff --git a/chrome/browser/automation/url_request_automation_job.h b/chrome/browser/automation/url_request_automation_job.h index ff20c15..d4ed0f0 100644 --- a/chrome/browser/automation/url_request_automation_job.h +++ b/chrome/browser/automation/url_request_automation_job.h @@ -8,6 +8,7 @@ #include "chrome/common/ref_counted_util.h" #include "net/http/http_response_headers.h" +#include "net/url_request/url_request.h" #include "net/url_request/url_request_job.h" class AutomationResourceMessageFilter; @@ -24,8 +25,10 @@ class URLRequestAutomationJob : public URLRequestJob { URLRequestAutomationJob( URLRequest* request, int tab, AutomationResourceMessageFilter* filter); - // Register an interceptor for URL requests. - static bool InitializeInterceptor(); + // Register our factory for HTTP/HTTPs requests. + static bool EnsureProtocolFactoryRegistered(); + + static URLRequest::ProtocolFactory Factory; // URLRequestJob methods. virtual void Start(); @@ -75,6 +78,12 @@ class URLRequestAutomationJob : public URLRequestJob { static int instance_count_; + static bool is_protocol_factory_registered_; + // The previous HTTP/HTTPs protocol factories. We pass unhandled + // requests off to these factories + static URLRequest::ProtocolFactory* old_http_factory_; + static URLRequest::ProtocolFactory* old_https_factory_; + DISALLOW_COPY_AND_ASSIGN(URLRequestAutomationJob); }; |