]> khamidou — GitHub mirrors - electron.git/commitdiff
Add undocumented "preload-url" option for web-preferences
authorCheng Zhao <zcbenz@gmail.com>
Sat, 5 Sep 2015 01:57:39 +0000 (10:57 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 6 Sep 2015 02:53:03 +0000 (10:53 +0800)
atom/browser/web_contents_preferences.cc
atom/common/options_switches.cc
atom/common/options_switches.h

index a5bb6172f514470f3efc341459b5dce825796ab1..269433e4d6b3e54835d175d23fe630b3b8c5869d 100644 (file)
@@ -8,7 +8,7 @@
 #include "base/command_line.h"
 #include "base/strings/string_number_conversions.h"
 #include "content/public/common/web_preferences.h"
-#include "storage/common/fileapi/file_system_util.h"  // IsAbsolute
+#include "net/base/filename_util.h"
 
 #if defined(OS_WIN)
 #include "ui/gfx/switches.h"
@@ -90,10 +90,19 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
 
   // The preload script.
   base::FilePath::StringType preload;
-  if (web_preferences.GetString(switches::kPreloadScript, &preload) &&
-      !preload.empty() &&
-      base::FilePath(preload).IsAbsolute())
-    command_line->AppendSwitchNative(switches::kPreloadScript, preload);
+  if (web_preferences.GetString(switches::kPreloadScript, &preload)) {
+    if (base::FilePath(preload).IsAbsolute())
+      command_line->AppendSwitchNative(switches::kPreloadScript, preload);
+    else
+      LOG(ERROR) << "preload script must have abosulute path.";
+  } else if (web_preferences.GetString(switches::kPreloadUrl, &preload)) {
+    // Translate to file path if there is "preload-url" option.
+    base::FilePath preload_path;
+    if (net::FileURLToFilePath(GURL(preload), &preload_path))
+      command_line->AppendSwitchPath(switches::kPreloadScript, preload_path);
+    else
+      LOG(ERROR) << "preload url must be file:// protocol.";
+  }
 
   // The zoom factor.
   double zoom_factor = 1.0;
index 8f457116ec3a0eac23434d138e714d9f29ef1373..ce5398e447f64c050eeb2a209ba3ae30aa4cf025 100644 (file)
@@ -75,6 +75,9 @@ const char kGuestInstanceID[] = "guest-instance-id";
 // Script that will be loaded by guest WebContents before other scripts.
 const char kPreloadScript[] = "preload";
 
+// Like --preload, but the passed argument is an URL.
+const char kPreloadUrl[] = "preload-url";
+
 // Whether the window should be transparent.
 const char kTransparent[] = "transparent";
 
index 2dd48ee32a1af9a0e0b3c32f6cd866a2c1aea9e6..c9298618bdfbd8dbf96b69afc2e7af681c868595 100644 (file)
@@ -41,6 +41,7 @@ extern const char kPpapiFlashPath[];
 extern const char kPpapiFlashVersion[];
 extern const char kGuestInstanceID[];
 extern const char kPreloadScript[];
+extern const char kPreloadUrl[];
 extern const char kTransparent[];
 extern const char kType[];
 extern const char kDisableAutoHideCursor[];