2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-09-23 04:13:46 +00:00
|
|
|
// 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"
|
|
|
|
|
2014-09-23 11:14:30 +00:00
|
|
|
#include "atom/browser/net/asar/url_request_asar_job.h"
|
2014-09-25 13:54:59 +00:00
|
|
|
#include "atom/common/asar/archive.h"
|
2015-02-12 09:23:49 +00:00
|
|
|
#include "atom/common/asar/asar_util.h"
|
2014-09-23 04:13:46 +00:00
|
|
|
#include "net/base/filename_util.h"
|
2014-09-23 13:48:40 +00:00
|
|
|
#include "net/base/net_errors.h"
|
|
|
|
#include "net/url_request/url_request_error_job.h"
|
2014-09-23 04:13:46 +00:00
|
|
|
#include "net/url_request/url_request_file_job.h"
|
|
|
|
|
|
|
|
namespace asar {
|
|
|
|
|
|
|
|
AsarProtocolHandler::AsarProtocolHandler(
|
|
|
|
const scoped_refptr<base::TaskRunner>& file_task_runner)
|
2014-09-23 11:14:30 +00:00
|
|
|
: file_task_runner_(file_task_runner) {}
|
2014-09-23 04:13:46 +00:00
|
|
|
|
2014-09-25 12:38:12 +00:00
|
|
|
AsarProtocolHandler::~AsarProtocolHandler() {
|
2014-09-25 13:54:59 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 04:13:46 +00:00
|
|
|
net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob(
|
|
|
|
net::URLRequest* request,
|
|
|
|
net::NetworkDelegate* network_delegate) const {
|
2014-09-23 11:14:30 +00:00
|
|
|
base::FilePath full_path;
|
|
|
|
net::FileURLToFilePath(request->url(), &full_path);
|
|
|
|
|
2014-09-23 13:48:40 +00:00
|
|
|
// Create asar:// job when the path contains "xxx.asar/", otherwise treat the
|
|
|
|
// URL request as file://.
|
2014-09-23 11:14:30 +00:00
|
|
|
base::FilePath asar_path, relative_path;
|
2015-02-12 09:31:14 +00:00
|
|
|
if (!GetAsarArchivePath(full_path, &asar_path, &relative_path))
|
2014-09-23 11:14:30 +00:00
|
|
|
return new net::URLRequestFileJob(request, network_delegate, full_path,
|
|
|
|
file_task_runner_);
|
2014-09-23 13:48:40 +00:00
|
|
|
|
2015-02-12 09:23:49 +00:00
|
|
|
std::shared_ptr<Archive> archive = GetOrCreateAsarArchive(asar_path);
|
2014-09-23 14:31:45 +00:00
|
|
|
if (!archive)
|
|
|
|
return new net::URLRequestErrorJob(request, network_delegate,
|
|
|
|
net::ERR_FILE_NOT_FOUND);
|
2014-09-23 13:48:40 +00:00
|
|
|
|
2014-09-23 14:31:45 +00:00
|
|
|
return new URLRequestAsarJob(request, network_delegate, archive,
|
2014-09-23 13:48:40 +00:00
|
|
|
relative_path, file_task_runner_);
|
2014-09-23 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AsarProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace asar
|