From: deepak1556 Date: Mon, 11 May 2015 07:26:36 +0000 (+0530) Subject: support https, ws, wss builtin schemes to be intercepted X-Git-Tag: v0.26.1~18^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=707503ac40e5fda17b504ee746203bb86a179c6a;p=electron.git support https, ws, wss builtin schemes to be intercepted --- diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 835a5c50..d69aab22 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 9cc3d2d2..cf5fc01c 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 ad66fa75..98085374 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 060f0350..5b721403 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