chore: remove awkward semi-documented preloadURL WebPreference (#33228)

This commit is contained in:
Jeremy Rose 2022-03-16 16:23:41 -07:00 коммит произвёл GitHub
Родитель e904486076
Коммит 4342b7ff55
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 16 добавлений и 23 удалений

Просмотреть файл

@ -820,9 +820,6 @@ This event can be used to configure `webPreferences` for the `webContents`
of a `<webview>` before it's loaded, and provides the ability to set settings
that can't be set via `<webview>` 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:

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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<stri
};
if (params.preload) {
webPreferences.preloadURL = params.preload;
webPreferences.preload = netBinding.fileURLToFilePath(params.preload);
}
// Security options that guest will always inherit from embedder

Просмотреть файл

@ -5,11 +5,15 @@
#include <string>
#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<v8::Object> exports,
@ -41,6 +53,7 @@ void Initialize(v8::Local<v8::Object> exports,
dict.SetMethod("isValidHeaderName", &IsValidHeaderName);
dict.SetMethod("isValidHeaderValue", &IsValidHeaderValue);
dict.SetMethod("createURLLoader", &SimpleURLLoaderWrapper::Create);
dict.SetMethod("fileURLToFilePath", &FileURLToFilePath);
}
} // namespace

Просмотреть файл

@ -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;

Просмотреть файл

@ -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";

Просмотреть файл

@ -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[];

Просмотреть файл

@ -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;
});
});

1
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;

1
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';
}