diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index d3b40fe1ef99..4c4ac3d384c9 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -6,6 +6,7 @@ #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/net/atom_url_request_job_factory.h" +#include "atom/browser/net/asar/asar_protocol_handler.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" #include "chrome/browser/browser_process.h" @@ -20,6 +21,12 @@ using content::BrowserThread; namespace atom { +namespace { + +const char* kAsarScheme = "asar"; + +} // namespace + AtomBrowserContext::AtomBrowserContext() : fake_browser_process_(new BrowserProcess), job_factory_(new AtomURLRequestJobFactory) { @@ -44,6 +51,10 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory( url::kFileScheme, new net::FileProtocolHandler( BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); + job_factory->SetProtocolHandler( + kAsarScheme, new asar::AsarProtocolHandler( + BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); // Set up interceptors in the reverse order. scoped_ptr top_job_factory = diff --git a/atom/browser/net/asar/asar_protocol_handler.cc b/atom/browser/net/asar/asar_protocol_handler.cc new file mode 100644 index 000000000000..5bc93d8dd002 --- /dev/null +++ b/atom/browser/net/asar/asar_protocol_handler.cc @@ -0,0 +1,33 @@ +// Copyright (c) 2014 GitHub, Inc. All rights reserved. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/net/asar/asar_protocol_handler.h" + +#include "net/base/filename_util.h" +#include "net/url_request/url_request_file_job.h" + +namespace asar { + +AsarProtocolHandler::AsarProtocolHandler( + const scoped_refptr& file_task_runner) + : file_task_runner_(file_task_runner) { +} + +AsarProtocolHandler::~AsarProtocolHandler() { +} + +net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob( + net::URLRequest* request, + net::NetworkDelegate* network_delegate) const { + base::FilePath file_path; + net::FileURLToFilePath(request->url(), &file_path); + return new net::URLRequestFileJob(request, network_delegate, file_path, + file_task_runner_); +} + +bool AsarProtocolHandler::IsSafeRedirectTarget(const GURL& location) const { + return false; +} + +} // namespace asar diff --git a/atom/browser/net/asar/asar_protocol_handler.h b/atom/browser/net/asar/asar_protocol_handler.h new file mode 100644 index 000000000000..bdf26e064452 --- /dev/null +++ b/atom/browser/net/asar/asar_protocol_handler.h @@ -0,0 +1,37 @@ +// Copyright (c) 2014 GitHub, Inc. All rights reserved. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_ +#define ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_ + +#include "base/memory/ref_counted.h" +#include "net/url_request/url_request_job_factory.h" + +namespace base { +class TaskRunner; +} + +namespace asar { + +class AsarProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { + public: + explicit AsarProtocolHandler( + const scoped_refptr& file_task_runner); + virtual ~AsarProtocolHandler(); + + // net::URLRequestJobFactory::ProtocolHandler: + virtual net::URLRequestJob* MaybeCreateJob( + net::URLRequest* request, + net::NetworkDelegate* network_delegate) const OVERRIDE; + virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE; + + private: + const scoped_refptr file_task_runner_; + + DISALLOW_COPY_AND_ASSIGN(AsarProtocolHandler); +}; + +} // namespace asar + +#endif // ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_ diff --git a/atom/browser/net/asar/url_request_asar_job.cc b/atom/browser/net/asar/url_request_asar_job.cc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/atom/browser/net/asar/url_request_asar_job.h b/atom/browser/net/asar/url_request_asar_job.h new file mode 100644 index 000000000000..e69de29bb2d1