diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 835a5c50ae0a..d69aab22fa8a 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -61,7 +61,13 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory( BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); job_factory->SetProtocolHandler( - url::kHttpScheme, new HttpProtocolHandler()); + url::kHttpScheme, new HttpProtocolHandler(url::kHttpScheme)); + job_factory->SetProtocolHandler( + url::kHttpsScheme, new HttpProtocolHandler(url::kHttpsScheme)); + job_factory->SetProtocolHandler( + url::kWsScheme, new HttpProtocolHandler(url::kWsScheme)); + job_factory->SetProtocolHandler( + url::kWssScheme, new HttpProtocolHandler(url::kWssScheme)); // Set up interceptors in the reverse order. scoped_ptr top_job_factory = job_factory.Pass(); diff --git a/atom/browser/net/http_protocol_handler.cc b/atom/browser/net/http_protocol_handler.cc index 9cc3d2d2675e..cf5fc01c0884 100644 --- a/atom/browser/net/http_protocol_handler.cc +++ b/atom/browser/net/http_protocol_handler.cc @@ -8,7 +8,8 @@ namespace atom { -HttpProtocolHandler::HttpProtocolHandler() { +HttpProtocolHandler::HttpProtocolHandler(const std::string& scheme) + : scheme_(scheme) { } HttpProtocolHandler::~HttpProtocolHandler() { @@ -19,7 +20,7 @@ net::URLRequestJob* HttpProtocolHandler::MaybeCreateJob( net::NetworkDelegate* network_delegate) const { return net::URLRequestHttpJob::Factory(request, network_delegate, - "http"); + scheme_); } } // namespace atom diff --git a/atom/browser/net/http_protocol_handler.h b/atom/browser/net/http_protocol_handler.h index ad66fa75e054..98085374175b 100644 --- a/atom/browser/net/http_protocol_handler.h +++ b/atom/browser/net/http_protocol_handler.h @@ -5,19 +5,24 @@ #ifndef ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_ #define ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_ +#include + #include "net/url_request/url_request_job_factory.h" namespace atom { class HttpProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { public: - HttpProtocolHandler(); + explicit HttpProtocolHandler(const std::string&); virtual ~HttpProtocolHandler(); // net::URLRequestJobFactory::ProtocolHandler: net::URLRequestJob* MaybeCreateJob( net::URLRequest* request, net::NetworkDelegate* network_delegate) const override; + + private: + std::string scheme_; }; } // namespace atom diff --git a/spec/api-protocol-spec.coffee b/spec/api-protocol-spec.coffee index 060f035037d1..5b72140344b7 100644 --- a/spec/api-protocol-spec.coffee +++ b/spec/api-protocol-spec.coffee @@ -197,3 +197,24 @@ describe 'protocol module', -> protocol.uninterceptProtocol 'http' done() protocol.interceptProtocol 'http', handler + + it 'can override https protocol handler', (done) -> + handler = remote.createFunctionWithReturnValue 'valar morghulis' + protocol.once 'intercepted', -> + protocol.uninterceptProtocol 'https' + done() + protocol.interceptProtocol 'https', handler + + it 'can override ws protocol handler', (done) -> + handler = remote.createFunctionWithReturnValue 'valar morghulis' + protocol.once 'intercepted', -> + protocol.uninterceptProtocol 'ws' + done() + protocol.interceptProtocol 'ws', handler + + it 'can override wss protocol handler', (done) -> + handler = remote.createFunctionWithReturnValue 'valar morghulis' + protocol.once 'intercepted', -> + protocol.uninterceptProtocol 'wss' + done() + protocol.interceptProtocol 'wss', handler