add about: protocol handler

This commit is contained in:
deepak1556 2016-11-09 12:32:51 +05:30
parent 3aab713d24
commit a0065e62fa
6 changed files with 133 additions and 0 deletions

View file

@ -10,6 +10,7 @@
#include "atom/browser/atom_download_manager_delegate.h"
#include "atom/browser/atom_permission_manager.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/atom_cert_verifier.h"
#include "atom/browser/net/atom_ct_delegate.h"
@ -130,6 +131,8 @@ AtomBrowserContext::CreateURLRequestJobFactory(
}
protocol_handlers->clear();
job_factory->SetProtocolHandler(url::kAboutScheme,
base::WrapUnique(new AboutProtocolHandler));
job_factory->SetProtocolHandler(
url::kDataScheme, base::WrapUnique(new net::DataProtocolHandler));
job_factory->SetProtocolHandler(

View 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

View 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_

View 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

View 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_

View file

@ -228,6 +228,8 @@
'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_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.h',
'atom/browser/net/asar/url_request_asar_job.cc',
@ -250,6 +252,8 @@
'atom/browser/net/http_protocol_handler.h',
'atom/browser/net/js_asker.cc',
'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.h',
'atom/browser/net/url_request_string_job.cc',