]> khamidou — GitHub mirrors - electron.git/commitdiff
Add "preload" option for BrowserWindow
authorCheng Zhao <zcbenz@gmail.com>
Wed, 12 Nov 2014 07:04:03 +0000 (15:04 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 12 Nov 2014 07:04:03 +0000 (15:04 +0800)
atom/browser/native_window.cc
atom/browser/native_window.h
atom/common/options_switches.cc
atom/renderer/lib/init.coffee

index a4366649b3a1b596326dd60beca178f1c9f2c864..95dc491ed43d601500a675f7e670786e321ea96e 100644 (file)
@@ -101,6 +101,13 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
   // Read icon before window is created.
   options.Get(switches::kIcon, &icon_);
 
+  // The "preload" option must be absolute path.
+  if (options.Get(switches::kPreloadScript, &preload_script_) &&
+      !preload_script_.IsAbsolute()) {
+    LOG(ERROR) << "Path of \"preload\" script must be absolute.";
+    preload_script_.clear();
+  }
+
   // Be compatible with old API of "node-integration" option.
   std::string old_string_token;
   if (options.Get(switches::kNodeIntegration, &old_string_token) &&
@@ -349,6 +356,10 @@ void NativeWindow::AppendExtraCommandLineSwitches(
   command_line->AppendSwitchASCII(switches::kNodeIntegration,
                                   node_integration_ ? "true" : "false");
 
+  // Append --preload.
+  if (!preload_script_.empty())
+    command_line->AppendSwitchPath(switches::kPreloadScript, preload_script_);
+
   // Append --zoom-factor.
   if (zoom_factor_ != 1.0)
     command_line->AppendSwitchASCII(switches::kZoomFactor,
index 7a21083ab3016be0bf610289f6b9ef9ba1d83632..a57a1a9dbe2b7eb8ad0db3ee8b3e30aa9a4e368f 100644 (file)
@@ -318,6 +318,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   // Web preferences.
   mate::PersistentDictionary web_preferences_;
 
+  // The script to load before page's JavaScript starts to run.
+  base::FilePath preload_script_;
+
   // Page's default zoom factor.
   double zoom_factor_;
 
index e6e65f204bbdbdc0d1dae213c9e582f65af16d54..4bbc5e60751575bdc07550e0241da72af82c50d7 100644 (file)
@@ -67,7 +67,7 @@ const char kEnablePlugins[] = "enable-plugins";
 const char kGuestInstanceID[] = "guest-instance-id";
 
 // Script that will be loaded by guest WebContents before other scripts.
-const char kPreloadScript[] = "preload-script";
+const char kPreloadScript[] = "preload";
 
 // Web runtime features.
 const char kExperimentalFeatures[]       = "experimental-features";
index 5203ec8530dcec2dc84450e9d4fe3caf2849e595..69e76e98e15552430da6fb5fada625fb7a16b9dc 100644 (file)
@@ -31,7 +31,7 @@ for arg in process.argv
     require('web-frame').setName 'ATOM_SHELL_GUEST_WEB_VIEW'
   else if arg.indexOf('--node-integration=') == 0
     nodeIntegration = arg.substr arg.indexOf('=') + 1
-  else if arg.indexOf('--preload-script=') == 0
+  else if arg.indexOf('--preload=') == 0
     preloadScript = arg.substr arg.indexOf('=') + 1
 
 if location.protocol is 'chrome-devtools:'