#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"
namespace atom {
+namespace {
+
+const char* kAsarScheme = "asar";
+
+} // namespace
+
AtomBrowserContext::AtomBrowserContext()
: fake_browser_process_(new BrowserProcess),
job_factory_(new AtomURLRequestJobFactory) {
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<net::URLRequestJobFactory> top_job_factory =
--- /dev/null
+// 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<base::TaskRunner>& 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
--- /dev/null
+// 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<base::TaskRunner>& 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<base::TaskRunner> file_task_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(AsarProtocolHandler);
+};
+
+} // namespace asar
+
+#endif // ATOM_BROWSER_NET_ASAR_ASAR_PROTOCOL_HANDLER_H_