Merge pull request #7908 from deepak1556/about_scheme_patch
protocol: register about scheme handler
This commit is contained in:
commit
7b463297c6
7 changed files with 140 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include "atom/browser/atom_download_manager_delegate.h"
|
#include "atom/browser/atom_download_manager_delegate.h"
|
||||||
#include "atom/browser/atom_permission_manager.h"
|
#include "atom/browser/atom_permission_manager.h"
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
|
#include "atom/browser/net/about_protocol_handler.h"
|
||||||
#include "atom/browser/net/asar/asar_protocol_handler.h"
|
#include "atom/browser/net/asar/asar_protocol_handler.h"
|
||||||
#include "atom/browser/net/atom_cert_verifier.h"
|
#include "atom/browser/net/atom_cert_verifier.h"
|
||||||
#include "atom/browser/net/atom_ct_delegate.h"
|
#include "atom/browser/net/atom_ct_delegate.h"
|
||||||
|
@ -130,6 +131,8 @@ AtomBrowserContext::CreateURLRequestJobFactory(
|
||||||
}
|
}
|
||||||
protocol_handlers->clear();
|
protocol_handlers->clear();
|
||||||
|
|
||||||
|
job_factory->SetProtocolHandler(url::kAboutScheme,
|
||||||
|
base::WrapUnique(new AboutProtocolHandler));
|
||||||
job_factory->SetProtocolHandler(
|
job_factory->SetProtocolHandler(
|
||||||
url::kDataScheme, base::WrapUnique(new net::DataProtocolHandler));
|
url::kDataScheme, base::WrapUnique(new net::DataProtocolHandler));
|
||||||
job_factory->SetProtocolHandler(
|
job_factory->SetProtocolHandler(
|
||||||
|
|
25
atom/browser/net/about_protocol_handler.cc
Normal file
25
atom/browser/net/about_protocol_handler.cc
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright (c) 2016 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "atom/browser/net/about_protocol_handler.h"
|
||||||
|
|
||||||
|
#include "atom/browser/net/url_request_about_job.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
AboutProtocolHandler::AboutProtocolHandler() {}
|
||||||
|
|
||||||
|
AboutProtocolHandler::~AboutProtocolHandler() {}
|
||||||
|
|
||||||
|
net::URLRequestJob* AboutProtocolHandler::MaybeCreateJob(
|
||||||
|
net::URLRequest* request,
|
||||||
|
net::NetworkDelegate* network_delegate) const {
|
||||||
|
return new URLRequestAboutJob(request, network_delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AboutProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace atom
|
29
atom/browser/net/about_protocol_handler.h
Normal file
29
atom/browser/net/about_protocol_handler.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright (c) 2016 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef ATOM_BROWSER_NET_ABOUT_PROTOCOL_HANDLER_H_
|
||||||
|
#define ATOM_BROWSER_NET_ABOUT_PROTOCOL_HANDLER_H_
|
||||||
|
|
||||||
|
#include "net/url_request/url_request_job_factory.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
class AboutProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
|
||||||
|
public:
|
||||||
|
AboutProtocolHandler();
|
||||||
|
~AboutProtocolHandler() override;
|
||||||
|
|
||||||
|
// net::URLRequestJobFactory::ProtocolHandler:
|
||||||
|
net::URLRequestJob* MaybeCreateJob(
|
||||||
|
net::URLRequest* request,
|
||||||
|
net::NetworkDelegate* network_delegate) const override;
|
||||||
|
bool IsSafeRedirectTarget(const GURL& location) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(AboutProtocolHandler);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
#endif // ATOM_BROWSER_NET_ABOUT_PROTOCOL_HANDLER_H_
|
37
atom/browser/net/url_request_about_job.cc
Normal file
37
atom/browser/net/url_request_about_job.cc
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright (c) 2016 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "atom/browser/net/url_request_about_job.h"
|
||||||
|
|
||||||
|
#include "base/threading/thread_task_runner_handle.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
URLRequestAboutJob::URLRequestAboutJob(net::URLRequest* request,
|
||||||
|
net::NetworkDelegate* network_delegate)
|
||||||
|
: net::URLRequestJob(request, network_delegate), weak_ptr_factory_(this) {}
|
||||||
|
|
||||||
|
void URLRequestAboutJob::Start() {
|
||||||
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||||
|
FROM_HERE, base::Bind(&URLRequestAboutJob::StartAsync,
|
||||||
|
weak_ptr_factory_.GetWeakPtr()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void URLRequestAboutJob::Kill() {
|
||||||
|
weak_ptr_factory_.InvalidateWeakPtrs();
|
||||||
|
URLRequestJob::Kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool URLRequestAboutJob::GetMimeType(std::string* mime_type) const {
|
||||||
|
*mime_type = "text/html";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
URLRequestAboutJob::~URLRequestAboutJob() {}
|
||||||
|
|
||||||
|
void URLRequestAboutJob::StartAsync() {
|
||||||
|
NotifyHeadersComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace atom
|
35
atom/browser/net/url_request_about_job.h
Normal file
35
atom/browser/net/url_request_about_job.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright (c) 2016 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef ATOM_BROWSER_NET_URL_REQUEST_ABOUT_JOB_H_
|
||||||
|
#define ATOM_BROWSER_NET_URL_REQUEST_ABOUT_JOB_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "base/memory/weak_ptr.h"
|
||||||
|
#include "net/url_request/url_request_job.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
class URLRequestAboutJob : public net::URLRequestJob {
|
||||||
|
public:
|
||||||
|
URLRequestAboutJob(net::URLRequest*, net::NetworkDelegate*);
|
||||||
|
|
||||||
|
// URLRequestJob:
|
||||||
|
void Start() override;
|
||||||
|
void Kill() override;
|
||||||
|
bool GetMimeType(std::string* mime_type) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
~URLRequestAboutJob() override;
|
||||||
|
void StartAsync();
|
||||||
|
|
||||||
|
base::WeakPtrFactory<URLRequestAboutJob> weak_ptr_factory_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(URLRequestAboutJob);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
#endif // ATOM_BROWSER_NET_URL_REQUEST_ABOUT_JOB_H_
|
|
@ -228,6 +228,8 @@
|
||||||
'atom/browser/osr/osr_render_widget_host_view.cc',
|
'atom/browser/osr/osr_render_widget_host_view.cc',
|
||||||
'atom/browser/osr/osr_render_widget_host_view.h',
|
'atom/browser/osr/osr_render_widget_host_view.h',
|
||||||
'atom/browser/osr/osr_render_widget_host_view_mac.mm',
|
'atom/browser/osr/osr_render_widget_host_view_mac.mm',
|
||||||
|
'atom/browser/net/about_protocol_handler.cc',
|
||||||
|
'atom/browser/net/about_protocol_handler.h',
|
||||||
'atom/browser/net/asar/asar_protocol_handler.cc',
|
'atom/browser/net/asar/asar_protocol_handler.cc',
|
||||||
'atom/browser/net/asar/asar_protocol_handler.h',
|
'atom/browser/net/asar/asar_protocol_handler.h',
|
||||||
'atom/browser/net/asar/url_request_asar_job.cc',
|
'atom/browser/net/asar/url_request_asar_job.cc',
|
||||||
|
@ -250,6 +252,8 @@
|
||||||
'atom/browser/net/http_protocol_handler.h',
|
'atom/browser/net/http_protocol_handler.h',
|
||||||
'atom/browser/net/js_asker.cc',
|
'atom/browser/net/js_asker.cc',
|
||||||
'atom/browser/net/js_asker.h',
|
'atom/browser/net/js_asker.h',
|
||||||
|
'atom/browser/net/url_request_about_job.cc',
|
||||||
|
'atom/browser/net/url_request_about_job.h',
|
||||||
'atom/browser/net/url_request_async_asar_job.cc',
|
'atom/browser/net/url_request_async_asar_job.cc',
|
||||||
'atom/browser/net/url_request_async_asar_job.h',
|
'atom/browser/net/url_request_async_asar_job.h',
|
||||||
'atom/browser/net/url_request_string_job.cc',
|
'atom/browser/net/url_request_string_job.cc',
|
||||||
|
|
|
@ -570,6 +570,13 @@ describe('protocol module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('protocol.isProtocolHandled', function () {
|
describe('protocol.isProtocolHandled', function () {
|
||||||
|
it('returns true for about:', function (done) {
|
||||||
|
protocol.isProtocolHandled('about', function (result) {
|
||||||
|
assert.equal(result, true)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('returns true for file:', function (done) {
|
it('returns true for file:', function (done) {
|
||||||
protocol.isProtocolHandled('file', function (result) {
|
protocol.isProtocolHandled('file', function (result) {
|
||||||
assert.equal(result, true)
|
assert.equal(result, true)
|
||||||
|
|
Loading…
Reference in a new issue