]> khamidou — GitHub mirrors - electron.git/commitdiff
protocol: api to register custom schemes to standard schemes
authordeepak1556 <hop2deep@gmail.com>
Fri, 12 Jun 2015 07:58:23 +0000 (13:28 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Wed, 17 Jun 2015 09:13:04 +0000 (14:43 +0530)
atom/app/atom_content_client.cc
atom/browser/api/atom_api_protocol.cc
atom/browser/api/atom_api_protocol.h
atom/browser/atom_browser_client.cc
atom/browser/atom_browser_client.h
atom/common/options_switches.cc
atom/common/options_switches.h
docs/api/protocol.md

index 74f88db0b9b2bad391273537d2169385f0fbc70b..1ba1f20315647d1fb58aa03cc82652625e377342 100644 (file)
@@ -75,6 +75,16 @@ std::string AtomContentClient::GetProduct() const {
 void AtomContentClient::AddAdditionalSchemes(
     std::vector<std::string>* standard_schemes,
     std::vector<std::string>* savable_schemes) {
+  auto command_line = base::CommandLine::ForCurrentProcess();
+  auto custom_schemes = command_line->GetSwitchValueASCII(
+      switches::kRegisterStandardSchemes);
+  if (!custom_schemes.empty()) {
+    std::vector<std::string> schemes;
+    base::SplitString(custom_schemes, ',', &schemes);
+    standard_schemes->insert(standard_schemes->end(),
+                             schemes.begin(),
+                             schemes.end());
+  }
   standard_schemes->push_back("chrome-extension");
 }
 
index 9bc2de4b42a94a89e576532669e9be9888af41eb..db7252ec95b9634444f359d65ff5d7e1b68bd0e0 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "atom/browser/api/atom_api_protocol.h"
 
+#include "atom/browser/atom_browser_client.h"
 #include "atom/browser/atom_browser_context.h"
 #include "atom/browser/net/adapter_request_job.h"
 #include "atom/browser/net/atom_url_request_job_factory.h"
@@ -205,6 +206,7 @@ mate::ObjectTemplateBuilder Protocol::GetObjectTemplateBuilder(
   return mate::ObjectTemplateBuilder(isolate)
       .SetMethod("registerProtocol", &Protocol::RegisterProtocol)
       .SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol)
+      .SetMethod("registerStandardSchemes", &Protocol::RegisterStandardSchemes)
       .SetMethod("isHandledProtocol", &Protocol::IsHandledProtocol)
       .SetMethod("interceptProtocol", &Protocol::InterceptProtocol)
       .SetMethod("uninterceptProtocol", &Protocol::UninterceptProtocol);
@@ -237,6 +239,11 @@ void Protocol::UnregisterProtocol(v8::Isolate* isolate,
                                      base::Unretained(this), scheme));
 }
 
+void Protocol::RegisterStandardSchemes(
+    const std::vector<std::string>& schemes) {
+  atom::AtomBrowserClient::SetCustomSchemes(schemes);
+}
+
 bool Protocol::IsHandledProtocol(const std::string& scheme) {
   return job_factory_->IsHandledProtocol(scheme);
 }
index 34725cecc92552803be512ae7dedd03f98c65c39..b059440f292781ba3524981e3374a3f1a19b14c5 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <string>
 #include <map>
+#include <vector>
 
 #include "atom/browser/api/event_emitter.h"
 #include "base/callback.h"
@@ -41,6 +42,9 @@ class Protocol : public mate::EventEmitter {
  private:
   typedef std::map<std::string, JsProtocolHandler> ProtocolHandlersMap;
 
+  // Register schemes to standard scheme list.
+  void RegisterStandardSchemes(const std::vector<std::string>& schemes);
+
   // Register/unregister an networking |scheme| which would be handled by
   // |callback|.
   void RegisterProtocol(v8::Isolate* isolate,
index ec519fa4f822b50f979fc4ae44a065d1e42c2bbc..c62bc6436ddd6f3692e2d6cb891acf9cd91e63a3 100644 (file)
@@ -16,6 +16,7 @@
 #include "base/command_line.h"
 #include "base/files/file_util.h"
 #include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
 #include "chrome/browser/printing/printing_message_filter.h"
 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
 #include "chrome/browser/speech/tts_message_filter.h"
@@ -43,6 +44,9 @@ int kDefaultRoutingID = 2;
 // Next navigation should not restart renderer process.
 bool g_suppress_renderer_process_restart = false;
 
+// Custom schemes to be registered to standard.
+std::string g_custom_schemes = "";
+
 // Find out the owner of the child process according to |process_id|.
 enum ProcessOwner {
   OWNER_NATIVE_WINDOW,
@@ -95,6 +99,11 @@ void AtomBrowserClient::SuppressRendererProcessRestartForOnce() {
   g_suppress_renderer_process_restart = true;
 }
 
+void AtomBrowserClient::SetCustomSchemes(
+    const std::vector<std::string>& schemes) {
+  g_custom_schemes = JoinString(schemes, ',');
+}
+
 AtomBrowserClient::AtomBrowserClient() {
 }
 
@@ -174,9 +183,13 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
     base::CommandLine* command_line,
     int process_id) {
   std::string process_type = command_line->GetSwitchValueASCII("type");
+
   if (process_type != "renderer")
     return;
 
+  command_line->AppendSwitchASCII(switches::kRegisterStandardSchemes,
+                                  g_custom_schemes);
+
   NativeWindow* window;
   WebViewManager::WebViewInfo info;
   ProcessOwner owner = GetProcessOwner(process_id, &window, &info);
index c8a26da7099f5dd5b71fd06e6b6064be360af5b8..8cbdb3f2e1993f977129f7d27f06494e911960af 100644 (file)
@@ -6,6 +6,7 @@
 #define ATOM_BROWSER_ATOM_BROWSER_CLIENT_H_
 
 #include <string>
+#include <vector>
 
 #include "brightray/browser/browser_client.h"
 
@@ -27,6 +28,8 @@ class AtomBrowserClient : public brightray::BrowserClient {
 
   // Don't force renderer process to restart for once.
   static void SuppressRendererProcessRestartForOnce();
+  // Custom schemes to be registered to standard.
+  static void SetCustomSchemes(const std::vector<std::string>& schemes);
 
  protected:
   // content::ContentBrowserClient:
index 2764f86a5fcfdfa45c0899bc95b10da255f3eed7..71469b9601b65ac979d08f32fd93c4f9ea04e05c 100644 (file)
@@ -104,6 +104,9 @@ const char kPageVisibility[] = "page-visibility";
 // Disable HTTP cache.
 const char kDisableHttpCache[] = "disable-http-cache";
 
+// Register schemes to standard.
+const char kRegisterStandardSchemes[] = "register-standard-schemes";
+
 }  // namespace switches
 
 }  // namespace atom
index e6d85063341a117fef37314e89ce3cd148c20f4e..fc25208a60acf26df2ebe78b7a4958760e4fa5af 100644 (file)
@@ -56,6 +56,7 @@ extern const char kSharedWorker[];
 extern const char kPageVisibility[];
 
 extern const char kDisableHttpCache[];
+extern const char kRegisterStandardSchemes[];
 
 }  // namespace switches
 
index ba62bf301f412340c89356f8c52338452b068d05..c6dd373b586c2a26b8459834591eb7370dedf25a 100644 (file)
@@ -39,6 +39,12 @@ response you would like to send.
 
 Unregisters the custom protocol of `scheme`.
 
+## protocol.registerStandardSchemes(value)
+
+* `value` Array
+
+`value` is an array of custom schemes to be registered to the standard.
+
 ## protocol.isHandledProtocol(scheme)
 
 * `scheme` String