diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 64af59668238..35ce46b590cc 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -820,9 +820,6 @@ This event can be used to configure `webPreferences` for the `webContents` of a `` before it's loaded, and provides the ability to set settings that can't be set via `` attributes. -**Note:** The specified `preload` script option will appear as `preloadURL` -(not `preload`) in the `webPreferences` object emitted with this event. - #### Event: 'did-attach-webview' Returns: diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index fd90e8b5d566..c2eab361cfd9 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -158,9 +158,6 @@ When the guest page doesn't have node integration this script will still have access to all Node APIs, but global objects injected by Node will be deleted after this script has finished executing. -**Note:** This option will appear as `preloadURL` (not `preload`) in -the `webPreferences` specified to the `will-attach-webview` event. - ### `httpreferrer` ```html diff --git a/docs/tutorial/security.md b/docs/tutorial/security.md index 688dda5a6896..d267a61a47d0 100644 --- a/docs/tutorial/security.md +++ b/docs/tutorial/security.md @@ -562,7 +562,6 @@ app.on('web-contents-created', (event, contents) => { contents.on('will-attach-webview', (event, webPreferences, params) => { // Strip away preload scripts if unused or verify their location is legitimate delete webPreferences.preload - delete webPreferences.preloadURL // Disable Node.js integration webPreferences.nodeIntegration = false diff --git a/lib/browser/guest-view-manager.ts b/lib/browser/guest-view-manager.ts index c973586e807d..c9c4585de28e 100644 --- a/lib/browser/guest-view-manager.ts +++ b/lib/browser/guest-view-manager.ts @@ -15,6 +15,7 @@ interface GuestInstance { const webViewManager = process._linkedBinding('electron_browser_web_view_manager'); const eventBinding = process._linkedBinding('electron_browser_event'); +const netBinding = process._linkedBinding('electron_browser_net'); const supportedWebViewEvents = Object.keys(webViewEvents); @@ -49,7 +50,7 @@ function makeWebPreferences (embedder: Electron.WebContents, params: Record #include "gin/handle.h" +#include "net/base/filename_util.h" #include "net/base/network_change_notifier.h" #include "net/http/http_util.h" #include "services/network/public/cpp/features.h" #include "shell/browser/api/electron_api_url_loader.h" +#include "shell/common/gin_converters/file_path_converter.h" +#include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/error_thrower.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" @@ -28,6 +32,14 @@ bool IsValidHeaderValue(std::string header_value) { return net::HttpUtil::IsValidHeaderValue(header_value); } +base::FilePath FileURLToFilePath(v8::Isolate* isolate, const GURL& url) { + base::FilePath path; + if (!net::FileURLToFilePath(url, &path)) + gin_helper::ErrorThrower(isolate).ThrowError( + "Failed to convert URL to file path"); + return path; +} + using electron::api::SimpleURLLoaderWrapper; void Initialize(v8::Local exports, @@ -41,6 +53,7 @@ void Initialize(v8::Local exports, dict.SetMethod("isValidHeaderName", &IsValidHeaderName); dict.SetMethod("isValidHeaderValue", &IsValidHeaderValue); dict.SetMethod("createURLLoader", &SimpleURLLoaderWrapper::Create); + dict.SetMethod("fileURLToFilePath", &FileURLToFilePath); } } // namespace diff --git a/shell/browser/web_contents_preferences.cc b/shell/browser/web_contents_preferences.cc index e54772a0bfce..c7bdcbf36224 100644 --- a/shell/browser/web_contents_preferences.cc +++ b/shell/browser/web_contents_preferences.cc @@ -258,15 +258,6 @@ void WebContentsPreferences::Merge( } else { LOG(ERROR) << "preload script must have absolute path."; } - } else if (web_preferences.Get(options::kPreloadURL, &preload_url_str)) { - // Translate to file path if there is "preload-url" option. - base::FilePath preload; - GURL preload_url(preload_url_str); - if (net::FileURLToFilePath(preload_url, &preload)) { - preload_path_ = preload; - } else { - LOG(ERROR) << "preload url must be file:// protocol."; - } } std::string type; diff --git a/shell/common/options_switches.cc b/shell/common/options_switches.cc index 5ae559c437eb..94ffb637ff12 100644 --- a/shell/common/options_switches.cc +++ b/shell/common/options_switches.cc @@ -120,9 +120,6 @@ const char kPreloadScript[] = "preload"; const char kPreloadScripts[] = "preloadScripts"; -// Like --preload, but the passed argument is an URL. -const char kPreloadURL[] = "preloadURL"; - // Enable the node integration. const char kNodeIntegration[] = "nodeIntegration"; diff --git a/shell/common/options_switches.h b/shell/common/options_switches.h index cfe8a4a191cc..d8f481906791 100644 --- a/shell/common/options_switches.h +++ b/shell/common/options_switches.h @@ -66,7 +66,6 @@ extern const char kOverlayHeight[]; extern const char kZoomFactor[]; extern const char kPreloadScript[]; extern const char kPreloadScripts[]; -extern const char kPreloadURL[]; extern const char kNodeIntegration[]; extern const char kContextIsolation[]; extern const char kExperimentalFeatures[]; diff --git a/spec/static/main.js b/spec/static/main.js index 28ec06f524cc..675c90fb42a9 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -155,7 +155,6 @@ ipcMain.on('disable-preload-on-next-will-attach-webview', (event, id) => { event.sender.once('will-attach-webview', (event, webPreferences, params) => { params.src = `file://${path.join(__dirname, '..', 'fixtures', 'pages', 'webview-stripped-preload.html')}`; delete webPreferences.preload; - delete webPreferences.preloadURL; }); }); diff --git a/typings/internal-ambient.d.ts b/typings/internal-ambient.d.ts index 92d707c8edac..c3b73935a299 100644 --- a/typings/internal-ambient.d.ts +++ b/typings/internal-ambient.d.ts @@ -222,6 +222,7 @@ declare namespace NodeJS { isOnline(): boolean; isValidHeaderName: (headerName: string) => boolean; isValidHeaderValue: (headerValue: string) => boolean; + fileURLToFilePath: (url: string) => string; Net: any; net: any; createURLLoader(options: CreateURLLoaderOptions): URLLoader; diff --git a/typings/internal-electron.d.ts b/typings/internal-electron.d.ts index a0d645440652..49568925fa80 100644 --- a/typings/internal-electron.d.ts +++ b/typings/internal-electron.d.ts @@ -97,7 +97,6 @@ declare namespace Electron { interface WebPreferences { disablePopups?: boolean; - preloadURL?: string; embedder?: Electron.WebContents; type?: 'backgroundPage' | 'window' | 'browserView' | 'remote' | 'webview' | 'offscreen'; }