Make sure standard schemes are also set in child process
authorCheng Zhao <zcbenz@gmail.com>
Wed, 8 Jun 2016 06:46:50 +0000 (15:46 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 8 Jun 2016 06:46:50 +0000 (15:46 +0900)
atom/app/atom_content_client.cc
atom/browser/api/atom_api_protocol.cc
atom/browser/atom_browser_client.cc
atom/common/options_switches.cc
atom/common/options_switches.h

index 40a6e1f5268dd3cad4796e329079453493e45d96..c9c41404d4a254db4c43310f0a9c830991ed3189 100644 (file)
@@ -181,6 +181,20 @@ void AtomContentClient::AddAdditionalSchemes(
     std::vector<url::SchemeWithType>* standard_schemes,
     std::vector<url::SchemeWithType>* referrer_schemes,
     std::vector<std::string>* savable_schemes) {
+  // Parse --standard-schemes=scheme1,scheme2
+  auto command_line = base::CommandLine::ForCurrentProcess();
+  std::string custom_schemes = command_line->GetSwitchValueASCII(
+      switches::kStandardSchemes);
+  if (!custom_schemes.empty()) {
+    // Note that url::SchemeWithType requires passing const char*, so we have
+    // to ensure the string still lives after this function exits.
+    static std::vector<std::string> schemes_list;
+    schemes_list = base::SplitString(
+        custom_schemes, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+    for (const std::string& scheme : schemes_list)
+      standard_schemes->push_back({scheme.c_str(), url::SCHEME_WITHOUT_PORT});
+  }
+
   standard_schemes->push_back({"chrome-extension", url::SCHEME_WITHOUT_PORT});
 }
 
index 226f689d32de9ac570e56b4e9ff76c4b8cbefe86..f420e52b3e9d9bc1ce14912637aaf5e8622af54d 100644 (file)
@@ -14,6 +14,9 @@
 #include "atom/common/native_mate_converters/callback.h"
 #include "atom/common/native_mate_converters/net_converter.h"
 #include "atom/common/node_includes.h"
+#include "atom/common/options_switches.h"
+#include "base/command_line.h"
+#include "base/strings/string_util.h"
 #include "native_mate/dictionary.h"
 #include "url/url_util.h"
 
@@ -160,6 +163,10 @@ void RegisterStandardSchemes(
     const std::vector<std::string>& schemes) {
   for (const auto& scheme : schemes)
     url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
+
+  auto command_line = base::CommandLine::ForCurrentProcess();
+  command_line->AppendSwitchASCII(atom::switches::kStandardSchemes,
+                                  base::JoinString(schemes, ","));
 }
 
 mate::Handle<atom::api::Protocol> CreateProtocol(v8::Isolate* isolate) {
index e3cb9c5c8c8921db18147eb9eceacdbbb9d408b4..c1b50459c68085b81aa6562701b1f12e4b37796d 100644 (file)
@@ -169,6 +169,14 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
   if (process_type != "renderer")
     return;
 
+  // Copy following switches to child process.
+  static const char* const kCommonSwitchNames[] = {
+    switches::kStandardSchemes,
+  };
+  command_line->CopySwitchesFrom(
+      *base::CommandLine::ForCurrentProcess(),
+      kCommonSwitchNames, arraysize(kCommonSwitchNames));
+
   // The registered service worker schemes.
   if (!g_custom_service_worker_schemes.empty())
     command_line->AppendSwitchASCII(switches::kRegisterServiceWorkerSchemes,
index 22cdc3c63aefb69a558efe65fe186f9ae355c2b0..d370f0ef859fb0f5780a117b1ceda56f75bc5c0b 100644 (file)
@@ -129,6 +129,9 @@ const char kPpapiFlashVersion[] = "ppapi-flash-version";
 // Disable HTTP cache.
 const char kDisableHttpCache[] = "disable-http-cache";
 
+// The list of standard schemes.
+const char kStandardSchemes[] = "standard-schemes";
+
 // Register schemes to handle service worker.
 const char kRegisterServiceWorkerSchemes[] = "register-service-worker-schemes";
 
index 0f75e56dcb3038e33591d15a8dc05fc8816e7fb3..5924c054911920df8ca93fbec5133067223dd547 100644 (file)
@@ -71,6 +71,7 @@ extern const char kEnablePlugins[];
 extern const char kPpapiFlashPath[];
 extern const char kPpapiFlashVersion[];
 extern const char kDisableHttpCache[];
+extern const char kStandardSchemes[];
 extern const char kRegisterServiceWorkerSchemes[];
 extern const char kSSLVersionFallbackMin[];
 extern const char kCipherSuiteBlacklist[];