Add asar:// protocol handler.
This commit is contained in:
parent
50ea0f0b45
commit
9b71117171
5 changed files with 81 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "atom/browser/atom_browser_main_parts.h"
|
#include "atom/browser/atom_browser_main_parts.h"
|
||||||
#include "atom/browser/net/atom_url_request_job_factory.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/sequenced_worker_pool.h"
|
||||||
#include "base/threading/worker_pool.h"
|
#include "base/threading/worker_pool.h"
|
||||||
#include "chrome/browser/browser_process.h"
|
#include "chrome/browser/browser_process.h"
|
||||||
|
@ -20,6 +21,12 @@ using content::BrowserThread;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const char* kAsarScheme = "asar";
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
AtomBrowserContext::AtomBrowserContext()
|
AtomBrowserContext::AtomBrowserContext()
|
||||||
: fake_browser_process_(new BrowserProcess),
|
: fake_browser_process_(new BrowserProcess),
|
||||||
job_factory_(new AtomURLRequestJobFactory) {
|
job_factory_(new AtomURLRequestJobFactory) {
|
||||||
|
@ -44,6 +51,10 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory(
|
||||||
url::kFileScheme, new net::FileProtocolHandler(
|
url::kFileScheme, new net::FileProtocolHandler(
|
||||||
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
|
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
|
||||||
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
|
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.
|
// Set up interceptors in the reverse order.
|
||||||
scoped_ptr<net::URLRequestJobFactory> top_job_factory =
|
scoped_ptr<net::URLRequestJobFactory> top_job_factory =
|
||||||
|
|
33
atom/browser/net/asar/asar_protocol_handler.cc
Normal file
33
atom/browser/net/asar/asar_protocol_handler.cc
Normal file
|
@ -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<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
|
37
atom/browser/net/asar/asar_protocol_handler.h
Normal file
37
atom/browser/net/asar/asar_protocol_handler.h
Normal file
|
@ -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<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_
|
0
atom/browser/net/asar/url_request_asar_job.cc
Normal file
0
atom/browser/net/asar/url_request_asar_job.cc
Normal file
0
atom/browser/net/asar/url_request_asar_job.h
Normal file
0
atom/browser/net/asar/url_request_asar_job.h
Normal file
Loading…
Reference in a new issue