add about: protocol handler
authordeepak1556 <hop2deep@gmail.com>
Wed, 9 Nov 2016 07:02:51 +0000 (12:32 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Wed, 9 Nov 2016 07:52:58 +0000 (13:22 +0530)
atom/browser/atom_browser_context.cc
atom/browser/net/about_protocol_handler.cc [new file with mode: 0644]
atom/browser/net/about_protocol_handler.h [new file with mode: 0644]
atom/browser/net/url_request_about_job.cc [new file with mode: 0644]
atom/browser/net/url_request_about_job.h [new file with mode: 0644]
filenames.gypi

index e076fe8..1bab4a9 100644 (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(
diff --git a/atom/browser/net/about_protocol_handler.cc b/atom/browser/net/about_protocol_handler.cc
new file mode 100644 (file)
index 0000000..12ce78a
--- /dev/null
@@ -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
diff --git a/atom/browser/net/about_protocol_handler.h b/atom/browser/net/about_protocol_handler.h
new file mode 100644 (file)
index 0000000..ad12060
--- /dev/null
@@ -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_
diff --git a/atom/browser/net/url_request_about_job.cc b/atom/browser/net/url_request_about_job.cc
new file mode 100644 (file)
index 0000000..d7112c8
--- /dev/null
@@ -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
diff --git a/atom/browser/net/url_request_about_job.h b/atom/browser/net/url_request_about_job.h
new file mode 100644 (file)
index 0000000..ed23789
--- /dev/null
@@ -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_
index 9197fc4..b7a53a4 100644 (file)
       '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',
       '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',