| Index: chrome/browser/custom_handlers/protocol_handler_registry.cc
|
| diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.cc b/chrome/browser/custom_handlers/protocol_handler_registry.cc
|
| index bab8c445560eba9b7b4e95bf914fa86c8dd9299c..8f20104e2f8b9fa16b4c4b8175507256807b8a8e 100644
|
| --- a/chrome/browser/custom_handlers/protocol_handler_registry.cc
|
| +++ b/chrome/browser/custom_handlers/protocol_handler_registry.cc
|
| @@ -9,8 +9,6 @@
|
| #include "base/bind.h"
|
| #include "base/command_line.h"
|
| #include "base/logging.h"
|
| -#include "base/memory/ref_counted.h"
|
| -#include "base/memory/scoped_ptr.h"
|
| #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h"
|
| #include "chrome/browser/net/chrome_url_request_context.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| @@ -19,13 +17,9 @@
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/custom_handlers/protocol_handler.h"
|
| #include "chrome/common/pref_names.h"
|
| -#include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/child_process_security_policy.h"
|
| -#include "content/public/browser/notification_service.h"
|
| #include "grit/generated_resources.h"
|
| #include "net/base/network_delegate.h"
|
| -#include "net/url_request/url_request.h"
|
| -#include "net/url_request/url_request_job.h"
|
| #include "net/url_request/url_request_redirect_job.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| @@ -155,62 +149,83 @@ net::URLRequestJob* ProtocolHandlerRegistry::Core::MaybeCreateJob(
|
| net::URLRequestRedirectJob::REDIRECT_302_FOUND);
|
| }
|
|
|
| -// URLInterceptor ------------------------------------------------------------
|
| +// JobInterceptorFactory -------------------------------------------------------
|
|
|
| -// Instances of this class are produced for ownership by the IO
|
| +// Instances of JobFactory are produced for ownership by the IO
|
| // thread where it handler URL requests. We should never hold
|
| // any pointers on this class, only produce them in response to
|
| -// requests via |ProtocolHandlerRegistry::CreateURLInterceptor|.
|
| -class ProtocolHandlerRegistry::URLInterceptor
|
| - : public net::URLRequestJobFactory::Interceptor {
|
| - public:
|
| - explicit URLInterceptor(Core* core);
|
| - virtual ~URLInterceptor();
|
| +// requests via |ProtocolHandlerRegistry::CreateURLRequestJobFactory|.
|
| +ProtocolHandlerRegistry::JobInterceptorFactory::JobInterceptorFactory(
|
| + Core* core) : core_(core) {
|
| + DCHECK(core_);
|
| + DetachFromThread();
|
| +}
|
|
|
| - virtual net::URLRequestJob* MaybeIntercept(
|
| - net::URLRequest* request,
|
| - net::NetworkDelegate* network_delegate) const OVERRIDE;
|
| +ProtocolHandlerRegistry::JobInterceptorFactory::~JobInterceptorFactory() {
|
| +}
|
|
|
| - virtual bool WillHandleProtocol(const std::string& protocol) const OVERRIDE;
|
| +void ProtocolHandlerRegistry::JobInterceptorFactory::Chain(
|
| + scoped_ptr<net::URLRequestJobFactory> job_factory) {
|
| + job_factory_ = job_factory.Pass();
|
| +}
|
|
|
| - virtual net::URLRequestJob* MaybeInterceptRedirect(
|
| - const GURL& url,
|
| - net::URLRequest* request,
|
| - net::NetworkDelegate* network_delegate) const OVERRIDE {
|
| - return NULL;
|
| - }
|
| +bool ProtocolHandlerRegistry::JobInterceptorFactory::SetProtocolHandler(
|
| + const std::string& scheme, ProtocolHandler* protocol_handler) {
|
| + return job_factory_->SetProtocolHandler(scheme, protocol_handler);
|
| +}
|
|
|
| - virtual net::URLRequestJob* MaybeInterceptResponse(
|
| - net::URLRequest* request,
|
| - net::NetworkDelegate* network_delegate) const OVERRIDE {
|
| - return NULL;
|
| - }
|
| +void ProtocolHandlerRegistry::JobInterceptorFactory::AddInterceptor(
|
| + Interceptor* interceptor) {
|
| + return job_factory_->AddInterceptor(interceptor);
|
| +}
|
|
|
| - private:
|
| - scoped_refptr<Core> core_;
|
| - DISALLOW_COPY_AND_ASSIGN(URLInterceptor);
|
| -};
|
| +net::URLRequestJob*
|
| +ProtocolHandlerRegistry::JobInterceptorFactory::MaybeCreateJobWithInterceptor(
|
| + net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
|
| + return job_factory_->MaybeCreateJobWithInterceptor(request, network_delegate);
|
| +}
|
|
|
| -ProtocolHandlerRegistry::URLInterceptor::URLInterceptor(Core* core)
|
| - : core_(core) {
|
| - DCHECK(core_);
|
| +net::URLRequestJob*
|
| +ProtocolHandlerRegistry::JobInterceptorFactory::
|
| +MaybeCreateJobWithProtocolHandler(
|
| + const std::string& scheme,
|
| + net::URLRequest* request,
|
| + net::NetworkDelegate* network_delegate) const {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + net::URLRequestJob* job = core_->MaybeCreateJob(request, network_delegate);
|
| + if (job)
|
| + return job;
|
| + return job_factory_->MaybeCreateJobWithProtocolHandler(
|
| + scheme, request, network_delegate);
|
| }
|
|
|
| -ProtocolHandlerRegistry::URLInterceptor::~URLInterceptor() {
|
| +net::URLRequestJob*
|
| +ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptRedirect(
|
| + const GURL& location,
|
| + net::URLRequest* request,
|
| + net::NetworkDelegate* network_delegate) const {
|
| + return job_factory_->MaybeInterceptRedirect(
|
| + location, request, network_delegate);
|
| }
|
|
|
| -net::URLRequestJob* ProtocolHandlerRegistry::URLInterceptor::MaybeIntercept(
|
| +net::URLRequestJob*
|
| +ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptResponse(
|
| net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| -
|
| - return core_->MaybeCreateJob(request, network_delegate);
|
| + return job_factory_->MaybeInterceptResponse(request, network_delegate);
|
| }
|
|
|
| -bool ProtocolHandlerRegistry::URLInterceptor::WillHandleProtocol(
|
| - const std::string& protocol) const {
|
| +bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledProtocol(
|
| + const std::string& scheme) const {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + return core_->IsHandledProtocol(scheme) ||
|
| + job_factory_->IsHandledProtocol(scheme);
|
| +}
|
|
|
| - return core_->IsHandledProtocol(protocol);
|
| +bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledURL(
|
| + const GURL& url) const {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + return (url.is_valid() && core_->IsHandledProtocol(url.scheme())) ||
|
| + job_factory_->IsHandledURL(url);
|
| }
|
|
|
| // DefaultClientObserver ------------------------------------------------------
|
| @@ -875,11 +890,11 @@ void ProtocolHandlerRegistry::AddPredefinedHandler(
|
| SetDefault(handler);
|
| }
|
|
|
| -net::URLRequestJobFactory::Interceptor*
|
| - ProtocolHandlerRegistry::CreateURLInterceptor() {
|
| +scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
|
| +ProtocolHandlerRegistry::CreateJobInterceptorFactory() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| // this is always created on the UI thread (in profile_io's
|
| // InitializeOnUIThread. Any method calls must be done
|
| // on the IO thread (this is checked).
|
| - return new URLInterceptor(core_);
|
| + return scoped_ptr<JobInterceptorFactory>(new JobInterceptorFactory(core_));
|
| }
|
|
|