mirror of
https://github.com/electron/electron.git
synced 2026-02-26 03:01:17 -05:00
Compare commits
94 Commits
v12.0.0-be
...
v12.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
258f245e74 | ||
|
|
d0fdf5a374 | ||
|
|
3d82985602 | ||
|
|
93342d9302 | ||
|
|
50094b3a25 | ||
|
|
13284a3a57 | ||
|
|
5da6ee1fc1 | ||
|
|
4de3e451ac | ||
|
|
d27046272e | ||
|
|
9ce7c51247 | ||
|
|
840ac755b8 | ||
|
|
8115520d2a | ||
|
|
92e3b1305c | ||
|
|
93dab148c8 | ||
|
|
e100c22a26 | ||
|
|
4efeaa090a | ||
|
|
93c6c8c103 | ||
|
|
df9a01bb53 | ||
|
|
5c10eb4c26 | ||
|
|
f836ef0f47 | ||
|
|
274f6f75b5 | ||
|
|
2f42c2c76e | ||
|
|
1cf09e7aab | ||
|
|
06580db96d | ||
|
|
337e691089 | ||
|
|
731fe11db6 | ||
|
|
9e4f6bf8b4 | ||
|
|
59328b6f8f | ||
|
|
facc12eafa | ||
|
|
d9ce3ac776 | ||
|
|
6314637ae9 | ||
|
|
00d5c6ad53 | ||
|
|
7ac905dd77 | ||
|
|
d99ab3fb41 | ||
|
|
80ca7be524 | ||
|
|
deb667054c | ||
|
|
22f6abc4f5 | ||
|
|
c023c480bb | ||
|
|
dd24a4b0f6 | ||
|
|
bb612d7a05 | ||
|
|
cf69f9a4ce | ||
|
|
d4eed90145 | ||
|
|
8f05f313ce | ||
|
|
592a1aed0f | ||
|
|
fc2762c66a | ||
|
|
9f48ef1c78 | ||
|
|
574b705f22 | ||
|
|
17c970b6a2 | ||
|
|
1f4ffe4f68 | ||
|
|
d121bcbbb5 | ||
|
|
d2a342c74d | ||
|
|
c19e1ee30e | ||
|
|
508075f870 | ||
|
|
c34103d912 | ||
|
|
7487fe91fe | ||
|
|
7b21bc543b | ||
|
|
6c09c2c644 | ||
|
|
44eb30fa71 | ||
|
|
c528ed5a8d | ||
|
|
15f29aa971 | ||
|
|
312682d655 | ||
|
|
8397716dab | ||
|
|
23075f8620 | ||
|
|
90d94e468e | ||
|
|
5cc6d79d17 | ||
|
|
8f825d35f7 | ||
|
|
05972074e3 | ||
|
|
21ac61270a | ||
|
|
f0500fae4c | ||
|
|
5f2f4182c4 | ||
|
|
ac8db00a70 | ||
|
|
ab5d0f4c8b | ||
|
|
203116867b | ||
|
|
67a67270f5 | ||
|
|
83a3eb64ec | ||
|
|
8b1260184a | ||
|
|
f13ddca55f | ||
|
|
f1c4265072 | ||
|
|
f5de5e9131 | ||
|
|
a73949315c | ||
|
|
189f7e0e4e | ||
|
|
2950f03e83 | ||
|
|
ca417e435c | ||
|
|
5237108396 | ||
|
|
3ae63c9a06 | ||
|
|
8828382b23 | ||
|
|
0e714d19c5 | ||
|
|
aec412e35d | ||
|
|
4b2d791212 | ||
|
|
fd629c16cb | ||
|
|
007c960f3c | ||
|
|
b2636e171a | ||
|
|
e7e1801443 | ||
|
|
0baf9997ad |
@@ -308,9 +308,10 @@ step-setup-goma-for-build: &step-setup-goma-for-build
|
||||
npm install
|
||||
mkdir third_party
|
||||
node -e "require('./src/utils/goma.js').downloadAndPrepare({ gomaOneForAll: true })"
|
||||
node -e "require('./src/utils/goma.js').ensure()"
|
||||
third_party/goma/goma_ctl.py ensure_start
|
||||
echo 'export GN_GOMA_FILE='`node -e "console.log(require('./src/utils/goma.js').gnFilePath)"` >> $BASH_ENV
|
||||
echo 'export LOCAL_GOMA_DIR='`node -e "console.log(require('./src/utils/goma.js').dir)"` >> $BASH_ENV
|
||||
echo 'export GOMA_FALLBACK_ON_AUTH_FAILURE=true' >> $BASH_ENV
|
||||
cd ..
|
||||
|
||||
step-restore-brew-cache: &step-restore-brew-cache
|
||||
|
||||
@@ -4,4 +4,3 @@
|
||||
APPVEYOR_CLOUD_TOKEN=
|
||||
CIRCLE_TOKEN=
|
||||
ELECTRON_GITHUB_TOKEN=
|
||||
VSTS_TOKEN=
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -68,4 +68,6 @@ ts-gen
|
||||
.depshash-target
|
||||
|
||||
# Used to accelerate builds after sync
|
||||
patches/mtime-cache.json
|
||||
patches/mtime-cache.json
|
||||
|
||||
spec/fixtures/logo.png
|
||||
2
DEPS
2
DEPS
@@ -14,7 +14,7 @@ gclient_gn_args = [
|
||||
|
||||
vars = {
|
||||
'chromium_version':
|
||||
'89.0.4389.58',
|
||||
'89.0.4389.128',
|
||||
'node_version':
|
||||
'v14.16.0',
|
||||
'nan_version':
|
||||
|
||||
@@ -1 +1 @@
|
||||
12.0.0-beta.31
|
||||
12.0.5
|
||||
@@ -36,6 +36,7 @@ environment:
|
||||
ELECTRON_ENABLE_STACK_DUMPING: 1
|
||||
MOCHA_REPORTER: mocha-multi-reporters
|
||||
MOCHA_MULTI_REPORTERS: mocha-appveyor-reporter, tap
|
||||
GOMA_FALLBACK_ON_AUTH_FAILURE: true
|
||||
notifications:
|
||||
- provider: Webhook
|
||||
url: https://electron-mission-control.herokuapp.com/rest/appveyor-hook
|
||||
|
||||
@@ -93,6 +93,6 @@ steps:
|
||||
condition: always()
|
||||
|
||||
- powershell: |
|
||||
Remove-Item -path $env:APPDATA/Electron* -Recurse -Force
|
||||
Remove-Item -path $env:APPDATA/Electron* -Recurse -Force -ErrorAction Ignore
|
||||
displayName: 'Delete user app data directories'
|
||||
condition: always()
|
||||
|
||||
@@ -163,7 +163,7 @@ if ((globalThis.process || binding.process).argv.includes("--profile-electron-in
|
||||
setImmediate: false
|
||||
},
|
||||
optimization: {
|
||||
minimize: true,
|
||||
minimize: env.mode === 'production',
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
terserOptions: {
|
||||
|
||||
@@ -22,6 +22,11 @@ template("webpack_build") {
|
||||
"//electron/typings/internal-electron.d.ts",
|
||||
] + invoker.inputs
|
||||
|
||||
mode = "development"
|
||||
if (is_official_build) {
|
||||
mode = "production"
|
||||
}
|
||||
|
||||
args = [
|
||||
"--config",
|
||||
rebase_path(invoker.config_file),
|
||||
@@ -29,6 +34,7 @@ template("webpack_build") {
|
||||
"--output-path=" + rebase_path(get_path_info(invoker.out_file, "dir")),
|
||||
"--env.buildflags=" +
|
||||
rebase_path("$target_gen_dir/buildflags/buildflags.h"),
|
||||
"--env.mode=" + mode,
|
||||
]
|
||||
deps += [ "buildflags" ]
|
||||
|
||||
|
||||
@@ -91,11 +91,6 @@ These individual tutorials expand on topics discussed in the guide above.
|
||||
* Electron Releases & Developer Feedback
|
||||
* [Versioning Policy](tutorial/electron-versioning.md)
|
||||
* [Release Timelines](tutorial/electron-timelines.md)
|
||||
* [Packaging App Source Code with asar](tutorial/application-packaging.md)
|
||||
* [Generating asar Archives](tutorial/application-packaging.md#generating-asar-archives)
|
||||
* [Using asar Archives](tutorial/application-packaging.md#using-asar-archives)
|
||||
* [Limitations](tutorial/application-packaging.md#limitations-of-the-node-api)
|
||||
* [Adding Unpacked Files to asar Archives](tutorial/application-packaging.md#adding-unpacked-files-to-asar-archives)
|
||||
* [Testing Widevine CDM](tutorial/testing-widevine-cdm.md)
|
||||
|
||||
---
|
||||
@@ -149,15 +144,14 @@ These individual tutorials expand on topics discussed in the guide above.
|
||||
### Modules for the Renderer Process (Web Page):
|
||||
|
||||
* [contextBridge](api/context-bridge.md)
|
||||
* [desktopCapturer](api/desktop-capturer.md)
|
||||
* [ipcRenderer](api/ipc-renderer.md)
|
||||
* [remote](api/remote.md)
|
||||
* [webFrame](api/web-frame.md)
|
||||
|
||||
### Modules for Both Processes:
|
||||
|
||||
* [clipboard](api/clipboard.md)
|
||||
* [crashReporter](api/crash-reporter.md)
|
||||
* [desktopCapturer](api/desktop-capturer.md)
|
||||
* [nativeImage](api/native-image.md)
|
||||
* [shell](api/shell.md)
|
||||
|
||||
|
||||
@@ -929,6 +929,10 @@ re-add a removed item to a custom category earlier than that will result in the
|
||||
entire custom category being omitted from the Jump List. The list of removed
|
||||
items can be obtained using `app.getJumpListSettings()`.
|
||||
|
||||
**Note:** The maximum length of a Jump List item's `description` property is
|
||||
260 characters. Beyond this limit, the item will not be added to the Jump
|
||||
List, nor will it be displayed.
|
||||
|
||||
Here's a very simple example of creating a custom Jump List:
|
||||
|
||||
```javascript
|
||||
|
||||
@@ -265,7 +265,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||
be the absolute file path to the script.
|
||||
When node integration is turned off, the preload script can reintroduce
|
||||
Node global symbols back to the global scope. See example
|
||||
[here](process.md#event-loaded).
|
||||
[here](context-bridge.md#exposing-node-global-symbols).
|
||||
* `sandbox` Boolean (optional) - If set, this will sandbox the renderer
|
||||
associated with the window, making it compatible with the Chromium
|
||||
OS-level sandbox and disabling the Node.js engine. This is not the same as
|
||||
@@ -337,7 +337,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||
more details.
|
||||
* `contextIsolation` Boolean (optional) - Whether to run Electron APIs and
|
||||
the specified `preload` script in a separate JavaScript context. Defaults
|
||||
to `false`. The context that the `preload` script runs in will only have
|
||||
to `true`. The context that the `preload` script runs in will only have
|
||||
access to its own dedicated `document` and `window` globals, as well as
|
||||
its own set of JavaScript builtins (`Array`, `Object`, `JSON`, etc.),
|
||||
which are all invisible to the loaded content. The Electron API will only
|
||||
@@ -349,8 +349,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||
context in the dev tools by selecting the 'Electron Isolated Context'
|
||||
entry in the combo box at the top of the Console tab.
|
||||
* `worldSafeExecuteJavaScript` Boolean (optional) - If true, values returned from `webFrame.executeJavaScript` will be sanitized to ensure JS values
|
||||
can't unsafely cross between worlds when using `contextIsolation`. The default
|
||||
is `false`. In Electron 12, the default will be changed to `true`. _Deprecated_
|
||||
can't unsafely cross between worlds when using `contextIsolation`. Defaults to `true`. _Deprecated_
|
||||
* `nativeWindowOpen` Boolean (optional) - Whether to use native
|
||||
`window.open()`. Defaults to `false`. Child windows will always have node
|
||||
integration disabled unless `nodeIntegrationInSubFrames` is true. **Note:** This option is currently
|
||||
@@ -1405,6 +1404,8 @@ The native type of the handle is `HWND` on Windows, `NSView*` on macOS, and
|
||||
|
||||
* `message` Integer
|
||||
* `callback` Function
|
||||
* `wParam` any - The `wParam` provided to the WndProc
|
||||
* `lParam` any - The `lParam` provided to the WndProc
|
||||
|
||||
Hooks a windows message. The `callback` is called when
|
||||
the message is received in the WndProc.
|
||||
@@ -1457,7 +1458,7 @@ Returns `Boolean` - Whether the window's document has been edited.
|
||||
|
||||
Returns `Promise<NativeImage>` - Resolves with a [NativeImage](native-image.md)
|
||||
|
||||
Captures a snapshot of the page within `rect`. Omitting `rect` will capture the whole visible page.
|
||||
Captures a snapshot of the page within `rect`. Omitting `rect` will capture the whole visible page. If the page is not visible, `rect` may be empty.
|
||||
|
||||
#### `win.loadURL(url[, options])`
|
||||
|
||||
|
||||
@@ -80,6 +80,12 @@ This switch can not be used in `app.commandLine.appendSwitch` since it is parsed
|
||||
earlier than user's app is loaded, but you can set the `ELECTRON_ENABLE_LOGGING`
|
||||
environment variable to achieve the same effect.
|
||||
|
||||
## --force-fieldtrials=`trials`
|
||||
|
||||
Field trials to be forcefully enabled or disabled.
|
||||
|
||||
For example: `WebRTC-Audio-Red-For-Opus/Enabled/`
|
||||
|
||||
### --host-rules=`rules`
|
||||
|
||||
A comma-separated list of `rules` that control how hostnames are mapped.
|
||||
|
||||
@@ -33,7 +33,7 @@ page you load in your renderer executes code in this world.
|
||||
|
||||
### Isolated World
|
||||
|
||||
When `contextIsolation` is enabled in your `webPreferences`, your `preload` scripts run in an
|
||||
When `contextIsolation` is enabled in your `webPreferences` (this is the default behavior since Electron 12.0.0), your `preload` scripts run in an
|
||||
"Isolated World". You can read more about context isolation and what it affects in the
|
||||
[security](../tutorial/security.md#3-enable-context-isolation-for-remote-content) docs.
|
||||
|
||||
@@ -109,3 +109,22 @@ has been included below for completeness:
|
||||
| `Symbol` | N/A | ❌ | ❌ | Symbols cannot be copied across contexts so they are dropped |
|
||||
|
||||
If the type you care about is not in the above table, it is probably not supported.
|
||||
|
||||
### Exposing Node Global Symbols
|
||||
|
||||
The `contextBridge` can be used by the preload script to give your renderer access to Node APIs.
|
||||
The table of supported types described above also applies to Node APIs that you expose through `contextBridge`.
|
||||
Please note that many Node APIs grant access to local system resources.
|
||||
Be very cautious about which globals and APIs you expose to untrusted remote content.
|
||||
|
||||
```javascript
|
||||
const { contextBridge } = require('electron')
|
||||
const crypto = require('crypto')
|
||||
contextBridge.exposeInMainWorld('nodeCrypto', {
|
||||
sha256sum (data) {
|
||||
const hash = crypto.createHash('sha256')
|
||||
hash.update(data)
|
||||
return hash.digest('hex')
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
@@ -45,6 +45,8 @@ The following events are available on instances of `Cookies`:
|
||||
|
||||
#### Event: 'changed'
|
||||
|
||||
Returns:
|
||||
|
||||
* `event` Event
|
||||
* `cookie` [Cookie](structures/cookie.md) - The cookie that was changed.
|
||||
* `cause` String - The cause of the change with one of the following values:
|
||||
|
||||
@@ -82,8 +82,11 @@ win.show()
|
||||
* The `blur` filter only applies to the web page, so there is no way to apply
|
||||
blur effect to the content below the window (i.e. other applications open on
|
||||
the user's system).
|
||||
* On Windows operating systems, transparent windows will not work when DWM is
|
||||
* The window will not be transparent when DevTools is opened.
|
||||
* On Windows operating systems,
|
||||
* transparent windows will not work when DWM is
|
||||
disabled.
|
||||
* transparent windows can not be maximized using the Windows system menu or by double clicking the title bar. The reasoning behind this can be seen on [this pull request](https://github.com/electron/electron/pull/28207).
|
||||
* On Linux, users have to put `--enable-transparent-visuals --disable-gpu` in
|
||||
the command line to disable GPU and allow ARGB to make transparent window,
|
||||
this is caused by an upstream bug that [alpha channel doesn't work on some
|
||||
|
||||
@@ -42,19 +42,6 @@ In sandboxed renderers the `process` object contains only a subset of the APIs:
|
||||
Emitted when Electron has loaded its internal initialization script and is
|
||||
beginning to load the web page or the main script.
|
||||
|
||||
It can be used by the preload script to add removed Node global symbols back to
|
||||
the global scope when node integration is turned off:
|
||||
|
||||
```javascript
|
||||
// preload.js
|
||||
const _setImmediate = setImmediate
|
||||
const _clearImmediate = clearImmediate
|
||||
process.once('loaded', () => {
|
||||
global.setImmediate = _setImmediate
|
||||
global.clearImmediate = _clearImmediate
|
||||
})
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
### `process.defaultApp` _Readonly_
|
||||
|
||||
@@ -19,3 +19,7 @@
|
||||
property set then its `type` is assumed to be `tasks`. If the `name` property
|
||||
is set but the `type` property is omitted then the `type` is assumed to be
|
||||
`custom`.
|
||||
|
||||
**Note:** The maximum length of a Jump List item's `description` property is
|
||||
260 characters. Beyond this limit, the item will not be added to the Jump
|
||||
List, nor will it be displayed.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* `title` String (optional) - The text to be displayed for the item in the Jump List.
|
||||
Should only be set if `type` is `task`.
|
||||
* `description` String (optional) - Description of the task (displayed in a tooltip).
|
||||
Should only be set if `type` is `task`.
|
||||
Should only be set if `type` is `task`. Maximum length 260 characters.
|
||||
* `iconPath` String (optional) - The absolute path to an icon to be displayed in a
|
||||
Jump List, which can be an arbitrary resource file that contains an icon
|
||||
(e.g. `.ico`, `.exe`, `.dll`). You can usually specify `process.execPath` to
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# UploadFile Object
|
||||
|
||||
* `type` String - `file`.
|
||||
* `type` 'file' - `file`.
|
||||
* `filePath` String - Path of file to be uploaded.
|
||||
* `offset` Integer - Defaults to `0`.
|
||||
* `length` Integer - Number of bytes to read from `offset`.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# UploadRawData Object
|
||||
|
||||
* `type` String - `rawData`.
|
||||
* `type` 'rawData' - `rawData`.
|
||||
* `bytes` Buffer - Data to be uploaded.
|
||||
|
||||
@@ -130,6 +130,8 @@ This is necessary for events such as `NSUserDefaultsDidChangeNotification`.
|
||||
* `userInfo` Record<String, unknown>
|
||||
* `object` String
|
||||
|
||||
Returns `Number` - The ID of this subscription
|
||||
|
||||
Same as `subscribeNotification`, but uses `NSWorkspace.sharedWorkspace.notificationCenter`.
|
||||
This is necessary for events such as `NSWorkspaceDidActivateApplicationNotification`.
|
||||
|
||||
|
||||
@@ -1169,6 +1169,7 @@ Ignore application menu shortcuts while this web contents is focused.
|
||||
* `url` String - The _resolved_ version of the URL passed to `window.open()`. e.g. opening a window with `window.open('foo')` will yield something like `https://the-origin/the/current/path/foo`.
|
||||
* `frameName` String - Name of the window provided in `window.open()`
|
||||
* `features` String - Comma separated list of window features provided to `window.open()`.
|
||||
|
||||
Returns `{action: 'deny'} | {action: 'allow', overrideBrowserWindowOptions?: BrowserWindowConstructorOptions}` - `deny` cancels the creation of the new
|
||||
window. `allow` will allow the new window to be created. Specifying `overrideBrowserWindowOptions` allows customization of the created window.
|
||||
Returning an unrecognized value such as a null, undefined, or an object
|
||||
|
||||
@@ -86,17 +86,6 @@ In the browser window some HTML APIs like `requestFullScreen` can only be
|
||||
invoked by a gesture from the user. Setting `userGesture` to `true` will remove
|
||||
this limitation.
|
||||
|
||||
#### `frame.executeJavaScriptInIsolatedWorld(worldId, code[, userGesture])`
|
||||
|
||||
* `worldId` Integer - The ID of the world to run the javascript in, `0` is the default world, `999` is the world used by Electron's `contextIsolation` feature. You can provide any integer here.
|
||||
* `code` String
|
||||
* `userGesture` Boolean (optional) - Default is `false`.
|
||||
|
||||
Returns `Promise<unknown>` - A promise that resolves with the result of the executed
|
||||
code or is rejected if execution throws or results in a rejected promise.
|
||||
|
||||
Works like `executeJavaScript` but evaluates `scripts` in an isolated context.
|
||||
|
||||
#### `frame.reload()`
|
||||
|
||||
Returns `boolean` - Whether the reload was initiated successfully. Only results in `false` when the frame has no history.
|
||||
|
||||
@@ -83,9 +83,9 @@ const mainWindow = new BrowserWindow()
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (url.startsWith('https://github.com/')) {
|
||||
return true
|
||||
return { action: 'allow' }
|
||||
}
|
||||
return false
|
||||
return { action: 'deny' }
|
||||
})
|
||||
|
||||
mainWindow.webContents.on('did-create-window', (childWindow) => {
|
||||
|
||||
@@ -6,14 +6,20 @@ Breaking changes will be documented here, and deprecation warnings added to JS c
|
||||
|
||||
This document uses the following convention to categorize breaking changes:
|
||||
|
||||
- **API Changed:** An API was changed in such a way that code that has not been updated is guaranteed to throw an exception.
|
||||
- **Behavior Changed:** The behavior of Electron has changed, but not in such a way that an exception will necessarily be thrown.
|
||||
- **Default Changed:** Code depending on the old default may break, not necessarily throwing an exception. The old behavior can be restored by explicitly specifying the value.
|
||||
- **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release.
|
||||
- **Removed:** An API or feature was removed, and is no longer supported by Electron.
|
||||
* **API Changed:** An API was changed in such a way that code that has not been updated is guaranteed to throw an exception.
|
||||
* **Behavior Changed:** The behavior of Electron has changed, but not in such a way that an exception will necessarily be thrown.
|
||||
* **Default Changed:** Code depending on the old default may break, not necessarily throwing an exception. The old behavior can be restored by explicitly specifying the value.
|
||||
* **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release.
|
||||
* **Removed:** An API or feature was removed, and is no longer supported by Electron.
|
||||
|
||||
## Planned Breaking API Changes (14.0)
|
||||
|
||||
### API Changed: `window.(open)`
|
||||
|
||||
The optional parameter `frameName` will no longer set the title of the window. This now follows the specification described by the [native documentation](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#parameters) under the corresponding parameter `windowName`.
|
||||
|
||||
If you were using this parameter to set the title of a window, you can instead use [win.setTitle(title)](https://www.electronjs.org/docs/api/browser-window#winsettitletitle).
|
||||
|
||||
### Removed: `worldSafeExecuteJavaScript`
|
||||
|
||||
In Electron 14, `worldSafeExecuteJavaScript` will be removed. There is no alternative, please
|
||||
@@ -24,6 +30,28 @@ You will be affected by this change if you use either `webFrame.executeJavaScrip
|
||||
|
||||
## Planned Breaking API Changes (13.0)
|
||||
|
||||
### API Changed: `session.setPermissionCheckHandler(handler)`
|
||||
|
||||
The `handler` methods first parameter was previously always a `webContents`, it can now sometimes be `null`. You should use the `requestingOrigin`, `embeddingOrigin` and `securityOrigin` properties to respond to the permission check correctly. As the `webContents` can be `null` it can no longer be relied on.
|
||||
|
||||
```js
|
||||
// Old code
|
||||
session.setPermissionCheckHandler((webContents, permission) => {
|
||||
if (webContents.getURL().startsWith('https://google.com/') && permission === 'notification') {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
// Replace with
|
||||
session.setPermissionCheckHandler((webContents, permission, requestingOrigin) => {
|
||||
if (new URL(requestingOrigin).hostname === 'google.com' && permission === 'notification') {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
```
|
||||
|
||||
### Removed: `shell.moveItemToTrash()`
|
||||
|
||||
The deprecated synchronous `shell.moveItemToTrash()` API has been removed. Use
|
||||
@@ -36,6 +64,78 @@ shell.moveItemToTrash(path)
|
||||
shell.trashItem(path).then(/* ... */)
|
||||
```
|
||||
|
||||
### Removed: `BrowserWindow` extension APIs
|
||||
|
||||
The deprecated extension APIs have been removed:
|
||||
|
||||
* `BrowserWindow.addExtension(path)`
|
||||
* `BrowserWindow.addDevToolsExtension(path)`
|
||||
* `BrowserWindow.removeExtension(name)`
|
||||
* `BrowserWindow.removeDevToolsExtension(name)`
|
||||
* `BrowserWindow.getExtensions()`
|
||||
* `BrowserWindow.getDevToolsExtensions()`
|
||||
|
||||
Use the session APIs instead:
|
||||
|
||||
* `ses.loadExtension(path)`
|
||||
* `ses.removeExtension(extension_id)`
|
||||
* `ses.getAllExtensions()`
|
||||
|
||||
```js
|
||||
// Removed in Electron 13
|
||||
BrowserWindow.addExtension(path)
|
||||
BrowserWindow.addDevToolsExtension(path)
|
||||
// Replace with
|
||||
session.defaultSession.loadExtension(path)
|
||||
```
|
||||
|
||||
```js
|
||||
// Removed in Electron 13
|
||||
BrowserWindow.removeExtension(name)
|
||||
BrowserWindow.removeDevToolsExtension(name)
|
||||
// Replace with
|
||||
session.defaultSession.removeExtension(extension_id)
|
||||
```
|
||||
|
||||
```js
|
||||
// Removed in Electron 13
|
||||
BrowserWindow.getExtensions()
|
||||
BrowserWindow.getDevToolsExtensions()
|
||||
// Replace with
|
||||
session.defaultSession.getAllExtensions()
|
||||
```
|
||||
|
||||
### Removed: methods in `systemPreferences`
|
||||
|
||||
The following `systemPreferences` methods have been deprecated:
|
||||
|
||||
* `systemPreferences.isDarkMode()`
|
||||
* `systemPreferences.isInvertedColorScheme()`
|
||||
* `systemPreferences.isHighContrastColorScheme()`
|
||||
|
||||
Use the following `nativeTheme` properties instead:
|
||||
|
||||
* `nativeTheme.shouldUseDarkColors`
|
||||
* `nativeTheme.shouldUseInvertedColorScheme`
|
||||
* `nativeTheme.shouldUseHighContrastColors`
|
||||
|
||||
```js
|
||||
// Removed in Electron 13
|
||||
systemPreferences.isDarkMode()
|
||||
// Replace with
|
||||
nativeTheme.shouldUseDarkColors
|
||||
|
||||
// Removed in Electron 13
|
||||
systemPreferences.isInvertedColorScheme()
|
||||
// Replace with
|
||||
nativeTheme.shouldUseInvertedColorScheme
|
||||
|
||||
// Removed in Electron 13
|
||||
systemPreferences.isHighContrastColorScheme()
|
||||
// Replace with
|
||||
nativeTheme.shouldUseHighContrastColors
|
||||
```
|
||||
|
||||
## Planned Breaking API Changes (12.0)
|
||||
|
||||
### Removed: Pepper Flash support
|
||||
@@ -60,6 +160,9 @@ the previous behavior, `contextIsolation: false` must be specified in WebPrefere
|
||||
|
||||
We [recommend having contextIsolation enabled](https://github.com/electron/electron/blob/master/docs/tutorial/security.md#3-enable-context-isolation-for-remote-content) for the security of your application.
|
||||
|
||||
Another implication is that `require()` cannot be used in the renderer process unless
|
||||
`nodeIntegration` is `true` and `contextIsolation` is `false`.
|
||||
|
||||
For more details see: https://github.com/electron/electron/issues/23506
|
||||
|
||||
### Removed: `crashReporter.getCrashesDirectory()`
|
||||
@@ -79,12 +182,12 @@ app.getPath('crashDumps')
|
||||
The following `crashReporter` methods are no longer available in the renderer
|
||||
process:
|
||||
|
||||
- `crashReporter.start`
|
||||
- `crashReporter.getLastCrashReport`
|
||||
- `crashReporter.getUploadedReports`
|
||||
- `crashReporter.getUploadToServer`
|
||||
- `crashReporter.setUploadToServer`
|
||||
- `crashReporter.getCrashesDirectory`
|
||||
* `crashReporter.start`
|
||||
* `crashReporter.getLastCrashReport`
|
||||
* `crashReporter.getUploadedReports`
|
||||
* `crashReporter.getUploadToServer`
|
||||
* `crashReporter.setUploadToServer`
|
||||
* `crashReporter.getCrashesDirectory`
|
||||
|
||||
They should be called only from the main process.
|
||||
|
||||
@@ -135,6 +238,7 @@ shell.trashItem(path).then(/* ... */)
|
||||
## Planned Breaking API Changes (11.0)
|
||||
|
||||
### Removed: `BrowserView.{destroy, fromId, fromWebContents, getAllViews}` and `id` property of `BrowserView`
|
||||
|
||||
The experimental APIs `BrowserView.{destroy, fromId, fromWebContents, getAllViews}`
|
||||
have now been removed. Additionally, the `id` property of `BrowserView`
|
||||
has also been removed.
|
||||
@@ -174,12 +278,12 @@ app.getPath('crashDumps')
|
||||
Calling the following `crashReporter` methods from the renderer process is
|
||||
deprecated:
|
||||
|
||||
- `crashReporter.start`
|
||||
- `crashReporter.getLastCrashReport`
|
||||
- `crashReporter.getUploadedReports`
|
||||
- `crashReporter.getUploadToServer`
|
||||
- `crashReporter.setUploadToServer`
|
||||
- `crashReporter.getCrashesDirectory`
|
||||
* `crashReporter.start`
|
||||
* `crashReporter.getLastCrashReport`
|
||||
* `crashReporter.getUploadedReports`
|
||||
* `crashReporter.getUploadToServer`
|
||||
* `crashReporter.setUploadToServer`
|
||||
* `crashReporter.getCrashesDirectory`
|
||||
|
||||
The only non-deprecated methods remaining in the `crashReporter` module in the
|
||||
renderer are `addExtraParameter`, `removeExtraParameter` and `getParameters`.
|
||||
@@ -221,6 +325,7 @@ We [recommend moving away from the remote
|
||||
module](https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31).
|
||||
|
||||
### `protocol.unregisterProtocol`
|
||||
|
||||
### `protocol.uninterceptProtocol`
|
||||
|
||||
The APIs are now synchronous and the optional callback is no longer needed.
|
||||
@@ -233,14 +338,23 @@ protocol.unregisterProtocol(scheme)
|
||||
```
|
||||
|
||||
### `protocol.registerFileProtocol`
|
||||
|
||||
### `protocol.registerBufferProtocol`
|
||||
|
||||
### `protocol.registerStringProtocol`
|
||||
|
||||
### `protocol.registerHttpProtocol`
|
||||
|
||||
### `protocol.registerStreamProtocol`
|
||||
|
||||
### `protocol.interceptFileProtocol`
|
||||
|
||||
### `protocol.interceptStringProtocol`
|
||||
|
||||
### `protocol.interceptBufferProtocol`
|
||||
|
||||
### `protocol.interceptHttpProtocol`
|
||||
|
||||
### `protocol.interceptStreamProtocol`
|
||||
|
||||
The APIs are now synchronous and the optional callback is no longer needed.
|
||||
@@ -285,6 +399,7 @@ For more detailed information see [#18397](https://github.com/electron/electron/
|
||||
### Deprecated: `BrowserWindow` extension APIs
|
||||
|
||||
The following extension APIs have been deprecated:
|
||||
|
||||
* `BrowserWindow.addExtension(path)`
|
||||
* `BrowserWindow.addDevToolsExtension(path)`
|
||||
* `BrowserWindow.removeExtension(name)`
|
||||
@@ -293,6 +408,7 @@ The following extension APIs have been deprecated:
|
||||
* `BrowserWindow.getDevToolsExtensions()`
|
||||
|
||||
Use the session APIs instead:
|
||||
|
||||
* `ses.loadExtension(path)`
|
||||
* `ses.removeExtension(extension_id)`
|
||||
* `ses.getAllExtensions()`
|
||||
@@ -373,7 +489,7 @@ Clone Algorithm][SCA], the same algorithm used to serialize messages for
|
||||
`postMessage`. This brings about a 2x performance improvement for large
|
||||
messages, but also brings some breaking changes in behavior.
|
||||
|
||||
- Sending Functions, Promises, WeakMaps, WeakSets, or objects containing any
|
||||
* Sending Functions, Promises, WeakMaps, WeakSets, or objects containing any
|
||||
such values, over IPC will now throw an exception, instead of silently
|
||||
converting the functions to `undefined`.
|
||||
|
||||
@@ -387,21 +503,21 @@ ipcRenderer.send('channel', { value: 3, someFunction: () => {} })
|
||||
// => throws Error("() => {} could not be cloned.")
|
||||
```
|
||||
|
||||
- `NaN`, `Infinity` and `-Infinity` will now be correctly serialized, instead
|
||||
* `NaN`, `Infinity` and `-Infinity` will now be correctly serialized, instead
|
||||
of being converted to `null`.
|
||||
- Objects containing cyclic references will now be correctly serialized,
|
||||
* Objects containing cyclic references will now be correctly serialized,
|
||||
instead of being converted to `null`.
|
||||
- `Set`, `Map`, `Error` and `RegExp` values will be correctly serialized,
|
||||
* `Set`, `Map`, `Error` and `RegExp` values will be correctly serialized,
|
||||
instead of being converted to `{}`.
|
||||
- `BigInt` values will be correctly serialized, instead of being converted to
|
||||
* `BigInt` values will be correctly serialized, instead of being converted to
|
||||
`null`.
|
||||
- Sparse arrays will be serialized as such, instead of being converted to dense
|
||||
* Sparse arrays will be serialized as such, instead of being converted to dense
|
||||
arrays with `null`s.
|
||||
- `Date` objects will be transferred as `Date` objects, instead of being
|
||||
* `Date` objects will be transferred as `Date` objects, instead of being
|
||||
converted to their ISO string representation.
|
||||
- Typed Arrays (such as `Uint8Array`, `Uint16Array`, `Uint32Array` and so on)
|
||||
* Typed Arrays (such as `Uint8Array`, `Uint16Array`, `Uint32Array` and so on)
|
||||
will be transferred as such, instead of being converted to Node.js `Buffer`.
|
||||
- Node.js `Buffer` objects will be transferred as `Uint8Array`s. You can
|
||||
* Node.js `Buffer` objects will be transferred as `Uint8Array`s. You can
|
||||
convert a `Uint8Array` back to a Node.js `Buffer` by wrapping the underlying
|
||||
`ArrayBuffer`:
|
||||
|
||||
@@ -470,6 +586,7 @@ limits are now fixed at a minimum of 0.25 and a maximum of 5.0, as defined
|
||||
### Deprecated events in `systemPreferences`
|
||||
|
||||
The following `systemPreferences` events have been deprecated:
|
||||
|
||||
* `inverted-color-scheme-changed`
|
||||
* `high-contrast-color-scheme-changed`
|
||||
|
||||
@@ -487,11 +604,13 @@ nativeTheme.on('updated', () => { /* ... */ })
|
||||
### Deprecated: methods in `systemPreferences`
|
||||
|
||||
The following `systemPreferences` methods have been deprecated:
|
||||
|
||||
* `systemPreferences.isDarkMode()`
|
||||
* `systemPreferences.isInvertedColorScheme()`
|
||||
* `systemPreferences.isHighContrastColorScheme()`
|
||||
|
||||
Use the following `nativeTheme` properties instead:
|
||||
|
||||
* `nativeTheme.shouldUseDarkColors`
|
||||
* `nativeTheme.shouldUseInvertedColorScheme`
|
||||
* `nativeTheme.shouldUseHighContrastColors`
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# Build Instructions
|
||||
|
||||
Follow the guidelines below for building Electron.
|
||||
Follow the guidelines below for building **Electron itself**, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the [application distribution][application-distribution] guide.
|
||||
|
||||
[application-distribution]: ../tutorial/application-distribution.md
|
||||
|
||||
## Platform prerequisites
|
||||
|
||||
@@ -86,8 +88,6 @@ $ gclient sync -f
|
||||
```sh
|
||||
$ cd src
|
||||
$ export CHROMIUM_BUILDTOOLS_PATH=`pwd`/buildtools
|
||||
# this next line is needed only if building with sccache
|
||||
$ export GN_EXTRA_ARGS="${GN_EXTRA_ARGS} cc_wrapper=\"${PWD}/electron/external_binaries/sccache\""
|
||||
$ gn gen out/Testing --args="import(\"//electron/build/args/testing.gn\") $GN_EXTRA_ARGS"
|
||||
```
|
||||
|
||||
@@ -141,12 +141,6 @@ This will build all of what was previously 'libchromiumcontent' (i.e. the
|
||||
`content/` directory of `chromium` and its dependencies, incl. WebKit and V8),
|
||||
so it will take a while.
|
||||
|
||||
To speed up subsequent builds, you can use [sccache][sccache]. Add the GN arg
|
||||
`cc_wrapper = "sccache"` by running `gn args out/Testing` to bring up an
|
||||
editor and adding a line to the end of the file.
|
||||
|
||||
[sccache]: https://github.com/mozilla/sccache
|
||||
|
||||
The built executable will be under `./out/Testing`:
|
||||
|
||||
```sh
|
||||
@@ -189,7 +183,6 @@ Not all combinations of source and target CPU/OS are supported by Chromium.
|
||||
| Windows x64 | Windows x86 | Automatically tested |
|
||||
| Linux x64 | Linux x86 | Automatically tested |
|
||||
|
||||
|
||||
If you test other combinations and find them to work, please update this document :)
|
||||
|
||||
See the GN reference for allowable values of [`target_os`][target_os values]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# Build Instructions (Linux)
|
||||
|
||||
Follow the guidelines below for building Electron on Linux.
|
||||
Follow the guidelines below for building **Electron itself** on Linux, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the [application distribution][application-distribution] guide.
|
||||
|
||||
[application-distribution]: ../tutorial/application-distribution.md
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@@ -55,6 +57,15 @@ $ sudo dnf install clang dbus-devel gtk3-devel libnotify-devel \
|
||||
nss-devel python-dbusmock openjdk-8-jre
|
||||
```
|
||||
|
||||
On Arch Linux / Manjaro, install the following libraries:
|
||||
|
||||
```sh
|
||||
$ sudo pacman -Syu base-devel clang libdbus gtk2 libnotify \
|
||||
libgnome-keyring alsa-lib libcap libcups libxtst \
|
||||
libxss nss gcc-multilib curl gperf bison \
|
||||
python2 python-dbusmock jdk8-openjdk
|
||||
```
|
||||
|
||||
Other distributions may offer similar packages for installation via package
|
||||
managers such as pacman. Or one can compile from source code.
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# Build Instructions (macOS)
|
||||
|
||||
Follow the guidelines below for building Electron on macOS.
|
||||
Follow the guidelines below for building **Electron itself** on macOS, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the [application distribution][application-distribution] guide.
|
||||
|
||||
[application-distribution]: ../tutorial/application-distribution.md
|
||||
|
||||
## Prerequisites
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# Build Instructions (Windows)
|
||||
|
||||
Follow the guidelines below for building Electron on Windows.
|
||||
Follow the guidelines below for building **Electron itself** on Windows, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the [application distribution][application-distribution] guide.
|
||||
|
||||
[application-distribution]: ../tutorial/application-distribution.md
|
||||
|
||||
## Prerequisites
|
||||
|
||||
|
||||
@@ -66,11 +66,11 @@ formatted correctly.
|
||||
|
||||
Electron APIs uses the same capitalization scheme as Node.js:
|
||||
|
||||
- When the module itself is a class like `BrowserWindow`, use `PascalCase`.
|
||||
- When the module is a set of APIs, like `globalShortcut`, use `camelCase`.
|
||||
- When the API is a property of object, and it is complex enough to be in a
|
||||
* When the module itself is a class like `BrowserWindow`, use `PascalCase`.
|
||||
* When the module is a set of APIs, like `globalShortcut`, use `camelCase`.
|
||||
* When the API is a property of object, and it is complex enough to be in a
|
||||
separate chapter like `win.webContents`, use `mixedCase`.
|
||||
- For other non-module APIs, use natural titles, like `<webview> Tag` or
|
||||
* For other non-module APIs, use natural titles, like `<webview> Tag` or
|
||||
`Process Object`.
|
||||
|
||||
When creating a new API, it is preferred to use getters and setters instead of
|
||||
|
||||
@@ -33,8 +33,7 @@ contributing, and more. Please use the issue tracker for bugs only!
|
||||
To submit a bug report:
|
||||
|
||||
When opening a new issue in the [`electron/electron` issue tracker](https://github.com/electron/electron/issues/new/choose), users
|
||||
will be presented with [a template](https://github.com/electron/electron/blob/master/.github/ISSUE_TEMPLATE/Bug_report.md)
|
||||
that should be filled in.
|
||||
will be presented with a template that should be filled in.
|
||||
|
||||
If you believe that you have found a bug in Electron, please fill out the template
|
||||
to the best of your ability.
|
||||
|
||||
@@ -36,9 +36,9 @@ $ git fetch upstream
|
||||
Build steps and dependencies differ slightly depending on your operating system.
|
||||
See these detailed guides on building Electron locally:
|
||||
|
||||
* [Building on macOS](https://electronjs.org/docs/development/build-instructions-macos)
|
||||
* [Building on Linux](https://electronjs.org/docs/development/build-instructions-linux)
|
||||
* [Building on Windows](https://electronjs.org/docs/development/build-instructions-windows)
|
||||
* [Building on macOS](build-instructions-macos.md)
|
||||
* [Building on Linux](build-instructions-linux.md)
|
||||
* [Building on Windows](build-instructions-windows.md)
|
||||
|
||||
Once you've built the project locally, you're ready to start making changes!
|
||||
|
||||
@@ -63,7 +63,7 @@ or tests in the `spec/` folder.
|
||||
Please be sure to run `npm run lint` from time to time on any code changes
|
||||
to ensure that they follow the project's code style.
|
||||
|
||||
See [coding style](https://electronjs.org/docs/development/coding-style) for
|
||||
See [coding style](coding-style.md) for
|
||||
more information about best practice when modifying code in different parts of
|
||||
the project.
|
||||
|
||||
@@ -91,29 +91,29 @@ Before a pull request can be merged, it **must** have a pull request title with
|
||||
|
||||
Examples of commit messages with semantic prefixes:
|
||||
|
||||
- `fix: don't overwrite prevent_default if default wasn't prevented`
|
||||
- `feat: add app.isPackaged() method`
|
||||
- `docs: app.isDefaultProtocolClient is now available on Linux`
|
||||
* `fix: don't overwrite prevent_default if default wasn't prevented`
|
||||
* `feat: add app.isPackaged() method`
|
||||
* `docs: app.isDefaultProtocolClient is now available on Linux`
|
||||
|
||||
Common prefixes:
|
||||
|
||||
- fix: A bug fix
|
||||
- feat: A new feature
|
||||
- docs: Documentation changes
|
||||
- test: Adding missing tests or correcting existing tests
|
||||
- build: Changes that affect the build system
|
||||
- ci: Changes to our CI configuration files and scripts
|
||||
- perf: A code change that improves performance
|
||||
- refactor: A code change that neither fixes a bug nor adds a feature
|
||||
- style: Changes that do not affect the meaning of the code (linting)
|
||||
- vendor: Bumping a dependency like libchromiumcontent or node
|
||||
* fix: A bug fix
|
||||
* feat: A new feature
|
||||
* docs: Documentation changes
|
||||
* test: Adding missing tests or correcting existing tests
|
||||
* build: Changes that affect the build system
|
||||
* ci: Changes to our CI configuration files and scripts
|
||||
* perf: A code change that improves performance
|
||||
* refactor: A code change that neither fixes a bug nor adds a feature
|
||||
* style: Changes that do not affect the meaning of the code (linting)
|
||||
* vendor: Bumping a dependency like libchromiumcontent or node
|
||||
|
||||
Other things to keep in mind when writing a commit message:
|
||||
|
||||
1. The first line should:
|
||||
- contain a short description of the change (preferably 50 characters or less,
|
||||
* contain a short description of the change (preferably 50 characters or less,
|
||||
and no more than 72 characters)
|
||||
- be entirely in lowercase with the exception of proper nouns, acronyms, and
|
||||
* be entirely in lowercase with the exception of proper nouns, acronyms, and
|
||||
the words that refer to code, like function/variable names
|
||||
2. Keep the second line blank.
|
||||
3. Wrap all other lines at 72 columns.
|
||||
@@ -144,7 +144,7 @@ master.
|
||||
### Step 7: Test
|
||||
|
||||
Bug fixes and features should always come with tests. A
|
||||
[testing guide](https://electronjs.org/docs/development/testing) has been
|
||||
[testing guide](testing.md) has been
|
||||
provided to make the process easier. Looking at other tests to see how they
|
||||
should be structured can also help.
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
<body>
|
||||
<h1>Hello World!</h1>
|
||||
<p>
|
||||
We are using node <script>document.write(process.versions.node)</script>,
|
||||
Chrome <script>document.write(process.versions.chrome)</script>,
|
||||
and Electron <script>document.write(process.versions.electron)</script>.
|
||||
We are using Node.js <span id="node-version"></span>,
|
||||
Chromium <span id="chrome-version"></span>,
|
||||
and Electron <span id="electron-version"></span>.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
function createWindow () {
|
||||
const win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
}
|
||||
})
|
||||
|
||||
win.loadFile('index.html')
|
||||
}
|
||||
|
||||
app.whenReady().then(createWindow)
|
||||
app.whenReady().then(() => {
|
||||
createWindow()
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
@@ -20,8 +29,3 @@ app.on('window-all-closed', () => {
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
|
||||
11
docs/fiddles/quick-start/preload.js
Normal file
11
docs/fiddles/quick-start/preload.js
Normal file
@@ -0,0 +1,11 @@
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const replaceText = (selector, text) => {
|
||||
const element = document.getElementById(selector)
|
||||
if (element) element.innerText = text
|
||||
}
|
||||
|
||||
for (const type of ['chrome', 'node', 'electron']) {
|
||||
replaceText(`${type}-version`, process.versions[type])
|
||||
}
|
||||
})
|
||||
|
||||
@@ -49,6 +49,7 @@ For API references, there are exceptions to this rule.
|
||||
* No nesting lists more than 2 levels (due to the markdown renderer).
|
||||
* All `js` and `javascript` code blocks are linted with
|
||||
[standard-markdown](https://www.npmjs.com/package/standard-markdown).
|
||||
* For unordered lists, use asterisks instead of dashes
|
||||
|
||||
## Picking words
|
||||
|
||||
|
||||
@@ -43,6 +43,6 @@ If the V8 context crashes, the DevTools will display this message.
|
||||
|
||||
`DevTools was disconnected from the page. Once page is reloaded, DevTools will automatically reconnect.`
|
||||
|
||||
Chromium logs can be enabled via the `ELECTRON_ENABLE_LOGGING` environment variable. For more information, see the [environment variables documentation](https://www.electronjs.org/docs/api/environment-variables#electron_enable_logging).
|
||||
Chromium logs can be enabled via the `ELECTRON_ENABLE_LOGGING` environment variable. For more information, see the [environment variables documentation](../api/environment-variables.md#electron_enable_logging).
|
||||
|
||||
Alternatively, the command line argument `--enable-logging` can be passed. More information is available in the [command line switches documentation](https://www.electronjs.org/docs/api/command-line-switches#--enable-logging).
|
||||
Alternatively, the command line argument `--enable-logging` can be passed. More information is available in the [command line switches documentation](../api/command-line-switches.md#--enable-logging).
|
||||
|
||||
@@ -1,25 +1,38 @@
|
||||
# Application Distribution
|
||||
|
||||
To distribute your app with Electron, you need to package and rebrand it. The easiest way to do this is to use one of the following third party packaging tools:
|
||||
## Overview
|
||||
|
||||
To distribute your app with Electron, you need to package and rebrand it.
|
||||
To do this, you can either use specialized tooling or manual approaches.
|
||||
|
||||
## With tooling
|
||||
|
||||
You can use the following tools to distribute your application:
|
||||
|
||||
* [electron-forge](https://github.com/electron-userland/electron-forge)
|
||||
* [electron-builder](https://github.com/electron-userland/electron-builder)
|
||||
* [electron-packager](https://github.com/electron/electron-packager)
|
||||
|
||||
These tools will take care of all the steps you need to take to end up with a distributable Electron applications, such as packaging your application, rebranding the executable, setting the right icons and optionally creating installers.
|
||||
These tools will take care of all the steps you need to take to end up with a
|
||||
distributable Electron application, such as bundling your application,
|
||||
rebranding the executable, and setting the right icons.
|
||||
|
||||
You can check the example of how to package your app with `electron-forge` in
|
||||
our [Quick Start Guide](quick-start.md#package-and-distribute-the-application).
|
||||
|
||||
## Manual distribution
|
||||
|
||||
You can also choose to manually get your app ready for distribution. The steps needed to do this are outlined below.
|
||||
### With prebuilt binaries
|
||||
|
||||
To distribute your app with Electron, you need to download Electron's [prebuilt
|
||||
To distribute your app manually, you need to download Electron's [prebuilt
|
||||
binaries](https://github.com/electron/electron/releases). Next, the folder
|
||||
containing your app should be named `app` and placed in Electron's resources
|
||||
directory as shown in the following examples. Note that the location of
|
||||
Electron's prebuilt binaries is indicated with `electron/` in the examples
|
||||
below.
|
||||
directory as shown in the following examples.
|
||||
|
||||
On macOS:
|
||||
> *NOTE:* the location of Electron's prebuilt binaries is indicated
|
||||
with `electron/` in the examples below.
|
||||
|
||||
*On macOS:*
|
||||
|
||||
```plaintext
|
||||
electron/Electron.app/Contents/Resources/app/
|
||||
@@ -28,7 +41,7 @@ electron/Electron.app/Contents/Resources/app/
|
||||
└── index.html
|
||||
```
|
||||
|
||||
On Windows and Linux:
|
||||
*On Windows and Linux:*
|
||||
|
||||
```plaintext
|
||||
electron/resources/app
|
||||
@@ -37,47 +50,44 @@ electron/resources/app
|
||||
└── index.html
|
||||
```
|
||||
|
||||
Then execute `Electron.app` (or `electron` on Linux, `electron.exe` on Windows),
|
||||
and Electron will start as your app. The `electron` directory will then be
|
||||
your distribution to deliver to final users.
|
||||
Then execute `Electron.app` on macOS, `electron` on Linux, or `electron.exe`
|
||||
on Windows, and Electron will start as your app. The `electron` directory
|
||||
will then be your distribution to deliver to users.
|
||||
|
||||
## Packaging Your App into a File
|
||||
### With an app source code archive
|
||||
|
||||
Apart from shipping your app by copying all of its source files, you can also
|
||||
package your app into an [asar](https://github.com/electron/asar) archive to avoid
|
||||
exposing your app's source code to users.
|
||||
Instead of from shipping your app by copying all of its source files, you can
|
||||
package your app into an [asar] archive to improve the performance of reading
|
||||
files on platforms like Windows, if you are not already using a bundler such
|
||||
as Parcel or Webpack.
|
||||
|
||||
To use an `asar` archive to replace the `app` folder, you need to rename the
|
||||
archive to `app.asar`, and put it under Electron's resources directory like
|
||||
below, and Electron will then try to read the archive and start from it.
|
||||
|
||||
On macOS:
|
||||
*On macOS:*
|
||||
|
||||
```plaintext
|
||||
electron/Electron.app/Contents/Resources/
|
||||
└── app.asar
|
||||
```
|
||||
|
||||
On Windows and Linux:
|
||||
*On Windows and Linux:*
|
||||
|
||||
```plaintext
|
||||
electron/resources/
|
||||
└── app.asar
|
||||
```
|
||||
|
||||
More details can be found in [Application packaging](application-packaging.md).
|
||||
You can find more details on how to use `asar` in the
|
||||
[`electron/asar` repository][asar].
|
||||
|
||||
## Rebranding with Downloaded Binaries
|
||||
### Rebranding with downloaded binaries
|
||||
|
||||
After bundling your app into Electron, you will want to rebrand Electron
|
||||
before distributing it to users.
|
||||
|
||||
### Windows
|
||||
|
||||
You can rename `electron.exe` to any name you like, and edit its icon and other
|
||||
information with tools like [rcedit](https://github.com/electron/rcedit).
|
||||
|
||||
### macOS
|
||||
#### macOS
|
||||
|
||||
You can rename `Electron.app` to any name you want, and you also have to rename
|
||||
the `CFBundleDisplayName`, `CFBundleIdentifier` and `CFBundleName` fields in the
|
||||
@@ -104,60 +114,20 @@ MyApp.app/Contents
|
||||
└── MyApp Helper
|
||||
```
|
||||
|
||||
### Linux
|
||||
#### Windows
|
||||
|
||||
You can rename `electron.exe` to any name you like, and edit its icon and other
|
||||
information with tools like [rcedit](https://github.com/electron/rcedit).
|
||||
|
||||
#### Linux
|
||||
|
||||
You can rename the `electron` executable to any name you like.
|
||||
|
||||
## Rebranding by Rebuilding Electron from Source
|
||||
### Rebranding by rebuilding Electron from source
|
||||
|
||||
It is also possible to rebrand Electron by changing the product name and
|
||||
building it from source. To do this you need to set the build argument
|
||||
corresponding to the product name (`electron_product_name = "YourProductName"`)
|
||||
in the `args.gn` file and rebuild.
|
||||
|
||||
### Creating a Custom Electron Fork
|
||||
|
||||
Creating a custom fork of Electron is almost certainly not something you will
|
||||
need to do in order to build your app, even for "Production Level" applications.
|
||||
Using a tool such as `electron-packager` or `electron-forge` will allow you to
|
||||
"Rebrand" Electron without having to do these steps.
|
||||
|
||||
You need to fork Electron when you have custom C++ code that you have patched
|
||||
directly into Electron, that either cannot be upstreamed, or has been rejected
|
||||
from the official version. As maintainers of Electron, we very much would like
|
||||
to make your scenario work, so please try as hard as you can to get your changes
|
||||
into the official version of Electron, it will be much much easier on you, and
|
||||
we appreciate your help.
|
||||
|
||||
#### Creating a Custom Release with surf-build
|
||||
|
||||
1. Install [Surf](https://github.com/surf-build/surf), via npm:
|
||||
`npm install -g surf-build@latest`
|
||||
|
||||
2. Create a new S3 bucket and create the following empty directory structure:
|
||||
|
||||
```sh
|
||||
- electron/
|
||||
- symbols/
|
||||
- dist/
|
||||
```
|
||||
|
||||
3. Set the following Environment Variables:
|
||||
|
||||
* `ELECTRON_GITHUB_TOKEN` - a token that can create releases on GitHub
|
||||
* `ELECTRON_S3_ACCESS_KEY`, `ELECTRON_S3_BUCKET`, `ELECTRON_S3_SECRET_KEY` -
|
||||
the place where you'll upload Node.js headers as well as symbols
|
||||
* `ELECTRON_RELEASE` - Set to `true` and the upload part will run, leave unset
|
||||
and `surf-build` will do CI-type checks, appropriate to run for every
|
||||
pull request.
|
||||
* `CI` - Set to `true` or else it will fail
|
||||
* `GITHUB_TOKEN` - set it to the same as `ELECTRON_GITHUB_TOKEN`
|
||||
* `SURF_TEMP` - set to `C:\Temp` on Windows to prevent path too long issues
|
||||
* `TARGET_ARCH` - set to `ia32` or `x64`
|
||||
|
||||
4. In `script/upload.py`, you _must_ set `ELECTRON_REPO` to your fork (`MYORG/electron`),
|
||||
especially if you are a contributor to Electron proper.
|
||||
|
||||
5. `surf-build -r https://github.com/MYORG/electron -s YOUR_COMMIT -n 'surf-PLATFORM-ARCH'`
|
||||
|
||||
6. Wait a very, very long time for the build to complete.
|
||||
[asar]: https://github.com/electron/asar
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
# Application Packaging
|
||||
|
||||
To mitigate [issues](https://github.com/joyent/node/issues/6960) around long
|
||||
path names on Windows, slightly speed up `require` and conceal your source code
|
||||
from cursory inspection, you can choose to package your app into an [asar][asar]
|
||||
archive with little changes to your source code.
|
||||
|
||||
Most users will get this feature for free, since it's supported out of the box
|
||||
by [`electron-packager`][electron-packager], [`electron-forge`][electron-forge],
|
||||
and [`electron-builder`][electron-builder]. If you are not using any of these
|
||||
tools, read on.
|
||||
|
||||
## Generating `asar` Archives
|
||||
|
||||
An [asar][asar] archive is a simple tar-like format that concatenates files
|
||||
into a single file. Electron can read arbitrary files from it without unpacking
|
||||
the whole file.
|
||||
|
||||
Steps to package your app into an `asar` archive:
|
||||
|
||||
### 1. Install the asar Utility
|
||||
|
||||
```sh
|
||||
$ npm install -g asar
|
||||
```
|
||||
|
||||
### 2. Package with `asar pack`
|
||||
|
||||
```sh
|
||||
$ asar pack your-app app.asar
|
||||
```
|
||||
|
||||
## Using `asar` Archives
|
||||
|
||||
In Electron there are two sets of APIs: Node APIs provided by Node.js and Web
|
||||
APIs provided by Chromium. Both APIs support reading files from `asar` archives.
|
||||
|
||||
### Node API
|
||||
|
||||
With special patches in Electron, Node APIs like `fs.readFile` and `require`
|
||||
treat `asar` archives as virtual directories, and the files in it as normal
|
||||
files in the filesystem.
|
||||
|
||||
For example, suppose we have an `example.asar` archive under `/path/to`:
|
||||
|
||||
```sh
|
||||
$ asar list /path/to/example.asar
|
||||
/app.js
|
||||
/file.txt
|
||||
/dir/module.js
|
||||
/static/index.html
|
||||
/static/main.css
|
||||
/static/jquery.min.js
|
||||
```
|
||||
|
||||
Read a file in the `asar` archive:
|
||||
|
||||
```javascript
|
||||
const fs = require('fs')
|
||||
fs.readFileSync('/path/to/example.asar/file.txt')
|
||||
```
|
||||
|
||||
List all files under the root of the archive:
|
||||
|
||||
```javascript
|
||||
const fs = require('fs')
|
||||
fs.readdirSync('/path/to/example.asar')
|
||||
```
|
||||
|
||||
Use a module from the archive:
|
||||
|
||||
```javascript
|
||||
require('./path/to/example.asar/dir/module.js')
|
||||
```
|
||||
|
||||
You can also display a web page in an `asar` archive with `BrowserWindow`:
|
||||
|
||||
```javascript
|
||||
const { BrowserWindow } = require('electron')
|
||||
const win = new BrowserWindow()
|
||||
|
||||
win.loadURL('file:///path/to/example.asar/static/index.html')
|
||||
```
|
||||
|
||||
### Web API
|
||||
|
||||
In a web page, files in an archive can be requested with the `file:` protocol.
|
||||
Like the Node API, `asar` archives are treated as directories.
|
||||
|
||||
For example, to get a file with `$.get`:
|
||||
|
||||
```html
|
||||
<script>
|
||||
let $ = require('./jquery.min.js')
|
||||
$.get('file:///path/to/example.asar/file.txt', (data) => {
|
||||
console.log(data)
|
||||
})
|
||||
</script>
|
||||
```
|
||||
|
||||
### Treating an `asar` Archive as a Normal File
|
||||
|
||||
For some cases like verifying the `asar` archive's checksum, we need to read the
|
||||
content of an `asar` archive as a file. For this purpose you can use the built-in
|
||||
`original-fs` module which provides original `fs` APIs without `asar` support:
|
||||
|
||||
```javascript
|
||||
const originalFs = require('original-fs')
|
||||
originalFs.readFileSync('/path/to/example.asar')
|
||||
```
|
||||
|
||||
You can also set `process.noAsar` to `true` to disable the support for `asar` in
|
||||
the `fs` module:
|
||||
|
||||
```javascript
|
||||
const fs = require('fs')
|
||||
process.noAsar = true
|
||||
fs.readFileSync('/path/to/example.asar')
|
||||
```
|
||||
|
||||
## Limitations of the Node API
|
||||
|
||||
Even though we tried hard to make `asar` archives in the Node API work like
|
||||
directories as much as possible, there are still limitations due to the
|
||||
low-level nature of the Node API.
|
||||
|
||||
### Archives Are Read-only
|
||||
|
||||
The archives can not be modified so all Node APIs that can modify files will not
|
||||
work with `asar` archives.
|
||||
|
||||
### Working Directory Can Not Be Set to Directories in Archive
|
||||
|
||||
Though `asar` archives are treated as directories, there are no actual
|
||||
directories in the filesystem, so you can never set the working directory to
|
||||
directories in `asar` archives. Passing them as the `cwd` option of some APIs
|
||||
will also cause errors.
|
||||
|
||||
### Extra Unpacking on Some APIs
|
||||
|
||||
Most `fs` APIs can read a file or get a file's information from `asar` archives
|
||||
without unpacking, but for some APIs that rely on passing the real file path to
|
||||
underlying system calls, Electron will extract the needed file into a
|
||||
temporary file and pass the path of the temporary file to the APIs to make them
|
||||
work. This adds a little overhead for those APIs.
|
||||
|
||||
APIs that requires extra unpacking are:
|
||||
|
||||
* `child_process.execFile`
|
||||
* `child_process.execFileSync`
|
||||
* `fs.open`
|
||||
* `fs.openSync`
|
||||
* `process.dlopen` - Used by `require` on native modules
|
||||
|
||||
### Fake Stat Information of `fs.stat`
|
||||
|
||||
The `Stats` object returned by `fs.stat` and its friends on files in `asar`
|
||||
archives is generated by guessing, because those files do not exist on the
|
||||
filesystem. So you should not trust the `Stats` object except for getting file
|
||||
size and checking file type.
|
||||
|
||||
### Executing Binaries Inside `asar` Archive
|
||||
|
||||
There are Node APIs that can execute binaries like `child_process.exec`,
|
||||
`child_process.spawn` and `child_process.execFile`, but only `execFile` is
|
||||
supported to execute binaries inside `asar` archive.
|
||||
|
||||
This is because `exec` and `spawn` accept `command` instead of `file` as input,
|
||||
and `command`s are executed under shell. There is no reliable way to determine
|
||||
whether a command uses a file in asar archive, and even if we do, we can not be
|
||||
sure whether we can replace the path in command without side effects.
|
||||
|
||||
## Adding Unpacked Files to `asar` Archives
|
||||
|
||||
As stated above, some Node APIs will unpack the file to the filesystem when
|
||||
called. Apart from the performance issues, various anti-virus scanners might
|
||||
be triggered by this behavior.
|
||||
|
||||
As a workaround, you can leave various files unpacked using the `--unpack` option.
|
||||
In the following example, shared libraries of native Node.js modules will not be
|
||||
packed:
|
||||
|
||||
```sh
|
||||
$ asar pack app app.asar --unpack *.node
|
||||
```
|
||||
|
||||
After running the command, you will notice that a folder named `app.asar.unpacked`
|
||||
was created together with the `app.asar` file. It contains the unpacked files
|
||||
and should be shipped together with the `app.asar` archive.
|
||||
|
||||
[asar]: https://github.com/electron/asar
|
||||
[electron-packager]: https://github.com/electron/electron-packager
|
||||
[electron-forge]: https://github.com/electron-userland/electron-forge
|
||||
[electron-builder]: https://github.com/electron-userland/electron-builder
|
||||
@@ -189,18 +189,18 @@ You can get a code signing certificate from a lot of resellers. Prices vary, so
|
||||
it may be worth your time to shop around. Popular resellers include:
|
||||
|
||||
* [digicert](https://www.digicert.com/code-signing/microsoft-authenticode.htm)
|
||||
* [Comodo](https://www.comodo.com/landing/ssl-certificate/authenticode-signature/)
|
||||
* [Sectigo](https://sectigo.com/ssl-certificates-tls/code-signing)
|
||||
* [GoDaddy](https://au.godaddy.com/web-security/code-signing-certificate)
|
||||
* Amongst others, please shop around to find one that suits your needs, Google
|
||||
is your friend 😄
|
||||
|
||||
There are a number of tools for signing your packaged app:
|
||||
|
||||
- [`electron-winstaller`] will generate an installer for windows and sign it for
|
||||
* [`electron-winstaller`] will generate an installer for windows and sign it for
|
||||
you
|
||||
- [`electron-forge`] can sign installers it generates through the
|
||||
* [`electron-forge`] can sign installers it generates through the
|
||||
Squirrel.Windows or MSI targets.
|
||||
- [`electron-builder`] can sign some of its windows targets
|
||||
* [`electron-builder`] can sign some of its windows targets
|
||||
|
||||
## Windows Store
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ the system's dark mode setting. You can do this by using the
|
||||
|
||||
If you want to manually switch between light/dark modes, you can do this by
|
||||
setting the desired mode in the
|
||||
[themeSource](https://www.electronjs.org/docs/api/native-theme#nativethemethemesource)
|
||||
[themeSource](../api/native-theme.md#nativethemethemesource)
|
||||
property of the `nativeTheme` module. This property's value will be propagated
|
||||
to your Renderer process. Any CSS rules related to `prefers-color-scheme` will
|
||||
be updated accordingly.
|
||||
@@ -96,7 +96,7 @@ color scheme, and update the "Current Theme Source" label to `System`.
|
||||
|
||||
To add listeners and handlers, add the following lines to the `renderer.js` file:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
document.getElementById('toggle-dark-mode').addEventListener('click', async () => {
|
||||
@@ -130,7 +130,7 @@ active using the `nativeTheme.shouldUseDarkColors` property, and set the
|
||||
`themeSource` to the opposite theme.
|
||||
* Upon receiving `dark-mode:system`, we reset the `themeSource` to `system`.
|
||||
|
||||
```js
|
||||
```javascript
|
||||
const { app, BrowserWindow, ipcMain, nativeTheme } = require('electron')
|
||||
|
||||
function createWindow () {
|
||||
@@ -154,7 +154,7 @@ function createWindow () {
|
||||
})
|
||||
|
||||
ipcMain.handle('dark-mode:system', () => {
|
||||
nativeTheme.themeSouce = 'system'
|
||||
nativeTheme.themeSource = 'system'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ attribute. The value of `prefers-color-scheme` will follow your
|
||||
|
||||
Create a `styles.css` file and add the following lines:
|
||||
|
||||
```css
|
||||
```css fiddle='docs/fiddles/features/macos-dark-mode'
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body { background: #333; color: white; }
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ $ code electron-quick-start
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### 3. Debugging
|
||||
|
||||
Set some breakpoints in `main.js`, and start debugging in the [Debug View](https://code.visualstudio.com/docs/editor/debugging). You should be able to hit the breakpoints.
|
||||
@@ -84,16 +83,16 @@ $ code electron-quick-start
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Configuration Notes**
|
||||
|
||||
- `cppvsdbg` requires the [built-in C/C++ extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) be enabled.
|
||||
- `${workspaceFolder}` is the full path to Chromium's `src` directory.
|
||||
- `your-executable-location` will be one of the following depending on a few items:
|
||||
- `Testing`: If you are using the default settings of [Electron's Build-Tools](https://github.com/electron/build-tools) or the default instructions when [building from source](https://www.electronjs.org/docs/development/build-instructions-gn#building).
|
||||
- `Release`: If you built a Release build rather than a Testing build.
|
||||
- `your-directory-name`: If you modified this during your build process from the default, this will be whatever you specified.
|
||||
- The `args` array string `"your-electron-project-path"` should be the absolute path to either the directory or `main.js` file of the Electron project you are using for testing. In this example, it should be your path to `electron-quick-start`.
|
||||
|
||||
* `cppvsdbg` requires the [built-in C/C++ extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) be enabled.
|
||||
* `${workspaceFolder}` is the full path to Chromium's `src` directory.
|
||||
* `your-executable-location` will be one of the following depending on a few items:
|
||||
* `Testing`: If you are using the default settings of [Electron's Build-Tools](https://github.com/electron/build-tools) or the default instructions when [building from source](https://www.electronjs.org/docs/development/build-instructions-gn#building).
|
||||
* `Release`: If you built a Release build rather than a Testing build.
|
||||
* `your-directory-name`: If you modified this during your build process from the default, this will be whatever you specified.
|
||||
* The `args` array string `"your-electron-project-path"` should be the absolute path to either the directory or `main.js` file of the Electron project you are using for testing. In this example, it should be your path to `electron-quick-start`.
|
||||
|
||||
#### 3. Debugging
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ Using the [React Developer Tools][react-devtools] as an example:
|
||||
* on macOS it is `~/Library/Application Support/Google/Chrome/Default/Extensions`.
|
||||
1. Pass the location of the extension to the [`ses.loadExtension`][load-extension]
|
||||
API. For React Developer Tools `v4.9.0`, it looks something like:
|
||||
|
||||
```javascript
|
||||
const { app, session } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
@@ -18,4 +18,5 @@
|
||||
| 9.0.0 | 2020-02-06 | 2020-05-19 | M83 | v12.14 |
|
||||
| 10.0.0 | 2020-05-21 | 2020-08-25 | M85 | v12.16 |
|
||||
| 11.0.0 | 2020-08-27 | 2020-11-17 | M87 | v12.18 |
|
||||
| 12.0.0 | 2020-11-19 | 2021-03-02 | M89 | v14.x |
|
||||
| 12.0.0 | 2020-11-19 | 2021-03-02 | M89 | v14.16 |
|
||||
| 13.0.0 | 2021-03-04 | 2021-05-25 | M91 | v14.x |
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
> A detailed look at our versioning policy and implementation.
|
||||
|
||||
As of version 2.0.0, Electron follows [semver](#semver). The following command will install the most recent stable build of Electron:
|
||||
As of version 2.0.0, Electron follows [SemVer](#semver). The following command will install the most recent stable build of Electron:
|
||||
|
||||
```sh
|
||||
npm install --save-dev electron
|
||||
@@ -16,11 +16,11 @@ npm install --save-dev electron@latest
|
||||
|
||||
## Version 1.x
|
||||
|
||||
Electron versions *< 2.0* did not conform to the [semver](https://semver.org) spec: major versions corresponded to end-user API changes, minor versions corresponded to Chromium major releases, and patch versions corresponded to new features and bug fixes. While convenient for developers merging features, it creates problems for developers of client-facing applications. The QA testing cycles of major apps like Slack, Stride, Teams, Skype, VS Code, Atom, and Desktop can be lengthy and stability is a highly desired outcome. There is a high risk in adopting new features while trying to absorb bug fixes.
|
||||
Electron versions *< 2.0* did not conform to the [SemVer](https://semver.org) spec: major versions corresponded to end-user API changes, minor versions corresponded to Chromium major releases, and patch versions corresponded to new features and bug fixes. While convenient for developers merging features, it creates problems for developers of client-facing applications. The QA testing cycles of major apps like Slack, Stride, Teams, Skype, VS Code, Atom, and Desktop can be lengthy and stability is a highly desired outcome. There is a high risk in adopting new features while trying to absorb bug fixes.
|
||||
|
||||
Here is an example of the 1.x strategy:
|
||||
|
||||

|
||||

|
||||
|
||||
An app developed with `1.8.1` cannot take the `1.8.3` bug fix without either absorbing the `1.8.2` feature, or by backporting the fix and maintaining a new release line.
|
||||
|
||||
@@ -28,7 +28,7 @@ An app developed with `1.8.1` cannot take the `1.8.3` bug fix without either abs
|
||||
|
||||
There are several major changes from our 1.x strategy outlined below. Each change is intended to satisfy the needs and priorities of developers/maintainers and app developers.
|
||||
|
||||
1. Strict use of semver
|
||||
1. Strict use of SemVer
|
||||
2. Introduction of semver-compliant `-beta` tags
|
||||
3. Introduction of [conventional commit messages](https://conventionalcommits.org/)
|
||||
4. Well-defined stabilization branches
|
||||
@@ -36,11 +36,11 @@ There are several major changes from our 1.x strategy outlined below. Each chang
|
||||
|
||||
We will cover in detail how git branching works, how npm tagging works, what developers should expect to see, and how one can backport changes.
|
||||
|
||||
# semver
|
||||
# SemVer
|
||||
|
||||
From 2.0 onward, Electron will follow semver.
|
||||
From 2.0 onward, Electron will follow SemVer.
|
||||
|
||||
Below is a table explicitly mapping types of changes to their corresponding category of semver (e.g. Major, Minor, Patch).
|
||||
Below is a table explicitly mapping types of changes to their corresponding category of SemVer (e.g. Major, Minor, Patch).
|
||||
|
||||
| Major Version Increments | Minor Version Increments | Patch Version Increments |
|
||||
| ------------------------------- | ---------------------------------- | ----------------------------- |
|
||||
@@ -54,12 +54,12 @@ Note that most Chromium updates will be considered breaking. Fixes that can be b
|
||||
|
||||
Stabilization branches are branches that run parallel to master, taking in only cherry-picked commits that are related to security or stability. These branches are never merged back to master.
|
||||
|
||||

|
||||

|
||||
|
||||
Since Electron 8, stabilization branches are always **major** version lines, and named against the following template `$MAJOR-x-y` e.g. `8-x-y`. Prior to that we used **minor** version lines and named them as `$MAJOR-$MINOR-x` e.g. `2-0-x`
|
||||
|
||||
We allow for multiple stabilization branches to exist simultaneously, and intend to support at least two in parallel at all times, backporting security fixes as necessary.
|
||||

|
||||

|
||||
|
||||
Older lines will not be supported by GitHub, but other groups can take ownership and backport stability and security fixes on their own. We discourage this, but recognize that it makes life easier for many app developers.
|
||||
|
||||
@@ -70,13 +70,13 @@ Developers want to know which releases are _safe_ to use. Even seemingly innocen
|
||||
* Use `~2.0.0` to admit only stability or security related fixes to your `2.0.0` release.
|
||||
* Use `^2.0.0` to admit non-breaking _reasonably stable_ feature work as well as security and bug fixes.
|
||||
|
||||
What’s important about the second point is that apps using `^` should still be able to expect a reasonable level of stability. To accomplish this, semver allows for a _pre-release identifier_ to indicate a particular version is not yet _safe_ or _stable_.
|
||||
What’s important about the second point is that apps using `^` should still be able to expect a reasonable level of stability. To accomplish this, SemVer allows for a _pre-release identifier_ to indicate a particular version is not yet _safe_ or _stable_.
|
||||
|
||||
Whatever you choose, you will periodically have to bump the version in your `package.json` as breaking changes are a fact of Chromium life.
|
||||
|
||||
The process is as follows:
|
||||
|
||||
1. All new major and minor releases lines begin with a beta series indicated by semver prerelease tags of `beta.N`, e.g. `2.0.0-beta.1`. After the first beta, subsequent beta releases must meet all of the following conditions:
|
||||
1. All new major and minor releases lines begin with a beta series indicated by SemVer prerelease tags of `beta.N`, e.g. `2.0.0-beta.1`. After the first beta, subsequent beta releases must meet all of the following conditions:
|
||||
1. The change is backwards API-compatible (deprecations are allowed)
|
||||
2. The risk to meeting our stability timeline must be low.
|
||||
2. If allowed changes need to be made once a release is beta, they are applied and the prerelease tag is incremented, e.g. `2.0.0-beta.2`.
|
||||
@@ -86,7 +86,7 @@ e.g. `2.0.1`.
|
||||
|
||||
Specifically, the above means:
|
||||
|
||||
1. Admitting non-breaking-API changes before Week 3 in the beta cycle is okay, even if those changes have the potential to cause moderate side-effects
|
||||
1. Admitting non-breaking-API changes before Week 3 in the beta cycle is okay, even if those changes have the potential to cause moderate side-effects.
|
||||
2. Admitting feature-flagged changes, that do not otherwise alter existing code paths, at most points in the beta cycle is okay. Users can explicitly enable those flags in their apps.
|
||||
3. Admitting features of any sort after Week 3 in the beta cycle is 👎 without a very good reason.
|
||||
|
||||
@@ -104,17 +104,17 @@ For each major and minor bump, you should expect to see something like the follo
|
||||
An example lifecycle in pictures:
|
||||
|
||||
* A new release branch is created that includes the latest set of features. It is published as `2.0.0-beta.1`.
|
||||

|
||||

|
||||
* A bug fix comes into master that can be backported to the release branch. The patch is applied, and a new beta is published as `2.0.0-beta.2`.
|
||||

|
||||

|
||||
* The beta is considered _generally stable_ and it is published again as a non-beta under `2.0.0`.
|
||||

|
||||

|
||||
* Later, a zero-day exploit is revealed and a fix is applied to master. We backport the fix to the `2-0-x` line and release `2.0.1`.
|
||||

|
||||

|
||||
|
||||
A few examples of how various semver ranges will pick up new releases:
|
||||
A few examples of how various SemVer ranges will pick up new releases:
|
||||
|
||||

|
||||

|
||||
|
||||
# Missing Features: Alphas
|
||||
|
||||
@@ -136,16 +136,16 @@ Feature flags are a common practice in Chromium, and are well-established in the
|
||||
|
||||
We seek to increase clarity at all levels of the update and releases process. Starting with `2.0.0` we will require pull requests adhere to the [Conventional Commits](https://conventionalcommits.org/) spec, which can be summarized as follows:
|
||||
|
||||
* Commits that would result in a semver **major** bump must start their body with `BREAKING CHANGE:`.
|
||||
* Commits that would result in a semver **minor** bump must start with `feat:`.
|
||||
* Commits that would result in a semver **patch** bump must start with `fix:`.
|
||||
* Commits that would result in a SemVer **major** bump must start their body with `BREAKING CHANGE:`.
|
||||
* Commits that would result in a SemVer **minor** bump must start with `feat:`.
|
||||
* Commits that would result in a SemVer **patch** bump must start with `fix:`.
|
||||
|
||||
* We allow squashing of commits, provided that the squashed message adheres to the above message format.
|
||||
* It is acceptable for some commits in a pull request to not include a semantic prefix, as long as the pull request title contains a meaningful encompassing semantic message.
|
||||
|
||||
# Versioned `master`
|
||||
|
||||
- The `master` branch will always contain the next major version `X.0.0-nightly.DATE` in its `package.json`
|
||||
- Release branches are never merged back to master
|
||||
- Release branches _do_ contain the correct version in their `package.json`
|
||||
- As soon as a release branch is cut for a major, master must be bumped to the next major. I.e. `master` is always versioned as the next theoretical release branch
|
||||
* The `master` branch will always contain the next major version `X.0.0-nightly.DATE` in its `package.json`
|
||||
* Release branches are never merged back to master
|
||||
* Release branches _do_ contain the correct version in their `package.json`
|
||||
* As soon as a release branch is cut for a major, master must be bumped to the next major. I.e. `master` is always versioned as the next theoretical release branch
|
||||
|
||||
@@ -17,7 +17,7 @@ Starting with a working application from the
|
||||
[Quick Start Guide](quick-start.md), update the `main.js` file with the
|
||||
following lines:
|
||||
|
||||
```js
|
||||
```javascript fiddle='docs/fiddles/features/keyboard-shortcuts/local'
|
||||
const { Menu, MenuItem } = require('electron')
|
||||
|
||||
const menu = new Menu()
|
||||
@@ -56,7 +56,7 @@ Starting with a working application from the
|
||||
[Quick Start Guide](quick-start.md), update the `main.js` file with the
|
||||
following lines:
|
||||
|
||||
```js
|
||||
```javascript fiddle='docs/fiddles/features/keyboard-shortcuts/global'
|
||||
const { app, globalShortcut } = require('electron')
|
||||
|
||||
app.whenReady().then(() => {
|
||||
@@ -101,7 +101,7 @@ Starting with a working application from the
|
||||
[Quick Start Guide](quick-start.md), update the `main.js` file with the
|
||||
following lines:
|
||||
|
||||
```js
|
||||
```javascript fiddle='docs/fiddles/features/keyboard-shortcuts/interception-from-main'
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
|
||||
app.whenReady().then(() => {
|
||||
|
||||
@@ -24,7 +24,7 @@ Starting with a working application from the
|
||||
[Quick Start Guide](quick-start.md), update the `main.js` file with the
|
||||
following lines:
|
||||
|
||||
```javascript
|
||||
```javascript fiddle='docs/fiddles/features/macos-dock-menu'
|
||||
const { app, Menu } = require('electron')
|
||||
|
||||
const dockMenu = Menu.buildFromTemplate([
|
||||
|
||||
325
docs/tutorial/message-ports.md
Normal file
325
docs/tutorial/message-ports.md
Normal file
@@ -0,0 +1,325 @@
|
||||
# MessagePorts in Electron
|
||||
|
||||
[`MessagePort`][]s are a web feature that allow passing messages between
|
||||
different contexts. It's like `window.postMessage`, but on different channels.
|
||||
The goal of this document is to describe how Electron extends the Channel
|
||||
Messaging model, and to give some examples of how you might use MessagePorts in
|
||||
your app.
|
||||
|
||||
Here is a very brief example of what a MessagePort is and how it works:
|
||||
|
||||
```js
|
||||
// renderer.js ///////////////////////////////////////////////////////////////
|
||||
// MessagePorts are created in pairs. A connected pair of message ports is
|
||||
// called a channel.
|
||||
const channel = new MessageChannel()
|
||||
|
||||
// The only difference between port1 and port2 is in how you use them. Messages
|
||||
// sent to port1 will be received by port2 and vice-versa.
|
||||
const port1 = channel.port1
|
||||
const port2 = channel.port2
|
||||
|
||||
// It's OK to send a message on the channel before the other end has registered
|
||||
// a listener. Messages will be queued until a listener is registered.
|
||||
port2.postMessage({ answer: 42 })
|
||||
|
||||
// Here we send the other end of the channel, port1, to the main process. It's
|
||||
// also possible to send MessagePorts to other frames, or to Web Workers, etc.
|
||||
ipcRenderer.postMessage('port', null, [port1])
|
||||
```
|
||||
|
||||
```js
|
||||
// main.js ///////////////////////////////////////////////////////////////////
|
||||
// In the main process, we receive the port.
|
||||
ipcMain.on('port', (event) => {
|
||||
// When we receive a MessagePort in the main process, it becomes a
|
||||
// MessagePortMain.
|
||||
const port = event.ports[0]
|
||||
|
||||
// MessagePortMain uses the Node.js-style events API, rather than the
|
||||
// web-style events API. So .on('message', ...) instead of .onmessage = ...
|
||||
port.on('message', (event) => {
|
||||
// data is { answer: 42 }
|
||||
const data = event.data
|
||||
})
|
||||
|
||||
// MessagePortMain queues messages until the .start() method has been called.
|
||||
port.start()
|
||||
})
|
||||
```
|
||||
|
||||
The [Channel Messaging API][] documentation is a great way to learn more about
|
||||
how MessagePorts work.
|
||||
|
||||
## MessagePorts in the main process
|
||||
|
||||
In the renderer, the `MessagePort` class behaves exactly as it does on the web.
|
||||
The main process is not a web page, though—it has no Blink integration—and so
|
||||
it does not have the `MessagePort` or `MessageChannel` classes. In order to
|
||||
handle and interact with MessagePorts in the main process, Electron adds two
|
||||
new classes: [`MessagePortMain`][] and [`MessageChannelMain`][]. These behave
|
||||
similarly to the analogous classes in the renderer.
|
||||
|
||||
`MessagePort` objects can be created in either the renderer or the main
|
||||
process, and passed back and forth using the [`ipcRenderer.postMessage`][] and
|
||||
[`WebContents.postMessage`][] methods. Note that the usual IPC methods like
|
||||
`send` and `invoke` cannot be used to transfer `MessagePort`s, only the
|
||||
`postMessage` methods can transfer `MessagePort`s.
|
||||
|
||||
By passing `MessagePort`s via the main process, you can connect two pages that
|
||||
might not otherwise be able to communicate (e.g. due to same-origin
|
||||
restrictions).
|
||||
|
||||
## Extension: `close` event
|
||||
|
||||
Electron adds one feature to `MessagePort` that isn't present on the web, in
|
||||
order to make MessagePorts more useful. That is the `close` event, which is
|
||||
emitted when the other end of the channel is closed. Ports can also be
|
||||
implicitly closed by being garbage-collected.
|
||||
|
||||
In the renderer, you can listen for the `close` event either by assigning to
|
||||
`port.onclose` or by calling `port.addEventListener('close', ...)`. In the main
|
||||
process, you can listen for the `close` event by calling `port.on('close',
|
||||
...)`.
|
||||
|
||||
## Example use cases
|
||||
|
||||
### Worker process
|
||||
|
||||
In this example, your app has a worker process implemented as a hidden window.
|
||||
You want the app page to be able to communicate directly with the worker
|
||||
process, without the performance overhead of relaying via the main process.
|
||||
|
||||
```js
|
||||
// main.js ///////////////////////////////////////////////////////////////////
|
||||
const { BrowserWindow, app, ipcMain, MessageChannelMain } = require('electron')
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
// The worker process is a hidden BrowserWindow, so that it will have access
|
||||
// to a full Blink context (including e.g. <canvas>, audio, fetch(), etc.)
|
||||
const worker = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: { nodeIntegration: true }
|
||||
})
|
||||
await worker.loadFile('worker.html')
|
||||
|
||||
// The main window will send work to the worker process and receive results
|
||||
// over a MessagePort.
|
||||
const mainWindow = new BrowserWindow({
|
||||
webPreferences: { nodeIntegration: true }
|
||||
})
|
||||
mainWindow.loadFile('app.html')
|
||||
|
||||
// We can't use ipcMain.handle() here, because the reply needs to transfer a
|
||||
// MessagePort.
|
||||
ipcMain.on('request-worker-channel', (event) => {
|
||||
// For security reasons, let's make sure only the frames we expect can
|
||||
// access the worker.
|
||||
if (event.senderFrame === mainWindow.webContents.mainFrame) {
|
||||
// Create a new channel ...
|
||||
const { port1, port2 } = new MessageChannelMain()
|
||||
// ... send one end to the worker ...
|
||||
worker.webContents.postMessage('new-client', null, [port1])
|
||||
// ... and the other end to the main window.
|
||||
event.senderFrame.postMessage('provide-worker-channel', null, [port2])
|
||||
// Now the main window and the worker can communicate with each other
|
||||
// without going through the main process!
|
||||
}
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- worker.html ------------------------------------------------------------>
|
||||
<script>
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
function doWork(input) {
|
||||
// Something cpu-intensive.
|
||||
return input * 2
|
||||
}
|
||||
|
||||
// We might get multiple clients, for instance if there are multiple windows,
|
||||
// or if the main window reloads.
|
||||
ipcRenderer.on('new-client', (event) => {
|
||||
const [ port ] = event.ports
|
||||
port.onmessage = (event) => {
|
||||
// The event data can be any serializable object (and the event could even
|
||||
// carry other MessagePorts with it!)
|
||||
const result = doWork(event.data)
|
||||
port.postMessage(result)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- app.html --------------------------------------------------------------->
|
||||
<script>
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
// We request that the main process sends us a channel we can use to
|
||||
// communicate with the worker.
|
||||
ipcRenderer.send('request-worker-channel')
|
||||
|
||||
ipcRenderer.once('provide-worker-channel', (event) => {
|
||||
// Once we receive the reply, we can take the port...
|
||||
const [ port ] = event.ports
|
||||
// ... register a handler to receive results ...
|
||||
port.onmessage = (event) => {
|
||||
console.log('received result:', event.data)
|
||||
}
|
||||
// ... and start sending it work!
|
||||
port.postMessage(21)
|
||||
})
|
||||
</script>
|
||||
```
|
||||
|
||||
### Reply streams
|
||||
|
||||
Electron's built-in IPC methods only support two modes: fire-and-forget
|
||||
(e.g. `send`), or request-response (e.g. `invoke`). Using MessageChannels, you
|
||||
can implement a "response stream", where a single request responds with a
|
||||
stream of data.
|
||||
|
||||
```js
|
||||
// renderer.js ///////////////////////////////////////////////////////////////
|
||||
|
||||
function makeStreamingRequest (element, callback) {
|
||||
// MessageChannels are lightweight--it's cheap to create a new one for each
|
||||
// request.
|
||||
const { port1, port2 } = new MessageChannel()
|
||||
|
||||
// We send one end of the port to the main process ...
|
||||
ipcRenderer.postMessage(
|
||||
'give-me-a-stream',
|
||||
{ element, count: 10 },
|
||||
[port2]
|
||||
)
|
||||
|
||||
// ... and we hang on to the other end. The main process will send messages
|
||||
// to its end of the port, and close it when it's finished.
|
||||
port1.onmessage = (event) => {
|
||||
callback(event.data)
|
||||
}
|
||||
port1.onclose = () => {
|
||||
console.log('stream ended')
|
||||
}
|
||||
}
|
||||
|
||||
makeStreamingRequest(42, (data) => {
|
||||
console.log('got response data:', event.data)
|
||||
})
|
||||
// We will see "got response data: 42" 10 times.
|
||||
```
|
||||
|
||||
```js
|
||||
// main.js ///////////////////////////////////////////////////////////////////
|
||||
|
||||
ipcMain.on('give-me-a-stream', (event, msg) => {
|
||||
// The renderer has sent us a MessagePort that it wants us to send our
|
||||
// response over.
|
||||
const [replyPort] = event.ports
|
||||
|
||||
// Here we send the messages synchronously, but we could just as easily store
|
||||
// the port somewhere and send messages asynchronously.
|
||||
for (let i = 0; i < msg.count; i++) {
|
||||
replyPort.postMessage(msg.element)
|
||||
}
|
||||
|
||||
// We close the port when we're done to indicate to the other end that we
|
||||
// won't be sending any more messages. This isn't strictly necessary--if we
|
||||
// didn't explicitly close the port, it would eventually be garbage
|
||||
// collected, which would also trigger the 'close' event in the renderer.
|
||||
replyPort.close()
|
||||
})
|
||||
```
|
||||
|
||||
### Communicating directly between the main process and the main world of a context-isolated page
|
||||
|
||||
When [context isolation][] is enabled, IPC messages from the main process to
|
||||
the renderer are delivered to the isolated world, rather than to the main
|
||||
world. Sometimes you want to deliver messages to the main world directly,
|
||||
without having to step through the isolated world.
|
||||
|
||||
```js
|
||||
// main.js ///////////////////////////////////////////////////////////////////
|
||||
const { BrowserWindow, app, MessageChannelMain } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
// Create a BrowserWindow with contextIsolation enabled.
|
||||
const bw = new BrowserWindow({
|
||||
webPreferences: {
|
||||
contextIsolation: true,
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
}
|
||||
})
|
||||
bw.loadURL('index.html')
|
||||
|
||||
// We'll be sending one end of this channel to the main world of the
|
||||
// context-isolated page.
|
||||
const { port1, port2 } = new MessageChannelMain()
|
||||
|
||||
// It's OK to send a message on the channel before the other end has
|
||||
// registered a listener. Messages will be queued until a listener is
|
||||
// registered.
|
||||
port2.postMessage({ test: 21 })
|
||||
|
||||
// We can also receive messages from the main world of the renderer.
|
||||
port2.on('message', (event) => {
|
||||
console.log('from renderer main world:', event.data)
|
||||
})
|
||||
port2.start()
|
||||
|
||||
// The preload script will receive this IPC message and transfer the port
|
||||
// over to the main world.
|
||||
bw.webContents.postMessage('main-world-port', null, [port1])
|
||||
})
|
||||
```
|
||||
|
||||
```js
|
||||
// preload.js ////////////////////////////////////////////////////////////////
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
// We need to wait until the main world is ready to receive the message before
|
||||
// sending the port. We create this promise in the preload so it's guaranteed
|
||||
// to register the onload listener before the load event is fired.
|
||||
const windowLoaded = new Promise(resolve => {
|
||||
window.onload = resolve
|
||||
})
|
||||
|
||||
ipcRenderer.on('main-world-port', async (event) => {
|
||||
await windowLoaded
|
||||
// We use regular window.postMessage to transfer the port from the isolated
|
||||
// world to the main world.
|
||||
window.postMessage('main-world-port', '*', event.ports)
|
||||
})
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- index.html ------------------------------------------------------------->
|
||||
<script>
|
||||
window.onmessage = (event) => {
|
||||
// event.source === window means the message is coming from the preload
|
||||
// script, as opposed to from an <iframe> or other source.
|
||||
if (event.source === window && event.data === 'main-world-port') {
|
||||
const [ port ] = event.ports
|
||||
// Once we have the port, we can communicate directly with the main
|
||||
// process.
|
||||
port.onmessage = (event) => {
|
||||
console.log('from main process:', event.data)
|
||||
port.postMessage(event.data * 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
[context isolation]: context-isolation.md
|
||||
[`ipcRenderer.postMessage`]: ../api/ipc-renderer.md#ipcrendererpostmessagechannel-message-transfer
|
||||
[`WebContents.postMessage`]: ../api/web-contents.md#contentspostmessagechannel-message-transfer
|
||||
[`MessagePortMain`]: ../api/message-port-main.md
|
||||
[`MessageChannelMain`]: ../api/message-channel-main.md
|
||||
[`MessagePort`]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort
|
||||
[Channel Messaging API]: https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API
|
||||
@@ -25,7 +25,7 @@ Starting with a working application from the
|
||||
|
||||
and add the following lines to the `renderer.js` file:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
const { ipcRenderer } = require('electron')
|
||||
|
||||
document.getElementById('drag').ondragstart = (event) => {
|
||||
@@ -40,7 +40,7 @@ and forward the information to the Main process.
|
||||
In the Main process(`main.js` file), expand the received event with a path to the file that is
|
||||
being dragged and an icon:
|
||||
|
||||
```javascript
|
||||
```javascript fiddle='docs/fiddles/features/drag-and-drop'
|
||||
const { ipcMain } = require('electron')
|
||||
|
||||
ipcMain.on('ondragstart', (event, filePath) => {
|
||||
@@ -52,7 +52,7 @@ ipcMain.on('ondragstart', (event, filePath) => {
|
||||
```
|
||||
|
||||
After launching the Electron application, try dragging and dropping
|
||||
the item from the BroswerWindow onto your desktop. In this guide,
|
||||
the item from the BrowserWindow onto your desktop. In this guide,
|
||||
the item is a Markdown file located in the root of the project:
|
||||
|
||||

|
||||
|
||||
@@ -28,7 +28,7 @@ Assuming you have a working Electron application from the
|
||||
|
||||
and add the `renderer.js` file:
|
||||
|
||||
```js
|
||||
```javascript fiddle='docs/fiddles/features/notifications/renderer'
|
||||
const myNotification = new Notification('Title', {
|
||||
body: 'Notification from the Renderer process'
|
||||
})
|
||||
@@ -52,7 +52,7 @@ message that was generated after triggering the `onclick` event:
|
||||
Starting with a working application from the
|
||||
[Quick Start Guide](quick-start.md), update the `main.js` file with the following lines:
|
||||
|
||||
```js
|
||||
```javascript fiddle='docs/fiddles/features/notifications/main'
|
||||
const { Notification } = require('electron')
|
||||
|
||||
function showNotification () {
|
||||
|
||||
@@ -1,59 +1,67 @@
|
||||
# Offscreen Rendering
|
||||
|
||||
Offscreen rendering lets you obtain the content of a browser window in a bitmap,
|
||||
so it can be rendered anywhere, for example on a texture in a 3D scene. The
|
||||
offscreen rendering in Electron uses a similar approach than the [Chromium
|
||||
Embedded Framework](https://bitbucket.org/chromiumembedded/cef) project.
|
||||
## Overview
|
||||
|
||||
Two modes of rendering can be used and only the dirty area is passed in the
|
||||
`'paint'` event to be more efficient. The rendering can be stopped, continued
|
||||
and the frame rate can be set. The specified frame rate is a top limit value,
|
||||
when there is nothing happening on a webpage, no frames are generated. The
|
||||
maximum frame rate is 240, because above that there is no benefit, only
|
||||
performance loss.
|
||||
Offscreen rendering lets you obtain the content of a `BrowserWindow` in a
|
||||
bitmap, so it can be rendered anywhere, for example, on texture in a 3D scene.
|
||||
The offscreen rendering in Electron uses a similar approach to that of the
|
||||
[Chromium Embedded Framework](https://bitbucket.org/chromiumembedded/cef)
|
||||
project.
|
||||
|
||||
**Note:** An offscreen window is always created as a [Frameless Window](../api/frameless-window.md).
|
||||
*Notes*:
|
||||
|
||||
## Rendering Modes
|
||||
* There are two rendering modes that can be used (see the section below) and only
|
||||
the dirty area is passed to the `paint` event to be more efficient.
|
||||
* You can stop/continue the rendering as well as set the frame rate.
|
||||
* The maximum frame rate is 240 because greater values bring only performance
|
||||
losses with no benefits.
|
||||
* When nothing is happening on a webpage, no frames are generated.
|
||||
* An offscreen window is always created as a
|
||||
[Frameless Window](../api/frameless-window.md).
|
||||
|
||||
### GPU accelerated
|
||||
### Rendering Modes
|
||||
|
||||
#### GPU accelerated
|
||||
|
||||
GPU accelerated rendering means that the GPU is used for composition. Because of
|
||||
that the frame has to be copied from the GPU which requires more performance,
|
||||
thus this mode is quite a bit slower than the other one. The benefit of this
|
||||
that, the frame has to be copied from the GPU which requires more resources,
|
||||
thus this mode is slower than the Software output device. The benefit of this
|
||||
mode is that WebGL and 3D CSS animations are supported.
|
||||
|
||||
### Software output device
|
||||
#### Software output device
|
||||
|
||||
This mode uses a software output device for rendering in the CPU, so the frame
|
||||
generation is much faster, thus this mode is preferred over the GPU accelerated
|
||||
one.
|
||||
generation is much faster. As a result, this mode is preferred over the GPU
|
||||
accelerated one.
|
||||
|
||||
To enable this mode GPU acceleration has to be disabled by calling the
|
||||
To enable this mode, GPU acceleration has to be disabled by calling the
|
||||
[`app.disableHardwareAcceleration()`][disablehardwareacceleration] API.
|
||||
|
||||
## Usage
|
||||
## Example
|
||||
|
||||
``` javascript
|
||||
Starting with a working application from the
|
||||
[Quick Start Guide](quick-start.md), add the following lines to the
|
||||
`main.js` file:
|
||||
|
||||
```javascript fiddle='docs/fiddles/features/offscreen-rendering'
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
const fs = require('fs')
|
||||
|
||||
app.disableHardwareAcceleration()
|
||||
|
||||
let win
|
||||
|
||||
app.whenReady().then(() => {
|
||||
win = new BrowserWindow({
|
||||
webPreferences: {
|
||||
offscreen: true
|
||||
}
|
||||
})
|
||||
win = new BrowserWindow({ webPreferences: { offscreen: true } })
|
||||
|
||||
win.loadURL('http://github.com')
|
||||
win.loadURL('https://github.com')
|
||||
win.webContents.on('paint', (event, dirty, image) => {
|
||||
// updateBitmap(dirty, image.getBitmap())
|
||||
fs.writeFileSync('ex.png', image.toPNG())
|
||||
})
|
||||
win.webContents.setFrameRate(30)
|
||||
win.webContents.setFrameRate(60)
|
||||
})
|
||||
```
|
||||
|
||||
After launching the Electron application, navigate to your application's
|
||||
working folder.
|
||||
[disablehardwareacceleration]: ../api/app.md#appdisablehardwareacceleration
|
||||
|
||||
@@ -34,11 +34,11 @@ let onlineStatusWindow
|
||||
|
||||
app.whenReady().then(() => {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false })
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/index.html`)
|
||||
})
|
||||
```
|
||||
|
||||
create the `online-status.html` file and add the following line before the
|
||||
in the `index.html` file, add the following line before the
|
||||
closing `</body>` tag:
|
||||
|
||||
```html
|
||||
@@ -47,7 +47,7 @@ closing `</body>` tag:
|
||||
|
||||
and add the `renderer.js` file:
|
||||
|
||||
```javascript
|
||||
```javascript fiddle='docs/fiddles/features/online-detection/renderer'
|
||||
const alertOnlineStatus = () => { window.alert(navigator.onLine ? 'online' : 'offline') }
|
||||
|
||||
window.addEventListener('online', alertOnlineStatus)
|
||||
@@ -78,7 +78,7 @@ let onlineStatusWindow
|
||||
|
||||
app.whenReady().then(() => {
|
||||
onlineStatusWindow = new BrowserWindow({ width: 0, height: 0, show: false, webPreferences: { nodeIntegration: true } })
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/online-status.html`)
|
||||
onlineStatusWindow.loadURL(`file://${__dirname}/index.html`)
|
||||
})
|
||||
|
||||
ipcMain.on('online-status-changed', (event, status) => {
|
||||
@@ -86,7 +86,7 @@ ipcMain.on('online-status-changed', (event, status) => {
|
||||
})
|
||||
```
|
||||
|
||||
create the `online-status.html` file and add the following line before the
|
||||
in the `index.html` file, add the following line before the
|
||||
closing `</body>` tag:
|
||||
|
||||
```html
|
||||
@@ -95,7 +95,7 @@ closing `</body>` tag:
|
||||
|
||||
and add the `renderer.js` file:
|
||||
|
||||
```javascript
|
||||
```javascript fiddle='docs/fiddles/features/online-detection/main'
|
||||
const { ipcRenderer } = require('electron')
|
||||
const updateOnlineStatus = () => { ipcRenderer.send('online-status-changed', navigator.onLine ? 'online' : 'offline') }
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ Starting with a working application from the
|
||||
[Quick Start Guide](quick-start.md), add the following lines to the
|
||||
`main.js` file:
|
||||
|
||||
```javascript
|
||||
```javascript fiddle='docs/fiddles/features/progress-bar'
|
||||
const { BrowserWindow } = require('electron')
|
||||
const win = new BrowserWindow()
|
||||
|
||||
|
||||
@@ -28,10 +28,11 @@ If both commands succeeded, you are ready to install Electron.
|
||||
|
||||
From a development perspective, an Electron application is essentially a Node.js application. This means that the starting point of your Electron application will be a `package.json` file like in any other Node.js application. A minimal Electron application has the following structure:
|
||||
|
||||
```plain
|
||||
```plaintext
|
||||
my-electron-app/
|
||||
├── package.json
|
||||
├── main.js
|
||||
├── preload.js
|
||||
└── index.html
|
||||
```
|
||||
|
||||
@@ -53,52 +54,55 @@ The main script specifies the entry point of your Electron application (in our c
|
||||
|
||||
The main script may look as follows:
|
||||
|
||||
```js
|
||||
```javascript fiddle='docs/fiddles/quick-start'
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
function createWindow () {
|
||||
const win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
}
|
||||
})
|
||||
|
||||
win.loadFile('index.html')
|
||||
win.webContents.openDevTools()
|
||||
}
|
||||
|
||||
app.whenReady().then(createWindow)
|
||||
app.whenReady().then(() => {
|
||||
createWindow()
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
##### What is going on above?
|
||||
|
||||
1. Line 1: First, you import the `app` and `BrowserWindow` modules of the `electron` package to be able to manage your application's lifecycle events, as well as create and control browser windows.
|
||||
2. Line 3: After that, you define a function that creates a [new browser window](../api/browser-window.md#new-browserwindowoptions) with node integration enabled, loads `index.html` file into this window (line 12, we will discuss the file later) and opens Developer Tools (line 13).
|
||||
3. Line 16: You create a new browser window by invoking the `createWindow` function once the Electron application [is initialized](../api/app.md#appwhenready).
|
||||
4. Line 18: You add a new listener that tries to quit the application when it no longer has any open windows. This listener is a no-op on macOS due to the operating system's [window management behavior](https://support.apple.com/en-ca/guide/mac-help/mchlp2469/mac).
|
||||
5. Line 24: You add a new listener that creates a new browser window only if when the application has no visible windows after being activated. For example, after launching the application for the first time, or re-launching the already running application.
|
||||
2. Line 2: Second, you import the `path` package which provides utility functions for file paths.
|
||||
3. Line 4: After that, you define a function that creates a [new browser window](../api/browser-window.md#new-browserwindowoptions) with a preload script, loads `index.html` file into this window (line 13, we will discuss the file later).
|
||||
4. Line 16: You create a new browser window by invoking the `createWindow` function once the Electron application [is initialized](../api/app.md#appwhenready).
|
||||
5. Line 18: You add a new listener that creates a new browser window only if when the application has no visible windows after being activated. For example, after launching the application for the first time, or re-launching the already running application.
|
||||
6. Line 25: You add a new listener that tries to quit the application when it no longer has any open windows. This listener is a no-op on macOS due to the operating system's [window management behavior](https://support.apple.com/en-ca/guide/mac-help/mchlp2469/mac).
|
||||
|
||||
#### Create a web page
|
||||
|
||||
This is the web page you want to display once the application is initialized. This web page represents the Renderer process. You can create multiple browser windows, where each window uses its own independent Renderer. Each window can optionally be granted with full access to Node.js API through the `nodeIntegration` preference.
|
||||
This is the web page you want to display once the application is initialized. This web page represents the Renderer process. You can create multiple browser windows, where each window uses its own independent Renderer. You can optionally grant access to additional Node.js APIs by exposing them from your preload script.
|
||||
|
||||
The `index.html` page looks as follows:
|
||||
|
||||
```html
|
||||
```html fiddle='docs/fiddles/quick-start'
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -108,13 +112,39 @@ The `index.html` page looks as follows:
|
||||
</head>
|
||||
<body style="background: white;">
|
||||
<h1>Hello World!</h1>
|
||||
We are using node <script>document.write(process.versions.node)</script>,
|
||||
Chrome <script>document.write(process.versions.chrome)</script>,
|
||||
and Electron <script>document.write(process.versions.electron)</script>.
|
||||
<p>
|
||||
We are using Node.js <span id="node-version"></span>,
|
||||
Chromium <span id="chrome-version"></span>,
|
||||
and Electron <span id="electron-version"></span>.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
#### Define a preload script
|
||||
|
||||
Your preload script (in our case, the `preload.js` file) acts as a bridge between Node.js and your web page. It allows you to expose specific APIs and behaviors to your web page rather than insecurely exposing the entire Node.js API. In this example we will use the preload script to read version information from the `process` object and update the web page with that info.
|
||||
|
||||
```javascript fiddle='docs/fiddles/quick-start'
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const replaceText = (selector, text) => {
|
||||
const element = document.getElementById(selector)
|
||||
if (element) element.innerText = text
|
||||
}
|
||||
|
||||
for (const type of ['chrome', 'node', 'electron']) {
|
||||
replaceText(`${type}-version`, process.versions[type])
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
##### What's going on above?
|
||||
|
||||
1. On line 1: First you define an event listener that tells you when the web page has loaded
|
||||
2. On line 2: Second you define a utility function used to set the text of the placeholders in the `index.html`
|
||||
3. On line 7: Next you loop through the list of components whose version you want to display
|
||||
4. On line 8: Finally, you call `replaceText` to look up the version placeholders in `index.html` and set their text value to the values from `process.versions`
|
||||
|
||||
#### Modify your package.json file
|
||||
|
||||
Your Electron application uses the `package.json` file as the main entry point (as any other Node.js application). The main script of your application is `main.js`, so modify the `package.json` file accordingly:
|
||||
@@ -123,18 +153,24 @@ Your Electron application uses the `package.json` file as the main entry point (
|
||||
{
|
||||
"name": "my-electron-app",
|
||||
"version": "0.1.0",
|
||||
"author": "your name",
|
||||
"description": "My Electron app",
|
||||
"main": "main.js"
|
||||
}
|
||||
```
|
||||
|
||||
> NOTE: If the `main` field is omitted, Electron will attempt to load an `index.js` file from the directory containing `package.json`.
|
||||
|
||||
> NOTE: The `author` and `description` fields are required for packaging, otherwise error will occur when running `npm run make`.
|
||||
|
||||
By default, the `npm start` command will run the main script with Node.js. To run the script with Electron, you need to change it as such:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my-electron-app",
|
||||
"version": "0.1.0",
|
||||
"author": "your name",
|
||||
"description": "My Electron app",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "electron ."
|
||||
@@ -160,7 +196,8 @@ The simplest and the fastest way to distribute your newly created app is using
|
||||
1. Import Electron Forge to your app folder:
|
||||
|
||||
```sh
|
||||
npx @electron-forge/cli import
|
||||
npm install --save-dev @electron-forge/cli
|
||||
npx electron-forge import
|
||||
|
||||
✔ Checking your system
|
||||
✔ Initializing Git Repository
|
||||
@@ -275,7 +312,7 @@ ipcRenderer.invoke('perform-action', ...args)
|
||||
|
||||
##### Node.js API
|
||||
|
||||
> NOTE: To access the Node.js API from the Renderer process, you need to set the `nodeIntegration` preference to `true`.
|
||||
> NOTE: To access the Node.js API from the Renderer process, you need to set the `nodeIntegration` preference to `true` and the `contextIsolation` preference to `false`. Please note that access to the Node.js API in any renderer that loads remote content is not recommended for [security reasons](../tutorial/security.md#2-do-not-enable-nodejs-integration-for-remote-content).
|
||||
|
||||
Electron exposes full access to Node.js API and its modules both in the Main and the Renderer processes. For example, you can read all the files from the root directory:
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ Starting with a working application from the
|
||||
[Quick Start Guide](quick-start.md), add the following lines to the
|
||||
`main.js` file:
|
||||
|
||||
```javascript
|
||||
```javascript fiddle='docs/fiddles/features/recent-documents'
|
||||
const { app } = require('electron')
|
||||
|
||||
app.addRecentDocument('/Users/USERNAME/Desktop/work.type')
|
||||
|
||||
@@ -24,7 +24,7 @@ Starting with a working application from the
|
||||
[Quick Start Guide](quick-start.md), add the following lines to the
|
||||
`main.js` file:
|
||||
|
||||
```javascript
|
||||
```javascript fiddle='docs/fiddles/features/represented-file'
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
|
||||
app.whenReady().then(() => {
|
||||
|
||||
@@ -44,7 +44,7 @@ Chromium shared library and Node.js. Vulnerabilities affecting these components
|
||||
may impact the security of your application. By updating Electron to the latest
|
||||
version, you ensure that critical vulnerabilities (such as *nodeIntegration bypasses*)
|
||||
are already patched and cannot be exploited in your application. For more information,
|
||||
see "[Use a current version of Electron](#17-use-a-current-version-of-electron)".
|
||||
see "[Use a current version of Electron](#15-use-a-current-version-of-electron)".
|
||||
|
||||
* **Evaluate your dependencies.** While NPM provides half a million reusable packages,
|
||||
it is your responsibility to choose trusted 3rd-party libraries. If you use outdated
|
||||
@@ -99,9 +99,7 @@ You should at least follow these steps to improve the security of your applicati
|
||||
12. [Disable or limit navigation](#12-disable-or-limit-navigation)
|
||||
13. [Disable or limit creation of new windows](#13-disable-or-limit-creation-of-new-windows)
|
||||
14. [Do not use `openExternal` with untrusted content](#14-do-not-use-openexternal-with-untrusted-content)
|
||||
15. [Disable the `remote` module](#15-disable-the-remote-module)
|
||||
16. [Filter the `remote` module](#16-filter-the-remote-module)
|
||||
17. [Use a current version of Electron](#17-use-a-current-version-of-electron)
|
||||
15. [Use a current version of Electron](#15-use-a-current-version-of-electron)
|
||||
|
||||
To automate the detection of misconfigurations and insecure patterns, it is
|
||||
possible to use
|
||||
@@ -665,134 +663,7 @@ const { shell } = require('electron')
|
||||
shell.openExternal('https://example.com/index.html')
|
||||
```
|
||||
|
||||
## 15) Disable the `remote` module
|
||||
|
||||
The `remote` module provides a way for the renderer processes to
|
||||
access APIs normally only available in the main process. Using it, a
|
||||
renderer can invoke methods of a main process object without explicitly sending
|
||||
inter-process messages. If your desktop application does not run untrusted
|
||||
content, this can be a useful way to have your renderer processes access and
|
||||
work with modules that are only available to the main process, such as
|
||||
GUI-related modules (dialogs, menus, etc.).
|
||||
|
||||
However, if your app can run untrusted content and even if you
|
||||
[sandbox][sandbox] your renderer processes accordingly, the `remote` module
|
||||
makes it easy for malicious code to escape the sandbox and have access to
|
||||
system resources via the higher privileges of the main process. Therefore,
|
||||
it should be disabled in such circumstances.
|
||||
|
||||
### Why?
|
||||
|
||||
`remote` uses an internal IPC channel to communicate with the main process.
|
||||
"Prototype pollution" attacks can grant malicious code access to the internal
|
||||
IPC channel, which can then be used to escape the sandbox by mimicking `remote`
|
||||
IPC messages and getting access to main process modules running with higher
|
||||
privileges.
|
||||
|
||||
Additionally, it's possible for preload scripts to accidentally leak modules to a
|
||||
sandboxed renderer. Leaking `remote` arms malicious code with a multitude
|
||||
of main process modules with which to perform an attack.
|
||||
|
||||
Disabling the `remote` module eliminates these attack vectors. Enabling
|
||||
context isolation also prevents the "prototype pollution" attacks from
|
||||
succeeding.
|
||||
|
||||
### How?
|
||||
|
||||
```js
|
||||
// Bad if the renderer can run untrusted content
|
||||
const mainWindow = new BrowserWindow({
|
||||
webPreferences: {
|
||||
enableRemoteModule: true
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
```js
|
||||
// Good
|
||||
const mainWindow = new BrowserWindow({
|
||||
webPreferences: {
|
||||
enableRemoteModule: false
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- Bad if the renderer can run untrusted content -->
|
||||
<webview enableremotemodule="true" src="page.html"></webview>
|
||||
|
||||
<!-- Good -->
|
||||
<webview enableremotemodule="false" src="page.html"></webview>
|
||||
```
|
||||
|
||||
> **Note:** The default value of `enableRemoteModule` is `false` starting
|
||||
> from Electron 10. For prior versions, you need to explicitly disable
|
||||
> the `remote` module by the means above.
|
||||
|
||||
## 16) Filter the `remote` module
|
||||
|
||||
If you cannot disable the `remote` module, you should filter the globals,
|
||||
Node, and Electron modules (so-called built-ins) accessible via `remote`
|
||||
that your application does not require. This can be done by blocking
|
||||
certain modules entirely and by replacing others with proxies that
|
||||
expose only the functionality that your app needs.
|
||||
|
||||
### Why?
|
||||
|
||||
Due to the system access privileges of the main process, functionality
|
||||
provided by the main process modules may be dangerous in the hands of
|
||||
malicious code running in a compromised renderer process. By limiting
|
||||
the set of accessible modules to the minimum that your app needs and
|
||||
filtering out the others, you reduce the toolset that malicious code
|
||||
can use to attack the system.
|
||||
|
||||
Note that the safest option is to
|
||||
[fully disable the remote module](#15-disable-the-remote-module). If
|
||||
you choose to filter access rather than completely disable the module,
|
||||
you must be very careful to ensure that no escalation of privilege is
|
||||
possible through the modules you allow past the filter.
|
||||
|
||||
### How?
|
||||
|
||||
```js
|
||||
const readOnlyFsProxy = require(/* ... */) // exposes only file read functionality
|
||||
|
||||
const allowedModules = new Set(['crypto'])
|
||||
const proxiedModules = new Map(['fs', readOnlyFsProxy])
|
||||
const allowedElectronModules = new Set(['shell'])
|
||||
const allowedGlobals = new Set()
|
||||
|
||||
app.on('remote-require', (event, webContents, moduleName) => {
|
||||
if (proxiedModules.has(moduleName)) {
|
||||
event.returnValue = proxiedModules.get(moduleName)
|
||||
}
|
||||
if (!allowedModules.has(moduleName)) {
|
||||
event.preventDefault()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('remote-get-builtin', (event, webContents, moduleName) => {
|
||||
if (!allowedElectronModules.has(moduleName)) {
|
||||
event.preventDefault()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('remote-get-global', (event, webContents, globalName) => {
|
||||
if (!allowedGlobals.has(globalName)) {
|
||||
event.preventDefault()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('remote-get-current-window', (event, webContents) => {
|
||||
event.preventDefault()
|
||||
})
|
||||
|
||||
app.on('remote-get-current-web-contents', (event, webContents) => {
|
||||
event.preventDefault()
|
||||
})
|
||||
```
|
||||
|
||||
## 17) Use a current version of Electron
|
||||
## 15) Use a current version of Electron
|
||||
|
||||
You should strive for always using the latest available version of Electron.
|
||||
Whenever a new major version is released, you should attempt to update your
|
||||
|
||||
@@ -83,7 +83,7 @@ snap(options)
|
||||
|
||||
### Step 1: Create Sample Snapcraft Project
|
||||
|
||||
Create your project directory and add add the following to `snap/snapcraft.yaml`:
|
||||
Create your project directory and add the following to `snap/snapcraft.yaml`:
|
||||
|
||||
```yaml
|
||||
name: electron-packager-hello-world
|
||||
|
||||
@@ -71,4 +71,4 @@ Although the spellchecker itself does not send any typings, words or user input
|
||||
myWindow.session.setSpellCheckerDictionaryDownloadURL('https://example.com/dictionaries/')
|
||||
```
|
||||
|
||||
Check out the docs for [`session.setSpellCheckerDictionaryDownloadURL`](https://www.electronjs.org/docs/api/session#sessetspellcheckerdictionarydownloadurlurl) for more information on where to get the dictionary files from and how you need to host them.
|
||||
Check out the docs for [`session.setSpellCheckerDictionaryDownloadURL`](../api/session.md#sessetspellcheckerdictionarydownloadurlurl) for more information on where to get the dictionary files from and how you need to host them.
|
||||
|
||||
@@ -10,21 +10,21 @@ for answers to questions,
|
||||
or to join in discussion with other developers who use Electron,
|
||||
you can interact with the community in these locations:
|
||||
|
||||
- [`Electron's Discord`](https://discord.com/invite/electron) has channels for:
|
||||
- Getting help
|
||||
- Ecosystem apps like [Electron Forge](https://github.com/electron-userland/electron-forge) and [Electron Fiddle](https://github.com/electron/fiddle)
|
||||
- Sharing ideas with other Electron app developers
|
||||
- And more!
|
||||
- [`electron`](https://discuss.atom.io/c/electron) category on the Atom forums
|
||||
- `#atom-shell` channel on Freenode
|
||||
- `#electron` channel on [Atom's Slack](https://discuss.atom.io/t/join-us-on-slack/16638?source_topic_id=25406)
|
||||
- [`electron-ru`](https://telegram.me/electron_ru) *(Russian)*
|
||||
- [`electron-br`](https://electron-br.slack.com) *(Brazilian Portuguese)*
|
||||
- [`electron-kr`](https://electron-kr.github.io/electron-kr) *(Korean)*
|
||||
- [`electron-jp`](https://electron-jp.slack.com) *(Japanese)*
|
||||
- [`electron-tr`](https://electron-tr.herokuapp.com) *(Turkish)*
|
||||
- [`electron-id`](https://electron-id.slack.com) *(Indonesia)*
|
||||
- [`electron-pl`](https://electronpl.github.io) *(Poland)*
|
||||
* [`Electron's Discord`](https://discord.com/invite/electron) has channels for:
|
||||
* Getting help
|
||||
* Ecosystem apps like [Electron Forge](https://github.com/electron-userland/electron-forge) and [Electron Fiddle](https://github.com/electron/fiddle)
|
||||
* Sharing ideas with other Electron app developers
|
||||
* And more!
|
||||
* [`electron`](https://discuss.atom.io/c/electron) category on the Atom forums
|
||||
* `#atom-shell` channel on Freenode
|
||||
* `#electron` channel on [Atom's Slack](https://discuss.atom.io/t/join-us-on-slack/16638?source_topic_id=25406)
|
||||
* [`electron-ru`](https://telegram.me/electron_ru) *(Russian)*
|
||||
* [`electron-br`](https://electron-br.slack.com) *(Brazilian Portuguese)*
|
||||
* [`electron-kr`](https://electron-kr.github.io/electron-kr) *(Korean)*
|
||||
* [`electron-jp`](https://electron-jp.slack.com) *(Japanese)*
|
||||
* [`electron-tr`](https://electron-tr.herokuapp.com) *(Turkish)*
|
||||
* [`electron-id`](https://electron-id.slack.com) *(Indonesia)*
|
||||
* [`electron-pl`](https://electronpl.github.io) *(Poland)*
|
||||
|
||||
If you'd like to contribute to Electron,
|
||||
see the [contributing document](https://github.com/electron/electron/blob/master/CONTRIBUTING.md).
|
||||
@@ -64,9 +64,9 @@ until the maintainers feel the maintenance burden is too high to continue doing
|
||||
|
||||
### Currently supported versions
|
||||
|
||||
- 11.x.y
|
||||
- 10.x.y
|
||||
- 9.x.y
|
||||
* 12.x.y
|
||||
* 11.x.y
|
||||
* 10.x.y
|
||||
|
||||
### End-of-life
|
||||
|
||||
@@ -94,7 +94,9 @@ Following platforms are supported by Electron:
|
||||
### macOS
|
||||
|
||||
Only 64bit binaries are provided for macOS, and the minimum macOS version
|
||||
supported is macOS 10.10 (Yosemite).
|
||||
supported is macOS 10.11 (El Capitan).
|
||||
|
||||
Native support for Apple Silicon (`arm64`) devices was added in Electron 11.0.0.
|
||||
|
||||
### Windows
|
||||
|
||||
@@ -102,7 +104,7 @@ Windows 7 and later are supported, older operating systems are not supported
|
||||
(and do not work).
|
||||
|
||||
Both `ia32` (`x86`) and `x64` (`amd64`) binaries are provided for Windows.
|
||||
[Electron 6.0.8 and later add native support for Windows on Arm (`arm64`) devices](windows-arm.md).
|
||||
[Native support for Windows on Arm (`arm64`) devices was added in Electron 6.0.8.](windows-arm.md).
|
||||
Running apps packaged with previous versions is possible using the ia32 binary.
|
||||
|
||||
### Linux
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# Using Native Node Modules
|
||||
|
||||
Native Node modules are supported by Electron, but since Electron is very
|
||||
likely to use a different V8 version from the Node binary installed on your
|
||||
system, the modules you use will need to be recompiled for Electron. Otherwise,
|
||||
Native Node.js modules are supported by Electron, but since Electron has a different
|
||||
[application binary interface (ABI)][abi] from a given Node.js binary (due to
|
||||
differences such as using Chromium's BoringSSL instead of OpenSSL), the native
|
||||
modules you use will need to be recompiled for Electron. Otherwise,
|
||||
you will get the following class of error when you try to run your app:
|
||||
|
||||
```sh
|
||||
@@ -23,9 +24,11 @@ You can install modules like other Node projects, and then rebuild the modules
|
||||
for Electron with the [`electron-rebuild`][electron-rebuild] package. This
|
||||
module can automatically determine the version of Electron and handle the
|
||||
manual steps of downloading headers and rebuilding native modules for your app.
|
||||
If you are using [Electron Forge][electron-forge], this tool is used automatically
|
||||
in both development mode and when making distributables.
|
||||
|
||||
For example, to install `electron-rebuild` and then rebuild modules with it
|
||||
via the command line:
|
||||
For example, to install the standalone `electron-rebuild` tool and then rebuild
|
||||
modules with it via the command line:
|
||||
|
||||
```sh
|
||||
npm install --save-dev electron-rebuild
|
||||
@@ -33,12 +36,12 @@ npm install --save-dev electron-rebuild
|
||||
# Every time you run "npm install", run this:
|
||||
./node_modules/.bin/electron-rebuild
|
||||
|
||||
# On Windows if you have trouble, try:
|
||||
# If you have trouble on Windows, try:
|
||||
.\node_modules\.bin\electron-rebuild.cmd
|
||||
```
|
||||
|
||||
For more information on usage and integration with other tools, consult the
|
||||
project's README.
|
||||
For more information on usage and integration with other tools such as [Electron
|
||||
Packager][electron-packager], consult the project's README.
|
||||
|
||||
### Using `npm`
|
||||
|
||||
@@ -129,13 +132,13 @@ should look like this:
|
||||
|
||||
In particular, it's important that:
|
||||
|
||||
- you link against `node.lib` from _Electron_ and not Node. If you link against
|
||||
* you link against `node.lib` from _Electron_ and not Node. If you link against
|
||||
the wrong `node.lib` you will get load-time errors when you require the
|
||||
module in Electron.
|
||||
- you include the flag `/DELAYLOAD:node.exe`. If the `node.exe` link is not
|
||||
* you include the flag `/DELAYLOAD:node.exe`. If the `node.exe` link is not
|
||||
delayed, then the delay-load hook won't get a chance to fire and the node
|
||||
symbols won't be correctly resolved.
|
||||
- `win_delay_load_hook.obj` is linked directly into the final DLL. If the hook
|
||||
* `win_delay_load_hook.obj` is linked directly into the final DLL. If the hook
|
||||
is set up in a dependent DLL, it won't fire at the right time.
|
||||
|
||||
See [`node-gyp`](https://github.com/nodejs/node-gyp/blob/e2401e1395bef1d3c8acec268b42dc5fb71c4a38/src/win_delay_load_hook.cc)
|
||||
@@ -147,23 +150,25 @@ for an example delay-load hook if you're implementing your own.
|
||||
native Node modules with prebuilt binaries for multiple versions of Node
|
||||
and Electron.
|
||||
|
||||
If modules provide binaries for the usage in Electron, make sure to omit
|
||||
`--build-from-source` and the `npm_config_build_from_source` environment
|
||||
variable in order to take full advantage of the prebuilt binaries.
|
||||
If the `prebuild`-powered module provide binaries for the usage in Electron,
|
||||
make sure to omit `--build-from-source` and the `npm_config_build_from_source`
|
||||
environment variable in order to take full advantage of the prebuilt binaries.
|
||||
|
||||
## Modules that rely on `node-pre-gyp`
|
||||
|
||||
The [`node-pre-gyp` tool][node-pre-gyp] provides a way to deploy native Node
|
||||
modules with prebuilt binaries, and many popular modules are using it.
|
||||
|
||||
Usually those modules work fine under Electron, but sometimes when Electron uses
|
||||
a newer version of V8 than Node and/or there are ABI changes, bad things may
|
||||
happen. So in general, it is recommended to always build native modules from
|
||||
source code. `electron-rebuild` handles this for you automatically.
|
||||
Sometimes those modules work fine under Electron, but when there are no
|
||||
Electron-specific binaries available, you'll need to build from source.
|
||||
Because of this, it is recommended to use `electron-rebuild` for these modules.
|
||||
|
||||
If you are following the `npm` way of installing modules, then this is done
|
||||
by default, if not, you have to pass `--build-from-source` to `npm`, or set the
|
||||
`npm_config_build_from_source` environment variable.
|
||||
If you are following the `npm` way of installing modules, you'll need to pass
|
||||
`--build-from-source` to `npm`, or set the `npm_config_build_from_source`
|
||||
environment variable.
|
||||
|
||||
[abi]: https://en.wikipedia.org/wiki/Application_binary_interface
|
||||
[electron-rebuild]: https://github.com/electron/electron-rebuild
|
||||
[electron-forge]: https://electronforge.io/
|
||||
[electron-packager]: https://github.com/electron/electron-packager
|
||||
[node-pre-gyp]: https://github.com/mapbox/node-pre-gyp
|
||||
|
||||
@@ -86,12 +86,12 @@ const driver = new webdriver.Builder()
|
||||
// The "9515" is the port opened by chrome driver.
|
||||
.usingServer('http://localhost:9515')
|
||||
.withCapabilities({
|
||||
chromeOptions: {
|
||||
'goog:chromeOptions': {
|
||||
// Here is the path to your Electron binary.
|
||||
binary: '/Path-to-Your-App.app/Contents/MacOS/Electron'
|
||||
}
|
||||
})
|
||||
.forBrowser('electron')
|
||||
.forBrowser('chrome') // note: use .forBrowser('electron') for selenium-webdriver <= 3.6.0
|
||||
.build()
|
||||
|
||||
driver.get('http://www.google.com')
|
||||
|
||||
@@ -20,7 +20,7 @@ and only allow the capabilities you want to support.
|
||||
### WebViews
|
||||
|
||||
> Important Note:
|
||||
[we do not recommend you to use use WebViews](https://www.electronjs.org/docs/api/webview-tag#warning),
|
||||
[we do not recommend you to use WebViews](../api/webview-tag.md#warning),
|
||||
as this tag undergoes dramatic architectural changes that may affect stability
|
||||
of your application. Consider switching to alternatives, like `iframe` and
|
||||
Electron's `BrowserView`, or an architecture that avoids embedded content
|
||||
|
||||
@@ -332,6 +332,8 @@ filenames = {
|
||||
"shell/browser/badging/badge_manager.h",
|
||||
"shell/browser/badging/badge_manager_factory.cc",
|
||||
"shell/browser/badging/badge_manager_factory.h",
|
||||
"shell/browser/bluetooth/electron_bluetooth_delegate.cc",
|
||||
"shell/browser/bluetooth/electron_bluetooth_delegate.h",
|
||||
"shell/browser/browser.cc",
|
||||
"shell/browser/browser.h",
|
||||
"shell/browser/browser_observer.h",
|
||||
@@ -400,6 +402,8 @@ filenames = {
|
||||
"shell/browser/native_window_observer.h",
|
||||
"shell/browser/net/asar/asar_url_loader.cc",
|
||||
"shell/browser/net/asar/asar_url_loader.h",
|
||||
"shell/browser/net/asar/asar_url_loader_factory.cc",
|
||||
"shell/browser/net/asar/asar_url_loader_factory.h",
|
||||
"shell/browser/net/cert_verifier_client.cc",
|
||||
"shell/browser/net/cert_verifier_client.h",
|
||||
"shell/browser/net/electron_url_loader_factory.cc",
|
||||
|
||||
@@ -532,15 +532,17 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
return fs.readFile(realPath, options, callback);
|
||||
}
|
||||
|
||||
const buffer = Buffer.alloc(info.size);
|
||||
const fd = archive.getFd();
|
||||
if (!(fd >= 0)) {
|
||||
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath });
|
||||
nextTick(callback, [error]);
|
||||
return;
|
||||
}
|
||||
|
||||
logASARAccess(asarPath, filePath, info.offset);
|
||||
archive.read(info.offset, info.size).then((buf) => {
|
||||
const buffer = Buffer.from(buf);
|
||||
callback(null, encoding ? buffer.toString(encoding) : buffer);
|
||||
}, (err) => {
|
||||
const error: AsarErrorObject = new Error(`EINVAL, ${err.message} while reading ${filePath} in ${asarPath}`);
|
||||
error.code = 'EINVAL';
|
||||
error.errno = -22;
|
||||
callback(error);
|
||||
fs.read(fd, buffer, 0, info.size, info.offset, (error: Error) => {
|
||||
callback(error, encoding ? buffer.toString(encoding) : buffer);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -573,19 +575,13 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
}
|
||||
|
||||
const { encoding } = options;
|
||||
const buffer = Buffer.alloc(info.size);
|
||||
const fd = archive.getFd();
|
||||
if (!(fd >= 0)) throw createError(AsarError.NOT_FOUND, { asarPath, filePath });
|
||||
|
||||
logASARAccess(asarPath, filePath, info.offset);
|
||||
let arrayBuffer: ArrayBuffer;
|
||||
try {
|
||||
arrayBuffer = archive.readSync(info.offset, info.size);
|
||||
} catch (err) {
|
||||
const error: AsarErrorObject = new Error(`EINVAL, ${err.message} while reading ${filePath} in ${asarPath}`);
|
||||
error.code = 'EINVAL';
|
||||
error.errno = -22;
|
||||
throw error;
|
||||
}
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
return encoding ? buffer.toString(encoding) : buffer;
|
||||
fs.readSync(fd, buffer, 0, info.size, info.offset);
|
||||
return (encoding) ? buffer.toString(encoding) : buffer;
|
||||
};
|
||||
|
||||
const { readdir } = fs;
|
||||
@@ -695,17 +691,12 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
return [str, str.length > 0];
|
||||
}
|
||||
|
||||
const buffer = Buffer.alloc(info.size);
|
||||
const fd = archive.getFd();
|
||||
if (!(fd >= 0)) return [];
|
||||
|
||||
logASARAccess(asarPath, filePath, info.offset);
|
||||
let arrayBuffer: ArrayBuffer;
|
||||
try {
|
||||
arrayBuffer = archive.readSync(info.offset, info.size);
|
||||
} catch (err) {
|
||||
const error: AsarErrorObject = new Error(`EINVAL, ${err.message} while reading ${filePath} in ${asarPath}`);
|
||||
error.code = 'EINVAL';
|
||||
error.errno = -22;
|
||||
throw error;
|
||||
}
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
fs.readSync(fd, buffer, 0, info.size, info.offset);
|
||||
const str = buffer.toString('utf8');
|
||||
return [str, str.length > 0];
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ class CrashReporter {
|
||||
|
||||
if (submitURL == null) throw new Error('submitURL is a required option to crashReporter.start');
|
||||
|
||||
if (!compress) {
|
||||
if (!compress && uploadToServer) {
|
||||
deprecate.log('Sending uncompressed crash reports is deprecated and will be removed in a future version of Electron. Set { compress: true } to opt-in to the new behavior. Crash reports will be uploaded gzipped, which most crash reporting servers support.');
|
||||
}
|
||||
|
||||
|
||||
@@ -119,10 +119,13 @@ class IncomingMessage extends Readable {
|
||||
this._shouldPush = this.push(chunk);
|
||||
}
|
||||
if (this._shouldPush && this._resume) {
|
||||
this._resume();
|
||||
// Reset the callback, so that a new one is used for each
|
||||
// batch of throttled data
|
||||
// batch of throttled data. Do this before calling resume to avoid a
|
||||
// potential race-condition
|
||||
const resume = this._resume;
|
||||
this._resume = null;
|
||||
|
||||
resume();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +188,11 @@ class ChunkedBodyStream extends Writable {
|
||||
this._downstream = pipe;
|
||||
if (this._pendingChunk) {
|
||||
const doneWriting = (maybeError: Error | void) => {
|
||||
// If the underlying request has been aborted, we honeslty don't care about the error
|
||||
// all work should cease as soon as we abort anyway, this error is probably a
|
||||
// "mojo pipe disconnected" error (code=9)
|
||||
if (this._clientRequest._aborted) return;
|
||||
|
||||
const cb = this._pendingCallback!;
|
||||
delete this._pendingCallback;
|
||||
delete this._pendingChunk;
|
||||
|
||||
@@ -7,8 +7,8 @@ const hiddenProperties = Symbol('hidden touch bar props');
|
||||
const extendConstructHook = (target: any, hook: Function) => {
|
||||
const existingHook = target._hook;
|
||||
target._hook = function () {
|
||||
hook.call(this);
|
||||
if (existingHook) existingHook.call(this);
|
||||
hook.call(this);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -135,7 +135,7 @@ class TouchBarGroup extends TouchBarItem<Electron.TouchBarGroupConstructorOption
|
||||
}
|
||||
}
|
||||
for (const item of newChild.orderedItems) {
|
||||
item._addParent(item);
|
||||
item._addParent(self);
|
||||
}
|
||||
})
|
||||
child!: TouchBar;
|
||||
@@ -179,7 +179,7 @@ class TouchBarPopover extends TouchBarItem<Electron.TouchBarPopoverConstructorOp
|
||||
}
|
||||
}
|
||||
for (const item of newChild.orderedItems) {
|
||||
item._addParent(item);
|
||||
item._addParent(self);
|
||||
}
|
||||
})
|
||||
child!: TouchBar;
|
||||
|
||||
@@ -104,6 +104,7 @@ const defaultPrintingSetting = {
|
||||
pagesPerSheet: 1,
|
||||
isFirstRequest: false,
|
||||
previewUIID: 0,
|
||||
// True, if the document source is modifiable. e.g. HTML and not PDF.
|
||||
previewModifiable: true,
|
||||
printToPDF: true,
|
||||
deviceName: 'Save as PDF',
|
||||
@@ -442,7 +443,11 @@ WebContents.prototype._callWindowOpenHandler = function (event: any, url: string
|
||||
event.preventDefault();
|
||||
return null;
|
||||
} else if (response.action === 'allow') {
|
||||
if (typeof response.overrideBrowserWindowOptions === 'object' && response.overrideBrowserWindowOptions !== null) { return response.overrideBrowserWindowOptions; } else { return {}; }
|
||||
if (typeof response.overrideBrowserWindowOptions === 'object' && response.overrideBrowserWindowOptions !== null) {
|
||||
return response.overrideBrowserWindowOptions;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
event.preventDefault();
|
||||
console.error('The window open handler response must be an object with an \'action\' property of \'allow\' or \'deny\'.');
|
||||
@@ -601,20 +606,23 @@ WebContents.prototype._init = function () {
|
||||
if (this.getType() !== 'remote') {
|
||||
// Make new windows requested by links behave like "window.open".
|
||||
this.on('-new-window' as any, (event: any, url: string, frameName: string, disposition: string,
|
||||
rawFeatures: string, referrer: any, postData: PostData) => {
|
||||
openGuestWindow({
|
||||
event,
|
||||
embedder: event.sender,
|
||||
disposition,
|
||||
referrer,
|
||||
postData,
|
||||
overrideBrowserWindowOptions: {},
|
||||
windowOpenArgs: {
|
||||
url,
|
||||
frameName,
|
||||
features: rawFeatures
|
||||
}
|
||||
});
|
||||
rawFeatures: string, referrer: Electron.Referrer, postData: PostData) => {
|
||||
const options = this._callWindowOpenHandler(event, url, frameName, rawFeatures);
|
||||
if (!event.defaultPrevented) {
|
||||
openGuestWindow({
|
||||
event,
|
||||
embedder: event.sender,
|
||||
disposition,
|
||||
referrer,
|
||||
postData,
|
||||
overrideBrowserWindowOptions: options || {},
|
||||
windowOpenArgs: {
|
||||
url,
|
||||
frameName,
|
||||
features: rawFeatures
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let windowOpenOverriddenOptions: BrowserWindowConstructorOptions | null = null;
|
||||
@@ -626,6 +634,7 @@ WebContents.prototype._init = function () {
|
||||
// it's technically a BrowserWindowConstructorOptions option because
|
||||
// we need to access it in the renderer at init time.
|
||||
backgroundColor: windowOpenOverriddenOptions.backgroundColor,
|
||||
transparent: windowOpenOverriddenOptions.transparent,
|
||||
...windowOpenOverriddenOptions.webPreferences
|
||||
} : undefined;
|
||||
this._setNextChildWebPreferences(
|
||||
|
||||
@@ -27,7 +27,7 @@ export const setDefaultApplicationMenu = () => {
|
||||
{
|
||||
label: 'Community Discussions',
|
||||
click: async () => {
|
||||
await shell.openExternal('https://discuss.atom.io/c/electron');
|
||||
await shell.openExternal('https://discord.gg/electron');
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -59,6 +59,7 @@ export function openGuestWindow ({ event, embedder, guest, referrer, disposition
|
||||
windowOpenArgs,
|
||||
additionalFeatures,
|
||||
disposition,
|
||||
postData,
|
||||
referrer
|
||||
});
|
||||
if (didCancelEvent) return;
|
||||
@@ -76,11 +77,14 @@ export function openGuestWindow ({ event, embedder, guest, referrer, disposition
|
||||
webContents: guest,
|
||||
...browserWindowOptions
|
||||
});
|
||||
if (!isNativeWindowOpen) {
|
||||
if (!guest) {
|
||||
// We should only call `loadURL` if the webContents was constructed by us in
|
||||
// the case of BrowserWindowProxy (non-sandboxed, nativeWindowOpen: false),
|
||||
// as navigating to the url when creating the window from an existing
|
||||
// webContents is not necessary (it will navigate there anyway).
|
||||
// This can also happen if we enter this function from OpenURLFromTab, in
|
||||
// which case the browser process is responsible for initiating navigation
|
||||
// in the new window.
|
||||
window.loadURL(url, {
|
||||
httpReferrer: referrer,
|
||||
...(postData && {
|
||||
@@ -148,7 +152,7 @@ function emitDeprecatedNewWindowEvent ({ event, embedder, guest, windowOpenArgs,
|
||||
const isWebViewWithPopupsDisabled = embedder.getType() === 'webview' && (embedder as any).getLastWebPreferences().disablePopups;
|
||||
const postBody = postData ? {
|
||||
data: postData,
|
||||
headers: formatPostDataHeaders(postData)
|
||||
...parseContentTypeFormat(postData)
|
||||
} : null;
|
||||
|
||||
embedder.emit(
|
||||
@@ -281,22 +285,40 @@ function getDeprecatedInheritedOptions (embedder: WebContents) {
|
||||
return inheritableOptions;
|
||||
}
|
||||
|
||||
function formatPostDataHeaders (postData: any) {
|
||||
function formatPostDataHeaders (postData: PostData) {
|
||||
if (!postData) return;
|
||||
|
||||
let extraHeaders = 'content-type: application/x-www-form-urlencoded';
|
||||
const { contentType, boundary } = parseContentTypeFormat(postData);
|
||||
if (boundary != null) { return `content-type: ${contentType}; boundary=${boundary}`; }
|
||||
|
||||
if (postData.length > 0) {
|
||||
const postDataFront = postData[0].bytes.toString();
|
||||
const boundary = /^--.*[^-\r\n]/.exec(
|
||||
postDataFront
|
||||
);
|
||||
if (boundary != null) {
|
||||
extraHeaders = `content-type: multipart/form-data; boundary=${boundary[0].substr(
|
||||
2
|
||||
)}`;
|
||||
return `content-type: ${contentType}`;
|
||||
}
|
||||
|
||||
const MULTIPART_CONTENT_TYPE = 'multipart/form-data';
|
||||
const URL_ENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded';
|
||||
|
||||
// Figure out appropriate headers for post data.
|
||||
const parseContentTypeFormat = function (postData: Exclude<PostData, undefined>) {
|
||||
if (postData.length) {
|
||||
if (postData[0].type === 'rawData') {
|
||||
// For multipart forms, the first element will start with the boundary
|
||||
// notice, which looks something like `------WebKitFormBoundary12345678`
|
||||
// Note, this regex would fail when submitting a urlencoded form with an
|
||||
// input attribute of name="--theKey", but, uhh, don't do that?
|
||||
const postDataFront = postData[0].bytes.toString();
|
||||
const boundary = /^--.*[^-\r\n]/.exec(postDataFront);
|
||||
if (boundary) {
|
||||
return {
|
||||
boundary: boundary[0].substr(2),
|
||||
contentType: MULTIPART_CONTENT_TYPE
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return extraHeaders;
|
||||
}
|
||||
// Either the form submission didn't contain any inputs (the postData array
|
||||
// was empty), or we couldn't find the boundary and thus we can assume this is
|
||||
// a key=value style form.
|
||||
return {
|
||||
contentType: URL_ENCODED_CONTENT_TYPE
|
||||
};
|
||||
};
|
||||
|
||||
@@ -62,7 +62,7 @@ export function parseCommaSeparatedKeyValue (source: string, useSoonToBeDeprecat
|
||||
for (const keyValuePair of source.split(',')) {
|
||||
const [key, value] = keyValuePair.split('=').map(str => str.trim());
|
||||
if (useSoonToBeDeprecatedBehaviorForBareKeys && value === undefined) {
|
||||
bareKeys.push(key);
|
||||
if (key) { bareKeys.push(key); }
|
||||
continue;
|
||||
}
|
||||
parsed[key] = coerce(key, value);
|
||||
|
||||
@@ -48,8 +48,10 @@ class WebFrame extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
const { hasSwitch } = process._linkedBinding('electron_common_command_line');
|
||||
const worldSafeJS = hasSwitch('world-safe-execute-javascript') && hasSwitch('context-isolation');
|
||||
const contextIsolation = binding.getWebPreference(window, 'contextIsolation');
|
||||
const worldSafeExecuteJavaScript = binding.getWebPreference(window, 'worldSafeExecuteJavaScript');
|
||||
|
||||
const worldSafeJS = worldSafeExecuteJavaScript || !contextIsolation;
|
||||
|
||||
// Populate the methods.
|
||||
for (const name in binding) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "electron",
|
||||
"version": "12.0.0-beta.31",
|
||||
"version": "12.0.5",
|
||||
"repository": "https://github.com/electron/electron",
|
||||
"description": "Build cross platform desktop apps with JavaScript, HTML, and CSS",
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
expose_ripemd160.patch
|
||||
expose_aes-cfb.patch
|
||||
expose_des-ede3.patch
|
||||
|
||||
40
patches/boringssl/expose_des-ede3.patch
Normal file
40
patches/boringssl/expose_des-ede3.patch
Normal file
@@ -0,0 +1,40 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jeremy Rose <nornagon@nornagon.net>
|
||||
Date: Wed, 24 Feb 2021 11:08:34 -0800
|
||||
Subject: expose des-ede3
|
||||
|
||||
This should be upstreamed.
|
||||
|
||||
diff --git a/crypto/cipher_extra/cipher_extra.c b/crypto/cipher_extra/cipher_extra.c
|
||||
index 588a4773437c311877f275bf3679f9688cda3c46..e771ed6589b4579cc35300d5b2a1b68d92e444f5 100644
|
||||
--- a/crypto/cipher_extra/cipher_extra.c
|
||||
+++ b/crypto/cipher_extra/cipher_extra.c
|
||||
@@ -93,6 +93,8 @@ const EVP_CIPHER *EVP_get_cipherbyname(const char *name) {
|
||||
return EVP_rc4();
|
||||
} else if (OPENSSL_strcasecmp(name, "des-cbc") == 0) {
|
||||
return EVP_des_cbc();
|
||||
+ } else if (OPENSSL_strcasecmp(name, "des-ede3") == 0) {
|
||||
+ return EVP_des_ede3();
|
||||
} else if (OPENSSL_strcasecmp(name, "des-ede3-cbc") == 0 ||
|
||||
// This is not a name used by OpenSSL, but tcpdump registers it
|
||||
// with |EVP_add_cipher_alias|. Our |EVP_add_cipher_alias| is a
|
||||
diff --git a/decrepit/evp/evp_do_all.c b/decrepit/evp/evp_do_all.c
|
||||
index 84af06fc56e4aa72d4d48801d7c037add0221747..fe412e350f43ad20758025da6b9754952d164938 100644
|
||||
--- a/decrepit/evp/evp_do_all.c
|
||||
+++ b/decrepit/evp/evp_do_all.c
|
||||
@@ -39,6 +39,7 @@ void EVP_CIPHER_do_all_sorted(void (*callback)(const EVP_CIPHER *cipher,
|
||||
callback(EVP_des_cbc(), "DES-CBC", NULL, arg);
|
||||
callback(EVP_des_ecb(), "DES-ECB", NULL, arg);
|
||||
callback(EVP_des_ede(), "DES-EDE", NULL, arg);
|
||||
+ callback(EVP_des_ede3(), "DES-EDE3", NULL, arg);
|
||||
callback(EVP_des_ede_cbc(), "DES-EDE-CBC", NULL, arg);
|
||||
callback(EVP_des_ede3_cbc(), "DES-EDE3-CBC", NULL, arg);
|
||||
callback(EVP_rc2_cbc(), "RC2-CBC", NULL, arg);
|
||||
@@ -65,6 +66,7 @@ void EVP_CIPHER_do_all_sorted(void (*callback)(const EVP_CIPHER *cipher,
|
||||
callback(EVP_des_cbc(), "des-cbc", NULL, arg);
|
||||
callback(EVP_des_ecb(), "des-ecb", NULL, arg);
|
||||
callback(EVP_des_ede(), "des-ede", NULL, arg);
|
||||
+ callback(EVP_des_ede3(), "des-ede3", NULL, arg);
|
||||
callback(EVP_des_ede_cbc(), "des-ede-cbc", NULL, arg);
|
||||
callback(EVP_des_ede3_cbc(), "des-ede3-cbc", NULL, arg);
|
||||
callback(EVP_rc2_cbc(), "rc2-cbc", NULL, arg);
|
||||
@@ -109,3 +109,7 @@ fix_export_zlib_symbols.patch
|
||||
don_t_use_potentially_null_getwebframe_-_view_when_get_blink.patch
|
||||
cherry-pick-5902d1aa722a.patch
|
||||
cherry-pick-5c7ad5393f74.patch
|
||||
word_break_between_space_and_alphanumeric.patch
|
||||
moves_background_color_setter_of_webview_to_blinks_webprefs_logic.patch
|
||||
blink_wasm_eval_csp.patch
|
||||
cherry-pick-162efe98330e.patch
|
||||
|
||||
@@ -10,10 +10,10 @@ DidCreateScriptContext is called, not all JS APIs are available in the
|
||||
context, which can cause some preload scripts to trip.
|
||||
|
||||
diff --git a/content/public/renderer/render_frame_observer.h b/content/public/renderer/render_frame_observer.h
|
||||
index 9ab534614b5bbb9b88069595603620c692b19711..5e3200887da9a584e9e0275d86e7e4254211009f 100644
|
||||
index 0b25680f2998e14ff2b974b373e39439cbb716a9..a7fabf210215d7b1bed3e95d1878a3543796462f 100644
|
||||
--- a/content/public/renderer/render_frame_observer.h
|
||||
+++ b/content/public/renderer/render_frame_observer.h
|
||||
@@ -122,6 +122,8 @@ class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener,
|
||||
@@ -123,6 +123,8 @@ class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener,
|
||||
virtual void DidHandleOnloadEvents() {}
|
||||
virtual void DidCreateScriptContext(v8::Local<v8::Context> context,
|
||||
int32_t world_id) {}
|
||||
@@ -23,10 +23,10 @@ index 9ab534614b5bbb9b88069595603620c692b19711..5e3200887da9a584e9e0275d86e7e425
|
||||
int32_t world_id) {}
|
||||
virtual void DidClearWindowObject() {}
|
||||
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
|
||||
index a401af64fad73f3717ab6bebdb28ba395d4090b2..eb777512e2cb36c6b4ae03cd0c0d728d76bd95fc 100644
|
||||
index d59a55cc4ec2341e6a12e59a515589aa634f4de5..2dc0c1e0d5bfc32e0d6506d75a0353a2f5c140a6 100644
|
||||
--- a/content/renderer/render_frame_impl.cc
|
||||
+++ b/content/renderer/render_frame_impl.cc
|
||||
@@ -4686,6 +4686,12 @@ void RenderFrameImpl::DidCreateScriptContext(v8::Local<v8::Context> context,
|
||||
@@ -4691,6 +4691,12 @@ void RenderFrameImpl::DidCreateScriptContext(v8::Local<v8::Context> context,
|
||||
observer.DidCreateScriptContext(context, world_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ index 9305b576b06a8020583939f357cd42902302b543..d772a31a436bf8f0617d87b5fcf5bd96
|
||||
// its owning reference back to our owning LocalFrame.
|
||||
client_->Detached(type);
|
||||
diff --git a/third_party/blink/renderer/core/frame/local_frame.cc b/third_party/blink/renderer/core/frame/local_frame.cc
|
||||
index 4fa167c47ac3bafd47976f302c0b957262930d42..1a93e18a3cf1e092749b9bb0666102c7d8ed1d23 100644
|
||||
index 4ceaa30497d240acee5899262f4a119a5a883275..6b70d19009844b074f432ac7566a47aba6aa8882 100644
|
||||
--- a/third_party/blink/renderer/core/frame/local_frame.cc
|
||||
+++ b/third_party/blink/renderer/core/frame/local_frame.cc
|
||||
@@ -672,10 +672,6 @@ bool LocalFrame::DetachImpl(FrameDetachType type) {
|
||||
|
||||
101
patches/chromium/blink_wasm_eval_csp.patch
Normal file
101
patches/chromium/blink_wasm_eval_csp.patch
Normal file
@@ -0,0 +1,101 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Cheng Zhao <zcbenz@gmail.com>
|
||||
Date: Thu, 4 Oct 2018 14:57:02 -0700
|
||||
Subject: feat: support wasm-eval csp behind WebAssemblyCSP flag
|
||||
|
||||
This is a minimal backport of
|
||||
https://chromium.googlesource.com/chromium/src/+/83913676803db53648b6a47d159102a7cf1dac36
|
||||
|
||||
The tracking issue in Chromium is
|
||||
https://bugs.chromium.org/p/chromium/issues/detail?id=948834
|
||||
|
||||
diff --git a/third_party/blink/renderer/core/frame/csp/content_security_policy.cc b/third_party/blink/renderer/core/frame/csp/content_security_policy.cc
|
||||
index 5e9aef4ef6398035c7a4704667d250d3fd54b25e..f8cf4b30c6ca02883b1c792bdb562c8550e8e17c 100644
|
||||
--- a/third_party/blink/renderer/core/frame/csp/content_security_policy.cc
|
||||
+++ b/third_party/blink/renderer/core/frame/csp/content_security_policy.cc
|
||||
@@ -313,7 +313,8 @@ void ContentSecurityPolicy::CopyPluginTypesFrom(
|
||||
|
||||
void ContentSecurityPolicy::DidReceiveHeaders(
|
||||
const ContentSecurityPolicyResponseHeaders& headers) {
|
||||
- if (headers.ShouldParseWasmEval())
|
||||
+ if (RuntimeEnabledFeatures::WebAssemblyCSPEnabled() ||
|
||||
+ headers.ShouldParseWasmEval())
|
||||
supports_wasm_eval_ = true;
|
||||
if (!headers.ContentSecurityPolicy().IsEmpty()) {
|
||||
AddAndReportPolicyFromHeaderValue(headers.ContentSecurityPolicy(),
|
||||
diff --git a/third_party/blink/renderer/core/frame/csp/csp_directive_list.cc b/third_party/blink/renderer/core/frame/csp/csp_directive_list.cc
|
||||
index 0411a75ca40371e1a309efba7b89e32f0edc917e..07b01fc682a172f5ed59c22285f9c968a9992307 100644
|
||||
--- a/third_party/blink/renderer/core/frame/csp/csp_directive_list.cc
|
||||
+++ b/third_party/blink/renderer/core/frame/csp/csp_directive_list.cc
|
||||
@@ -314,9 +314,14 @@ bool CSPDirectiveList::CheckEval(
|
||||
return !directive || directive->allow_eval;
|
||||
}
|
||||
|
||||
+bool SupportsWasmEval(const ContentSecurityPolicy* policy) {
|
||||
+ return RuntimeEnabledFeatures::WebAssemblyCSPEnabled() ||
|
||||
+ policy->SupportsWasmEval();
|
||||
+}
|
||||
+
|
||||
bool CSPDirectiveList::CheckWasmEval(
|
||||
const network::mojom::blink::CSPSourceList* directive) const {
|
||||
- return !directive || directive->allow_wasm_eval;
|
||||
+ return !directive || (SupportsWasmEval(policy_.Get()) && directive->allow_wasm_eval);
|
||||
}
|
||||
|
||||
bool CSPDirectiveList::IsMatchingNoncePresent(
|
||||
@@ -736,10 +741,14 @@ bool CSPDirectiveList::AllowWasmEval(
|
||||
ContentSecurityPolicy::ExceptionStatus exception_status,
|
||||
const String& content) const {
|
||||
if (reporting_disposition == ReportingDisposition::kReport) {
|
||||
+ String infix = SupportsWasmEval(policy_.Get())
|
||||
+ ? "neither 'wasm-eval' nor 'unsafe-eval' is"
|
||||
+ : "'unsafe-eval' is not";
|
||||
return CheckWasmEvalAndReportViolation(
|
||||
- "Refused to compile or instantiate WebAssembly module because "
|
||||
- "'wasm-eval' is not an allowed source of script in the following "
|
||||
- "Content Security Policy directive: ",
|
||||
+ "Refused to compile or instantiate WebAssembly module because " +
|
||||
+ infix +
|
||||
+ " an allowed source of script in the following "
|
||||
+ "Content Security Policy directive: ",
|
||||
exception_status, content);
|
||||
}
|
||||
return IsReportOnly() ||
|
||||
diff --git a/third_party/blink/renderer/core/frame/csp/source_list_directive.cc b/third_party/blink/renderer/core/frame/csp/source_list_directive.cc
|
||||
index d28ab719440cde74e82d7d0f557987e50ef7f531..5b44cb7f0203e4cbe8898d1e25cd5c4c080ef5f6 100644
|
||||
--- a/third_party/blink/renderer/core/frame/csp/source_list_directive.cc
|
||||
+++ b/third_party/blink/renderer/core/frame/csp/source_list_directive.cc
|
||||
@@ -403,10 +403,15 @@ bool ParseSource(const UChar* begin,
|
||||
return true;
|
||||
}
|
||||
|
||||
- if (policy->SupportsWasmEval() &&
|
||||
- EqualIgnoringASCIICase("'wasm-eval'", token)) {
|
||||
- source_list.allow_wasm_eval = true;
|
||||
- return true;
|
||||
+ // Temporarily behind a runtime feature
|
||||
+ if (EqualIgnoringASCIICase("'wasm-eval'", token)) {
|
||||
+ if (RuntimeEnabledFeatures::WebAssemblyCSPEnabled() ||
|
||||
+ policy->SupportsWasmEval()) {
|
||||
+ source_list.allow_wasm_eval = true;
|
||||
+ return true;
|
||||
+ } else {
|
||||
+ return false;
|
||||
+ }
|
||||
}
|
||||
|
||||
if (EqualIgnoringASCIICase("'strict-dynamic'", token)) {
|
||||
diff --git a/third_party/blink/renderer/platform/runtime_enabled_features.json5 b/third_party/blink/renderer/platform/runtime_enabled_features.json5
|
||||
index c81216f07beb0fc363b0eb0d6b104031ca2c1992..2aba9f6528569c19461e0084f4a0495dfd6b59ea 100644
|
||||
--- a/third_party/blink/renderer/platform/runtime_enabled_features.json5
|
||||
+++ b/third_party/blink/renderer/platform/runtime_enabled_features.json5
|
||||
@@ -2099,6 +2099,9 @@
|
||||
{
|
||||
name: "WebAppWindowControlsOverlay",
|
||||
},
|
||||
+ {
|
||||
+ name: "WebAssemblyCSP",
|
||||
+ },
|
||||
{
|
||||
name: "WebAssemblySimd",
|
||||
origin_trial_feature_name: "WebAssemblySimd",
|
||||
@@ -9,7 +9,7 @@ potentially prevent a window from being created.
|
||||
TODO(loc): this patch is currently broken.
|
||||
|
||||
diff --git a/content/browser/renderer_host/render_frame_host_impl.cc b/content/browser/renderer_host/render_frame_host_impl.cc
|
||||
index 6fc0faf92c8cd4122a69a5c4dc9c0f16faacf9d7..c77be3e54c897cd6c2a596288d6b6beb0de9804e 100644
|
||||
index 0e1a439de32f166818c59cb7aa010544360c9112..2e222a1bf9cb50efa990f875b102001998691f06 100644
|
||||
--- a/content/browser/renderer_host/render_frame_host_impl.cc
|
||||
+++ b/content/browser/renderer_host/render_frame_host_impl.cc
|
||||
@@ -5213,6 +5213,7 @@ void RenderFrameHostImpl::CreateNewWindow(
|
||||
@@ -21,7 +21,7 @@ index 6fc0faf92c8cd4122a69a5c4dc9c0f16faacf9d7..c77be3e54c897cd6c2a596288d6b6beb
|
||||
&no_javascript_access);
|
||||
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index 496c364797997997f2886abc95db2e6f49d848c6..3981c2caabd0362530c27e0dee572a56aaac0caf 100644
|
||||
index f4751d821d34a998407b37ca4b8221cd8a2ad135..762d4d6164df6f097c3dd77c695a3270a225ec68 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -3560,6 +3560,14 @@ RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow(
|
||||
@@ -68,10 +68,10 @@ index 182c6bf04e9937080efcedfc617fb9e072f10500..6fb3a1ee4a31e9a228e8ab04b1ce21c8
|
||||
|
||||
// Operation result when the renderer asks the browser to create a new window.
|
||||
diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc
|
||||
index e79384f012c548b5e2d42509a2a81484e0443b49..e485c81b2c6335b958983602a8b0e3d84fff5ab4 100644
|
||||
index c84ae68f2f271185e6021fcd0b41fe68c42a17e7..b84afa745f7a2b378f7cda18b7cdbb5357e2234c 100644
|
||||
--- a/content/public/browser/content_browser_client.cc
|
||||
+++ b/content/public/browser/content_browser_client.cc
|
||||
@@ -553,6 +553,8 @@ bool ContentBrowserClient::CanCreateWindow(
|
||||
@@ -554,6 +554,8 @@ bool ContentBrowserClient::CanCreateWindow(
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const blink::mojom::WindowFeatures& features,
|
||||
@@ -81,10 +81,10 @@ index e79384f012c548b5e2d42509a2a81484e0443b49..e485c81b2c6335b958983602a8b0e3d8
|
||||
bool opener_suppressed,
|
||||
bool* no_javascript_access) {
|
||||
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
|
||||
index a0d311812044f008d3220930a04d5300edd678fb..d92cfc2b18881a4d48cc4bd8340d6a84b8469c77 100644
|
||||
index c4fc708ab2789d2cf873bb8a5cff64259ab1d184..a9b4f7770a04d713de363c80c3a0f2b107b6d426 100644
|
||||
--- a/content/public/browser/content_browser_client.h
|
||||
+++ b/content/public/browser/content_browser_client.h
|
||||
@@ -154,6 +154,7 @@ class NetworkService;
|
||||
@@ -155,6 +155,7 @@ class NetworkService;
|
||||
class TrustedURLLoaderHeaderClient;
|
||||
} // namespace mojom
|
||||
struct ResourceRequest;
|
||||
@@ -92,7 +92,7 @@ index a0d311812044f008d3220930a04d5300edd678fb..d92cfc2b18881a4d48cc4bd8340d6a84
|
||||
} // namespace network
|
||||
|
||||
namespace sandbox {
|
||||
@@ -904,6 +905,8 @@ class CONTENT_EXPORT ContentBrowserClient {
|
||||
@@ -905,6 +906,8 @@ class CONTENT_EXPORT ContentBrowserClient {
|
||||
const std::string& frame_name,
|
||||
WindowOpenDisposition disposition,
|
||||
const blink::mojom::WindowFeatures& features,
|
||||
|
||||
204
patches/chromium/cherry-pick-162efe98330e.patch
Normal file
204
patches/chromium/cherry-pick-162efe98330e.patch
Normal file
@@ -0,0 +1,204 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Sigurdur Asgeirsson <siggi@chromium.org>
|
||||
Date: Thu, 11 Mar 2021 21:18:42 +0000
|
||||
Subject: Reland "Use a timer instead of a sleep loop."
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
This is a reland of ec21b4b42aa7ccebe79bfbee7db87c9cba20979a
|
||||
|
||||
Original change's description:
|
||||
> Use a timer instead of a sleep loop.
|
||||
>
|
||||
> This paves the way for implementing timer slack on the kqueue
|
||||
> message pump.
|
||||
>
|
||||
> Bug: 1181297
|
||||
> Change-Id: I74fdb63e85cf726000ee94b5851f84b06de314ae
|
||||
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2713848
|
||||
> Auto-Submit: Sigurður Ásgeirsson <siggi@chromium.org>
|
||||
> Reviewed-by: Mark Mentovai <mark@chromium.org>
|
||||
> Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org>
|
||||
> Reviewed-by: Robert Sesek <rsesek@chromium.org>
|
||||
> Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
|
||||
> Cr-Commit-Position: refs/heads/master@{#857894}
|
||||
|
||||
Bug: 1181297
|
||||
Change-Id: I63287f8d53f0aee9833d090ef6d32aa94698c692
|
||||
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2753412
|
||||
Reviewed-by: Robert Sesek <rsesek@chromium.org>
|
||||
Reviewed-by: Mark Mentovai <mark@chromium.org>
|
||||
Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org>
|
||||
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
|
||||
Cr-Commit-Position: refs/heads/master@{#862125}
|
||||
|
||||
diff --git a/base/message_loop/message_pump_kqueue.cc b/base/message_loop/message_pump_kqueue.cc
|
||||
index 9a0be64d50a8460bd80615f83e6d41d71c65e586..4a01b36db138a43c39196206b8dd015c9700c8c3 100644
|
||||
--- a/base/message_loop/message_pump_kqueue.cc
|
||||
+++ b/base/message_loop/message_pump_kqueue.cc
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "base/mac/mach_logging.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/posix/eintr_wrapper.h"
|
||||
+#include "base/time/time_override.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
@@ -21,10 +22,22 @@ namespace {
|
||||
// port sets. MessagePumpKqueue will directly use Mach ports in the kqueue if
|
||||
// it is possible.
|
||||
bool KqueueNeedsPortSet() {
|
||||
- static bool kqueue_needs_port_set = mac::IsAtMostOS10_11();
|
||||
+ static const bool kqueue_needs_port_set = mac::IsAtMostOS10_11();
|
||||
return kqueue_needs_port_set;
|
||||
}
|
||||
|
||||
+#if DCHECK_IS_ON()
|
||||
+// Prior to macOS 10.14, kqueue timers may spuriously wake up, because earlier
|
||||
+// wake ups race with timer resets in the kernel. As of macOS 10.14, updating a
|
||||
+// timer from the thread that reads the kqueue does not cause spurious wakeups.
|
||||
+// Note that updating a kqueue timer from one thread while another thread is
|
||||
+// waiting in a kevent64 invocation is still (inherently) racy.
|
||||
+bool KqueueTimersSpuriouslyWakeUp() {
|
||||
+ static const bool kqueue_timers_spuriously_wakeup = mac::IsAtMostOS10_13();
|
||||
+ return kqueue_timers_spuriously_wakeup;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
int ChangeOneEvent(const ScopedFD& kqueue, kevent64_s* event) {
|
||||
return HANDLE_EINTR(kevent64(kqueue.get(), event, 1, nullptr, 0, 0, nullptr));
|
||||
}
|
||||
@@ -364,25 +377,13 @@ bool MessagePumpKqueue::DoInternalWork(Delegate::NextWorkInfo* next_work_info) {
|
||||
|
||||
bool poll = next_work_info == nullptr;
|
||||
int flags = poll ? KEVENT_FLAG_IMMEDIATE : 0;
|
||||
- bool indefinite =
|
||||
- next_work_info != nullptr && next_work_info->delayed_run_time.is_max();
|
||||
-
|
||||
- int rv = 0;
|
||||
- do {
|
||||
- timespec timeout{};
|
||||
- if (!indefinite && !poll) {
|
||||
- if (rv != 0) {
|
||||
- // The wait was interrupted and made |next_work_info|'s view of
|
||||
- // TimeTicks::Now() stale. Refresh it before doing another wait.
|
||||
- next_work_info->recent_now = TimeTicks::Now();
|
||||
- }
|
||||
- timeout = next_work_info->remaining_delay().ToTimeSpec();
|
||||
- }
|
||||
- // This does not use HANDLE_EINTR, since retrying the syscall requires
|
||||
- // adjusting the timeout to account for time already waited.
|
||||
- rv = kevent64(kqueue_.get(), nullptr, 0, events_.data(), events_.size(),
|
||||
- flags, indefinite ? nullptr : &timeout);
|
||||
- } while (rv < 0 && errno == EINTR);
|
||||
+ if (!poll && scheduled_wakeup_time_ != next_work_info->delayed_run_time) {
|
||||
+ UpdateWakeupTimer(next_work_info->delayed_run_time);
|
||||
+ DCHECK_EQ(scheduled_wakeup_time_, next_work_info->delayed_run_time);
|
||||
+ }
|
||||
+
|
||||
+ int rv = HANDLE_EINTR(kevent64(kqueue_.get(), nullptr, 0, events_.data(),
|
||||
+ events_.size(), flags, nullptr));
|
||||
|
||||
PCHECK(rv >= 0) << "kevent64";
|
||||
return ProcessEvents(rv);
|
||||
@@ -445,6 +446,25 @@ bool MessagePumpKqueue::ProcessEvents(int count) {
|
||||
if (controller) {
|
||||
controller->watcher()->OnMachMessageReceived(port);
|
||||
}
|
||||
+ } else if (event->filter == EVFILT_TIMER) {
|
||||
+ // The wakeup timer fired.
|
||||
+#if DCHECK_IS_ON()
|
||||
+ // On macOS 10.13 and earlier, kqueue timers may spuriously wake up.
|
||||
+ // When this happens, the timer will be re-scheduled the next time
|
||||
+ // DoInternalWork is entered, which means this doesn't lead to a
|
||||
+ // spinning wait.
|
||||
+ // When clock overrides are active, TimeTicks::Now may be decoupled from
|
||||
+ // wall-clock time, and can therefore not be used to validate whether the
|
||||
+ // expected wall-clock time has passed.
|
||||
+ if (!KqueueTimersSpuriouslyWakeUp() &&
|
||||
+ !subtle::ScopedTimeClockOverrides::overrides_active()) {
|
||||
+ // Given the caveats above, assert that the timer didn't fire early.
|
||||
+ DCHECK_LE(scheduled_wakeup_time_, base::TimeTicks::Now());
|
||||
+ }
|
||||
+#endif
|
||||
+ DCHECK_NE(scheduled_wakeup_time_, base::TimeTicks::Max());
|
||||
+ scheduled_wakeup_time_ = base::TimeTicks::Max();
|
||||
+ --event_count_;
|
||||
} else {
|
||||
NOTREACHED() << "Unexpected event for filter " << event->filter;
|
||||
}
|
||||
@@ -453,4 +473,47 @@ bool MessagePumpKqueue::ProcessEvents(int count) {
|
||||
return did_work;
|
||||
}
|
||||
|
||||
+void MessagePumpKqueue::UpdateWakeupTimer(const base::TimeTicks& wakeup_time) {
|
||||
+ DCHECK_NE(wakeup_time, scheduled_wakeup_time_);
|
||||
+
|
||||
+ // The ident of the wakeup timer. There's only the one timer as the pair
|
||||
+ // (ident, filter) is the identity of the event.
|
||||
+ constexpr uint64_t kWakeupTimerIdent = 0x0;
|
||||
+ if (wakeup_time == base::TimeTicks::Max()) {
|
||||
+ // Clear the timer.
|
||||
+ kevent64_s timer{};
|
||||
+ timer.ident = kWakeupTimerIdent;
|
||||
+ timer.filter = EVFILT_TIMER;
|
||||
+ timer.flags = EV_DELETE;
|
||||
+
|
||||
+ int rv = ChangeOneEvent(kqueue_, &timer);
|
||||
+ PCHECK(rv == 0) << "kevent64, delete timer";
|
||||
+ --event_count_;
|
||||
+ } else {
|
||||
+ // Set/reset the timer.
|
||||
+ kevent64_s timer{};
|
||||
+ timer.ident = kWakeupTimerIdent;
|
||||
+ timer.filter = EVFILT_TIMER;
|
||||
+ // This updates the timer if it already exists in |kqueue_|.
|
||||
+ timer.flags = EV_ADD | EV_ONESHOT;
|
||||
+ // Specify the sleep in microseconds to avoid undersleeping due to
|
||||
+ // numeric problems. The sleep is computed from TimeTicks::Now rather than
|
||||
+ // NextWorkInfo::recent_now because recent_now is strictly earlier than
|
||||
+ // current wall-clock. Using an earlier wall clock time to compute the
|
||||
+ // delta to the next wakeup wall-clock time would guarantee oversleep.
|
||||
+ // If wakeup_time is in the past, the delta below will be negative and the
|
||||
+ // timer is set immediately.
|
||||
+ timer.fflags = NOTE_USECONDS;
|
||||
+ timer.data = (wakeup_time - base::TimeTicks::Now()).InMicroseconds();
|
||||
+ int rv = ChangeOneEvent(kqueue_, &timer);
|
||||
+ PCHECK(rv == 0) << "kevent64, set timer";
|
||||
+
|
||||
+ // Bump the event count if we just added the timer.
|
||||
+ if (scheduled_wakeup_time_ == base::TimeTicks::Max())
|
||||
+ ++event_count_;
|
||||
+ }
|
||||
+
|
||||
+ scheduled_wakeup_time_ = wakeup_time;
|
||||
+}
|
||||
+
|
||||
} // namespace base
|
||||
diff --git a/base/message_loop/message_pump_kqueue.h b/base/message_loop/message_pump_kqueue.h
|
||||
index 9acfcf22c3e0643000938ae1804eaeb4bbf7bd69..824d90fe2ab3083b094bb1a3ab1a0840f98b89f1 100644
|
||||
--- a/base/message_loop/message_pump_kqueue.h
|
||||
+++ b/base/message_loop/message_pump_kqueue.h
|
||||
@@ -136,6 +136,10 @@ class BASE_EXPORT MessagePumpKqueue : public MessagePump,
|
||||
// true if work was done, or false if no work was done.
|
||||
bool ProcessEvents(int count);
|
||||
|
||||
+ // Sets the wakeup timer to |wakeup_time|, or clears it if |wakeup_time| is
|
||||
+ // base::TimeTicks::Max(). Updates |scheduled_wakeup_time_| to follow.
|
||||
+ void UpdateWakeupTimer(const base::TimeTicks& wakeup_time);
|
||||
+
|
||||
// Receive right to which an empty Mach message is sent to wake up the pump
|
||||
// in response to ScheduleWork().
|
||||
mac::ScopedMachReceiveRight wakeup_;
|
||||
@@ -159,6 +163,10 @@ class BASE_EXPORT MessagePumpKqueue : public MessagePump,
|
||||
// Whether the pump has been Quit() or not.
|
||||
bool keep_running_ = true;
|
||||
|
||||
+ // The currently scheduled wakeup, if any. If no wakeup is scheduled,
|
||||
+ // contains base::TimeTicks::Max().
|
||||
+ base::TimeTicks scheduled_wakeup_time_{base::TimeTicks::Max()};
|
||||
+
|
||||
// The number of events scheduled on the |kqueue_|. There is always at least
|
||||
// 1, for the |wakeup_| port (or |port_set_|).
|
||||
size_t event_count_ = 1;
|
||||
@@ -264,7 +264,7 @@ index c5c5a7b63b5b3b62a9517cbef3ae23ce57a3c89c..4f1b7e88d6d2ae89a60311c8aeb1fcee
|
||||
void AddNewContents(content::WebContents* source,
|
||||
std::unique_ptr<content::WebContents> new_contents,
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index d20ce60c04007a83e412defbf525a756788bd0cc..a733423a617638147602c49874e0fa60c7983460 100644
|
||||
index a2bce274bdd70c0481a1bc75d449bfadf7b91618..af8196ef8a368b6e91703a8b91db58b94417a182 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -3521,8 +3521,7 @@ RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow(
|
||||
|
||||
@@ -7,10 +7,10 @@ spellchecker uses a few IDS_ resources. We need to load these from
|
||||
Electrons grit header instead of Chromes
|
||||
|
||||
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
|
||||
index 508e6780855e31b4e9e520b793527c0e295ed01a..14dd777a3d1ede24e0f73c7718a2b69aaaff8f52 100644
|
||||
index 2ace902f57a7a91124d316c1ad5df0e977e0a6d5..cf06039565541ebada001acfe3b6eb2ac0a42b44 100644
|
||||
--- a/chrome/browser/BUILD.gn
|
||||
+++ b/chrome/browser/BUILD.gn
|
||||
@@ -6203,6 +6203,7 @@ static_library("browser") {
|
||||
@@ -6206,6 +6206,7 @@ static_library("browser") {
|
||||
deps += [
|
||||
"//components/spellcheck/browser",
|
||||
"//components/spellcheck/common",
|
||||
|
||||
@@ -20,7 +20,7 @@ to deal with color spaces. That is being tracked at
|
||||
https://crbug.com/634542 and https://crbug.com/711107.
|
||||
|
||||
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
|
||||
index 23ca139dc684007eedc35696108bb1171191f86d..80a47f960fa8c1fdd45ea9cd18eacd8e7cff8d49 100644
|
||||
index ed8edf6ba74d22997ef51a2114cf7c9b7b08fdd5..c918fcc6fc450aa7438b96fa5f1d16093a8facef 100644
|
||||
--- a/cc/trees/layer_tree_host_impl.cc
|
||||
+++ b/cc/trees/layer_tree_host_impl.cc
|
||||
@@ -1770,6 +1770,10 @@ void LayerTreeHostImpl::SetIsLikelyToRequireADraw(
|
||||
|
||||
@@ -11,7 +11,7 @@ This regressed in https://chromium-review.googlesource.com/c/chromium/src/+/2572
|
||||
Upstream: https://chromium-review.googlesource.com/c/chromium/src/+/2598393
|
||||
|
||||
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
|
||||
index 3f9d1ba1217c43d18322e603c7958d94497c88f6..835577bbc61d97f8ed41ad085a7c7c83e76da69a 100644
|
||||
index 143115a151b37a9b7193a34d1564aaab6e5ca8f6..16d5060aa2313caadeb293861068e5b8ff9b0e01 100644
|
||||
--- a/content/renderer/render_frame_impl.cc
|
||||
+++ b/content/renderer/render_frame_impl.cc
|
||||
@@ -2689,7 +2689,7 @@ blink::WebLocalFrame* RenderFrameImpl::GetWebFrame() {
|
||||
|
||||
@@ -33,7 +33,7 @@ index 0ccfe130f00ec3b6c75cd8ee04d5a2777e1fd00c..653829457d58bf92057cc36aa8a28970
|
||||
DISALLOW_COPY_AND_ASSIGN(StaticHttpUserAgentSettings);
|
||||
};
|
||||
diff --git a/services/network/network_context.cc b/services/network/network_context.cc
|
||||
index 103958bba8a41b217bbaf4d8899fec3ad562aa70..a9447adde5430f123bb28fb8bf746d20cfba3485 100644
|
||||
index 258fc7463f81e58bdeb22c6eea465c9e97242fb0..380f804021bbbb6a6a7f580d236b9a511b089125 100644
|
||||
--- a/services/network/network_context.cc
|
||||
+++ b/services/network/network_context.cc
|
||||
@@ -1129,6 +1129,13 @@ void NetworkContext::SetNetworkConditions(
|
||||
|
||||
@@ -85,10 +85,10 @@ index fb648cda4e1aaa578cf271a60027e43b5d3a39d2..b567763c75832b742403356bb5deeaec
|
||||
// Visibility -----------------------------------------------------------
|
||||
|
||||
diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
|
||||
index 68688f094a68f9f29d7e8ec8d1158a0a4d7bb3f3..755d037d6f5046d4641b6532918125d1ca84cdd8 100644
|
||||
index 065393eeee18e8ed8f4eeb9ee001372b2333234e..2e3c4a5b2d583fe8a19afbbc33a83daa74d90b18 100644
|
||||
--- a/third_party/blink/renderer/core/exported/web_view_impl.cc
|
||||
+++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
|
||||
@@ -3477,6 +3477,13 @@ PageScheduler* WebViewImpl::Scheduler() const {
|
||||
@@ -3480,6 +3480,13 @@ PageScheduler* WebViewImpl::Scheduler() const {
|
||||
return GetPage()->GetPageScheduler();
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ index 68688f094a68f9f29d7e8ec8d1158a0a4d7bb3f3..755d037d6f5046d4641b6532918125d1
|
||||
void WebViewImpl::SetVisibilityState(
|
||||
mojom::blink::PageVisibilityState visibility_state,
|
||||
bool is_initial_state) {
|
||||
@@ -3487,7 +3494,8 @@ void WebViewImpl::SetVisibilityState(
|
||||
@@ -3490,7 +3497,8 @@ void WebViewImpl::SetVisibilityState(
|
||||
}
|
||||
GetPage()->SetVisibilityState(visibility_state, is_initial_state);
|
||||
GetPage()->GetPageScheduler()->SetPageVisible(
|
||||
|
||||
@@ -8,25 +8,21 @@ rendering with the viz compositor by way of a custom HostDisplayClient
|
||||
and LayeredWindowUpdater.
|
||||
|
||||
diff --git a/components/viz/host/host_display_client.cc b/components/viz/host/host_display_client.cc
|
||||
index 3b00759e513dc7e19fd68398e853c8ce6ac73905..d89fe3a7cc3f89d99606a74936626eeee3836956 100644
|
||||
index 3b00759e513dc7e19fd68398e853c8ce6ac73905..47f4e7cc2e8b3141dcaf9e7a498fec32c9342f40 100644
|
||||
--- a/components/viz/host/host_display_client.cc
|
||||
+++ b/components/viz/host/host_display_client.cc
|
||||
@@ -45,9 +45,13 @@ void HostDisplayClient::OnDisplayReceivedCALayerParams(
|
||||
@@ -45,9 +45,9 @@ void HostDisplayClient::OnDisplayReceivedCALayerParams(
|
||||
}
|
||||
#endif
|
||||
|
||||
-#if defined(OS_WIN)
|
||||
+void HostDisplayClient::IsOffscreen(IsOffscreenCallback callback) {
|
||||
+ std::move(callback).Run(false);
|
||||
+}
|
||||
+
|
||||
void HostDisplayClient::CreateLayeredWindowUpdater(
|
||||
mojo::PendingReceiver<mojom::LayeredWindowUpdater> receiver) {
|
||||
+#if defined(OS_WIN)
|
||||
if (!NeedsToUseLayerWindow(widget_)) {
|
||||
DLOG(ERROR) << "HWND shouldn't be using a layered window";
|
||||
return;
|
||||
@@ -55,8 +59,12 @@ void HostDisplayClient::CreateLayeredWindowUpdater(
|
||||
@@ -55,8 +55,12 @@ void HostDisplayClient::CreateLayeredWindowUpdater(
|
||||
|
||||
layered_window_updater_ =
|
||||
std::make_unique<LayeredWindowUpdaterImpl>(widget_, std::move(receiver));
|
||||
@@ -41,24 +37,15 @@ index 3b00759e513dc7e19fd68398e853c8ce6ac73905..d89fe3a7cc3f89d99606a74936626eee
|
||||
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
|
||||
// of lacros-chrome is complete.
|
||||
diff --git a/components/viz/host/host_display_client.h b/components/viz/host/host_display_client.h
|
||||
index 5e260e13762f61971c99f755e93d73aa794d9175..b4a46b030335f49b59b2c678078e5f18ef432300 100644
|
||||
index 5e260e13762f61971c99f755e93d73aa794d9175..a57770718b71def04fa35c7655d9368a58f39f20 100644
|
||||
--- a/components/viz/host/host_display_client.h
|
||||
+++ b/components/viz/host/host_display_client.h
|
||||
@@ -32,17 +32,17 @@ class VIZ_HOST_EXPORT HostDisplayClient : public mojom::DisplayClient {
|
||||
mojo::PendingRemote<mojom::DisplayClient> GetBoundRemote(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
|
||||
|
||||
- private:
|
||||
+ protected:
|
||||
// mojom::DisplayClient implementation:
|
||||
+ void IsOffscreen(IsOffscreenCallback callback) override;
|
||||
+
|
||||
#if defined(OS_APPLE)
|
||||
void OnDisplayReceivedCALayerParams(
|
||||
@@ -39,10 +39,9 @@ class VIZ_HOST_EXPORT HostDisplayClient : public mojom::DisplayClient {
|
||||
const gfx::CALayerParams& ca_layer_params) override;
|
||||
#endif
|
||||
|
||||
-#if defined(OS_WIN)
|
||||
+ protected:
|
||||
void CreateLayeredWindowUpdater(
|
||||
mojo::PendingReceiver<mojom::LayeredWindowUpdater> receiver) override;
|
||||
-#endif
|
||||
@@ -106,8 +93,22 @@ index 0f6a5a2fa3d82ae76889ef55af14e18b86cacffc..e33cd6305f53aa9287c61bf2d38848f8
|
||||
"display_embedder/software_output_surface.cc",
|
||||
"display_embedder/software_output_surface.h",
|
||||
"display_embedder/viz_process_context_provider.cc",
|
||||
diff --git a/components/viz/service/display_embedder/output_surface_provider.h b/components/viz/service/display_embedder/output_surface_provider.h
|
||||
index 77d463e683d8b8d3a202681a6884eacaab79d70d..05d51cb2637d34c073cd0025e365803633459a86 100644
|
||||
--- a/components/viz/service/display_embedder/output_surface_provider.h
|
||||
+++ b/components/viz/service/display_embedder/output_surface_provider.h
|
||||
@@ -39,7 +39,8 @@ class OutputSurfaceProvider {
|
||||
mojom::DisplayClient* display_client,
|
||||
DisplayCompositorMemoryAndTaskController* gpu_dependency,
|
||||
const RendererSettings& renderer_settings,
|
||||
- const DebugRendererSettings* debug_settings) = 0;
|
||||
+ const DebugRendererSettings* debug_settings,
|
||||
+ bool offscreen) = 0;
|
||||
};
|
||||
|
||||
} // namespace viz
|
||||
diff --git a/components/viz/service/display_embedder/output_surface_provider_impl.cc b/components/viz/service/display_embedder/output_surface_provider_impl.cc
|
||||
index 79c800e77a160cc0b10a29dd560d37e19c9d05fd..6513af7550933f988edacc0de124ae29c06500f8 100644
|
||||
index 79c800e77a160cc0b10a29dd560d37e19c9d05fd..a9b1b267c97ed513890ba8466f66c3eafcbd5d5b 100644
|
||||
--- a/components/viz/service/display_embedder/output_surface_provider_impl.cc
|
||||
+++ b/components/viz/service/display_embedder/output_surface_provider_impl.cc
|
||||
@@ -25,6 +25,7 @@
|
||||
@@ -126,29 +127,70 @@ index 79c800e77a160cc0b10a29dd560d37e19c9d05fd..6513af7550933f988edacc0de124ae29
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
#include "ui/gl/gl_context.h"
|
||||
#include "ui/gl/init/gl_factory.h"
|
||||
@@ -245,6 +247,22 @@ OutputSurfaceProviderImpl::CreateSoftwareOutputDeviceForPlatform(
|
||||
@@ -130,7 +132,8 @@ std::unique_ptr<OutputSurface> OutputSurfaceProviderImpl::CreateOutputSurface(
|
||||
mojom::DisplayClient* display_client,
|
||||
DisplayCompositorMemoryAndTaskController* gpu_dependency,
|
||||
const RendererSettings& renderer_settings,
|
||||
- const DebugRendererSettings* debug_settings) {
|
||||
+ const DebugRendererSettings* debug_settings,
|
||||
+ bool offscreen) {
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
if (surface_handle == gpu::kNullSurfaceHandle)
|
||||
return std::make_unique<OutputSurfaceUnified>();
|
||||
@@ -142,7 +145,7 @@ std::unique_ptr<OutputSurface> OutputSurfaceProviderImpl::CreateOutputSurface(
|
||||
|
||||
if (!gpu_compositing) {
|
||||
output_surface = std::make_unique<SoftwareOutputSurface>(
|
||||
- CreateSoftwareOutputDeviceForPlatform(surface_handle, display_client));
|
||||
+ CreateSoftwareOutputDeviceForPlatform(surface_handle, display_client, offscreen));
|
||||
} else if (renderer_settings.use_skia_renderer) {
|
||||
DCHECK(gpu_dependency);
|
||||
{
|
||||
@@ -241,10 +244,22 @@ std::unique_ptr<OutputSurface> OutputSurfaceProviderImpl::CreateOutputSurface(
|
||||
std::unique_ptr<SoftwareOutputDevice>
|
||||
OutputSurfaceProviderImpl::CreateSoftwareOutputDeviceForPlatform(
|
||||
gpu::SurfaceHandle surface_handle,
|
||||
- mojom::DisplayClient* display_client) {
|
||||
+ mojom::DisplayClient* display_client,
|
||||
+ bool offscreen) {
|
||||
if (headless_)
|
||||
return std::make_unique<SoftwareOutputDevice>();
|
||||
|
||||
+#if !defined(OS_MAC)
|
||||
+ {
|
||||
+ mojo::ScopedAllowSyncCallForTesting allow_sync;
|
||||
+ if (offscreen) {
|
||||
+ DCHECK(display_client);
|
||||
+ bool offscreen = false;
|
||||
+ if (display_client->IsOffscreen(&offscreen) && offscreen) {
|
||||
+ mojom::LayeredWindowUpdaterPtr layered_window_updater;
|
||||
+ display_client->CreateLayeredWindowUpdater(
|
||||
+ mojo::MakeRequest(&layered_window_updater));
|
||||
+
|
||||
+ return std::make_unique<SoftwareOutputDeviceProxy>(
|
||||
+ std::move(layered_window_updater));
|
||||
+ }
|
||||
+ mojom::LayeredWindowUpdaterPtr layered_window_updater;
|
||||
+ display_client->CreateLayeredWindowUpdater(
|
||||
+ mojo::MakeRequest(&layered_window_updater));
|
||||
+ return std::make_unique<SoftwareOutputDeviceProxy>(
|
||||
+ std::move(layered_window_updater));
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
#if defined(OS_WIN)
|
||||
return CreateSoftwareOutputDeviceWin(surface_handle, &output_device_backing_,
|
||||
display_client);
|
||||
diff --git a/components/viz/service/display_embedder/output_surface_provider_impl.h b/components/viz/service/display_embedder/output_surface_provider_impl.h
|
||||
index a6bb42cdbc567f526cc70c5c4d9b967274dc0332..d116844635922c8a1086dfa13063b8ae8b43ce59 100644
|
||||
--- a/components/viz/service/display_embedder/output_surface_provider_impl.h
|
||||
+++ b/components/viz/service/display_embedder/output_surface_provider_impl.h
|
||||
@@ -61,12 +61,14 @@ class VIZ_SERVICE_EXPORT OutputSurfaceProviderImpl
|
||||
mojom::DisplayClient* display_client,
|
||||
DisplayCompositorMemoryAndTaskController* gpu_dependency,
|
||||
const RendererSettings& renderer_settings,
|
||||
- const DebugRendererSettings* debug_settings) override;
|
||||
+ const DebugRendererSettings* debug_settings,
|
||||
+ bool offscreen) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<SoftwareOutputDevice> CreateSoftwareOutputDeviceForPlatform(
|
||||
gpu::SurfaceHandle surface_handle,
|
||||
- mojom::DisplayClient* display_client);
|
||||
+ mojom::DisplayClient* display_client,
|
||||
+ bool offscreen);
|
||||
|
||||
GpuServiceImpl* const gpu_service_impl_;
|
||||
gpu::CommandBufferTaskExecutor* const task_executor_;
|
||||
diff --git a/components/viz/service/display_embedder/software_output_device_mac.cc b/components/viz/service/display_embedder/software_output_device_mac.cc
|
||||
index 49149081cc603f14eacee647cbb2fcf8ed5e66fd..9ff3f2ee203403fdaa31edb8a0bcc000c4d214d7 100644
|
||||
--- a/components/viz/service/display_embedder/software_output_device_mac.cc
|
||||
@@ -454,11 +496,25 @@ index 2bb30e5318b6b48c2e6d4b1f64a6a36c68f963d1..9e805f27a9d7d1c0aa68cdf9f48895c0
|
||||
&SoftwareOutputDeviceWinProxy::DrawAck, base::Unretained(this)));
|
||||
waiting_on_draw_ack_ = true;
|
||||
|
||||
diff --git a/components/viz/service/frame_sinks/root_compositor_frame_sink_impl.cc b/components/viz/service/frame_sinks/root_compositor_frame_sink_impl.cc
|
||||
index 8112abf9ca0bf214721f5996bb59f7458d9347d2..8b3c2a4cce0c4789fadd555b360dea2c145ae1a4 100644
|
||||
--- a/components/viz/service/frame_sinks/root_compositor_frame_sink_impl.cc
|
||||
+++ b/components/viz/service/frame_sinks/root_compositor_frame_sink_impl.cc
|
||||
@@ -46,7 +46,8 @@ RootCompositorFrameSinkImpl::Create(
|
||||
params->gpu_compositing, params->widget, params->renderer_settings);
|
||||
auto output_surface = output_surface_provider->CreateOutputSurface(
|
||||
params->widget, params->gpu_compositing, display_client.get(),
|
||||
- display_controller.get(), params->renderer_settings, debug_settings);
|
||||
+ display_controller.get(), params->renderer_settings, debug_settings,
|
||||
+ params->offscreen);
|
||||
|
||||
// Creating output surface failed. The host can send a new request, possibly
|
||||
// with a different compositing mode.
|
||||
diff --git a/content/browser/compositor/viz_process_transport_factory.cc b/content/browser/compositor/viz_process_transport_factory.cc
|
||||
index 11ac1649ed0f5be1d12e8a30b8d170f86b8e9bb8..ade5afce4a5d3c9e44081a3b1ac971b595e7a5da 100644
|
||||
index 11ac1649ed0f5be1d12e8a30b8d170f86b8e9bb8..05746d9a561c3933ae0c5578467f20b486453943 100644
|
||||
--- a/content/browser/compositor/viz_process_transport_factory.cc
|
||||
+++ b/content/browser/compositor/viz_process_transport_factory.cc
|
||||
@@ -414,8 +414,13 @@ void VizProcessTransportFactory::OnEstablishedGpuChannel(
|
||||
@@ -414,8 +414,14 @@ void VizProcessTransportFactory::OnEstablishedGpuChannel(
|
||||
compositor_data.display_private.reset();
|
||||
root_params->display_private =
|
||||
compositor_data.display_private.BindNewEndpointAndPassReceiver();
|
||||
@@ -467,6 +523,7 @@ index 11ac1649ed0f5be1d12e8a30b8d170f86b8e9bb8..ade5afce4a5d3c9e44081a3b1ac971b5
|
||||
+ if (compositor->delegate()) {
|
||||
+ compositor_data.display_client = compositor->delegate()->CreateHostDisplayClient(
|
||||
+ compositor);
|
||||
+ root_params->offscreen = compositor->delegate()->IsOffscreen();
|
||||
+ } else {
|
||||
+ compositor_data.display_client =
|
||||
+ std::make_unique<HostDisplayClient>(compositor);
|
||||
@@ -474,40 +531,11 @@ index 11ac1649ed0f5be1d12e8a30b8d170f86b8e9bb8..ade5afce4a5d3c9e44081a3b1ac971b5
|
||||
root_params->display_client =
|
||||
compositor_data.display_client->GetBoundRemote(resize_task_runner_);
|
||||
|
||||
diff --git a/mojo/public/cpp/bindings/sync_call_restrictions.h b/mojo/public/cpp/bindings/sync_call_restrictions.h
|
||||
index 4ff82130b358cd4f0bf1bd5673a9f7b89c087ea5..2bb5dfb20ab58b623b43da1f36b4d586cd5b8ecb 100644
|
||||
--- a/mojo/public/cpp/bindings/sync_call_restrictions.h
|
||||
+++ b/mojo/public/cpp/bindings/sync_call_restrictions.h
|
||||
@@ -33,6 +33,7 @@ class Compositor;
|
||||
|
||||
namespace viz {
|
||||
class HostFrameSinkManager;
|
||||
+class GpuDisplayProvider;
|
||||
}
|
||||
|
||||
namespace mojo {
|
||||
@@ -83,6 +84,8 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncCallRestrictions {
|
||||
// For destroying the GL context/surface that draw to a platform window before
|
||||
// the platform window is destroyed.
|
||||
friend class viz::HostFrameSinkManager;
|
||||
+ // For query of whether to use SoftwareOutputDevice or not
|
||||
+ friend class viz::GpuDisplayProvider;
|
||||
// For preventing frame swaps of wrong size during resize on Windows.
|
||||
// (https://crbug.com/811945)
|
||||
friend class ui::Compositor;
|
||||
diff --git a/services/viz/privileged/mojom/compositing/display_private.mojom b/services/viz/privileged/mojom/compositing/display_private.mojom
|
||||
index 0c9686f3c8070000bf5b180d9c06a8817d430c4a..a69b9613a61ef68624b3f69dc087603ad5cfd0c2 100644
|
||||
index 0c9686f3c8070000bf5b180d9c06a8817d430c4a..4538b95f6e71708144eb7752438b1b31d60cb2ca 100644
|
||||
--- a/services/viz/privileged/mojom/compositing/display_private.mojom
|
||||
+++ b/services/viz/privileged/mojom/compositing/display_private.mojom
|
||||
@@ -80,12 +80,14 @@ interface DisplayPrivate {
|
||||
};
|
||||
|
||||
interface DisplayClient {
|
||||
+ [Sync]
|
||||
+ IsOffscreen() => (bool success);
|
||||
+
|
||||
[EnableIf=is_mac]
|
||||
OnDisplayReceivedCALayerParams(gfx.mojom.CALayerParams ca_layer_params);
|
||||
@@ -85,7 +85,6 @@ interface DisplayClient {
|
||||
|
||||
// Creates a LayeredWindowUpdater implementation to draw into a layered
|
||||
// window.
|
||||
@@ -515,6 +543,18 @@ index 0c9686f3c8070000bf5b180d9c06a8817d430c4a..a69b9613a61ef68624b3f69dc087603a
|
||||
CreateLayeredWindowUpdater(pending_receiver<LayeredWindowUpdater> receiver);
|
||||
|
||||
// Notifies that a swap has occurred and provides information about the pixel
|
||||
diff --git a/services/viz/privileged/mojom/compositing/frame_sink_manager.mojom b/services/viz/privileged/mojom/compositing/frame_sink_manager.mojom
|
||||
index a0b87925e0c9d02f586cc4e9446cbfcf12b7aa1c..71659834eec5237016f95f93defa9dcb30f0af52 100644
|
||||
--- a/services/viz/privileged/mojom/compositing/frame_sink_manager.mojom
|
||||
+++ b/services/viz/privileged/mojom/compositing/frame_sink_manager.mojom
|
||||
@@ -30,6 +30,7 @@ struct RootCompositorFrameSinkParams {
|
||||
// Disables begin frame rate limiting for the display compositor.
|
||||
bool disable_frame_rate_limit = false;
|
||||
bool use_preferred_interval_for_video = false;
|
||||
+ bool offscreen = false;
|
||||
|
||||
[EnableIf=is_android]
|
||||
float refresh_rate;
|
||||
diff --git a/services/viz/privileged/mojom/compositing/layered_window_updater.mojom b/services/viz/privileged/mojom/compositing/layered_window_updater.mojom
|
||||
index 6b7fbb6cf13dc8ee6ade0878a9a2c1efc5d4d3f1..e2af75168cb914a7b3b4a6c9b6a285498c3f8e72 100644
|
||||
--- a/services/viz/privileged/mojom/compositing/layered_window_updater.mojom
|
||||
@@ -527,7 +567,7 @@ index 6b7fbb6cf13dc8ee6ade0878a9a2c1efc5d4d3f1..e2af75168cb914a7b3b4a6c9b6a28549
|
||||
+ Draw(gfx.mojom.Rect damage_rect) => ();
|
||||
};
|
||||
diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
|
||||
index e1db8f745c077b2f57b39a48aeab434fe0e98541..08c7dfa4988ef0247b0bd788171e4a9653612f19 100644
|
||||
index e1db8f745c077b2f57b39a48aeab434fe0e98541..ddafd1f2aa38ef30776fa89ffcf5d108be963ac9 100644
|
||||
--- a/ui/compositor/compositor.h
|
||||
+++ b/ui/compositor/compositor.h
|
||||
@@ -77,6 +77,7 @@ class ExternalBeginFrameController;
|
||||
@@ -538,12 +578,13 @@ index e1db8f745c077b2f57b39a48aeab434fe0e98541..08c7dfa4988ef0247b0bd788171e4a96
|
||||
class HostFrameSinkManager;
|
||||
class LocalSurfaceId;
|
||||
class RasterContextProvider;
|
||||
@@ -133,6 +134,15 @@ class COMPOSITOR_EXPORT ContextFactory {
|
||||
@@ -133,6 +134,16 @@ class COMPOSITOR_EXPORT ContextFactory {
|
||||
virtual viz::HostFrameSinkManager* GetHostFrameSinkManager() = 0;
|
||||
};
|
||||
|
||||
+class COMPOSITOR_EXPORT CompositorDelegate {
|
||||
+ public:
|
||||
+ virtual bool IsOffscreen() const = 0;
|
||||
+ virtual std::unique_ptr<viz::HostDisplayClient> CreateHostDisplayClient(
|
||||
+ ui::Compositor* compositor) = 0;
|
||||
+
|
||||
@@ -554,7 +595,7 @@ index e1db8f745c077b2f57b39a48aeab434fe0e98541..08c7dfa4988ef0247b0bd788171e4a96
|
||||
// Compositor object to take care of GPU painting.
|
||||
// A Browser compositor object is responsible for generating the final
|
||||
// displayable form of pixels comprising a single widget's contents. It draws an
|
||||
@@ -167,6 +177,9 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient,
|
||||
@@ -167,6 +178,9 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient,
|
||||
// Schedules a redraw of the layer tree associated with this compositor.
|
||||
void ScheduleDraw();
|
||||
|
||||
@@ -564,7 +605,7 @@ index e1db8f745c077b2f57b39a48aeab434fe0e98541..08c7dfa4988ef0247b0bd788171e4a96
|
||||
// Sets the root of the layer tree drawn by this Compositor. The root layer
|
||||
// must have no parent. The compositor's root layer is reset if the root layer
|
||||
// is destroyed. NULL can be passed to reset the root layer, in which case the
|
||||
@@ -435,6 +448,8 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient,
|
||||
@@ -435,6 +449,8 @@ class COMPOSITOR_EXPORT Compositor : public cc::LayerTreeHostClient,
|
||||
|
||||
std::unique_ptr<PendingBeginFrameArgs> pending_begin_frame_args_;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ This patch can be removed once app.allowRendererProcessReuse is forced
|
||||
to true as then Chromiums assumptions around processes become correct.
|
||||
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index 3981c2caabd0362530c27e0dee572a56aaac0caf..81ecd2d06104aa125c95d40336e8192ec23a1206 100644
|
||||
index 762d4d6164df6f097c3dd77c695a3270a225ec68..eac2487f18332616b1550bd7fa1f39f5c532b079 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -2971,11 +2971,13 @@ bool WebContentsImpl::HandleMouseEvent(const blink::WebMouseEvent& event) {
|
||||
|
||||
@@ -229,10 +229,10 @@ index 1d79bf9261aad6e649a029257f7e6848cc34ad69..64cd5e188786ed60e474aeb1cabacd3d
|
||||
size_t GetRelatedActiveContentsCount() override;
|
||||
bool RequiresDedicatedProcess() override;
|
||||
diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc
|
||||
index e485c81b2c6335b958983602a8b0e3d84fff5ab4..9fd15de448372693e7792aeee0ae1eb51fbe158e 100644
|
||||
index b84afa745f7a2b378f7cda18b7cdbb5357e2234c..94cda2d735bbb313471ded7b0e922c6f96cac901 100644
|
||||
--- a/content/public/browser/content_browser_client.cc
|
||||
+++ b/content/public/browser/content_browser_client.cc
|
||||
@@ -65,6 +65,21 @@
|
||||
@@ -66,6 +66,21 @@
|
||||
|
||||
namespace content {
|
||||
|
||||
@@ -255,12 +255,12 @@ index e485c81b2c6335b958983602a8b0e3d84fff5ab4..9fd15de448372693e7792aeee0ae1eb5
|
||||
const MainFunctionParams& parameters) {
|
||||
return nullptr;
|
||||
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
|
||||
index d92cfc2b18881a4d48cc4bd8340d6a84b8469c77..b5a1596632f135a52a24f4d90c34aa79defd1d4d 100644
|
||||
index a9b4f7770a04d713de363c80c3a0f2b107b6d426..ebd20fad629f24c6068e1a80c63f7811689df9ab 100644
|
||||
--- a/content/public/browser/content_browser_client.h
|
||||
+++ b/content/public/browser/content_browser_client.h
|
||||
@@ -255,8 +255,45 @@ class CONTENT_EXPORT ContentBrowserClient {
|
||||
using IsClipboardPasteAllowedCallback =
|
||||
base::OnceCallback<void(ClipboardPasteAllowed)>;
|
||||
@@ -256,8 +256,45 @@ class CONTENT_EXPORT ContentBrowserClient {
|
||||
using IsClipboardPasteContentAllowedCallback =
|
||||
base::OnceCallback<void(ClipboardPasteContentAllowed)>;
|
||||
|
||||
+ // Identifies the type of site instance to use for a navigation.
|
||||
+ enum SiteInstanceForNavigationType {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Samuel Attard <sattard@slack-corp.com>
|
||||
Date: Mon, 8 Mar 2021 16:27:39 -0800
|
||||
Subject: moves background_color setter of WebView to blinks webprefs logic
|
||||
|
||||
background_color can be updated at runtime, as such we need to apply the
|
||||
new background color to the WebView in the ApplyPreferences method.
|
||||
There is no current way to attach an observer to these prefs so patching
|
||||
is our only option.
|
||||
|
||||
Ideally we could add an embedder observer pattern here but that can be
|
||||
done in future work.
|
||||
|
||||
diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
|
||||
index 2e3c4a5b2d583fe8a19afbbc33a83daa74d90b18..3aec314cd0d603c14b7de59f20f938910c7931f5 100644
|
||||
--- a/third_party/blink/renderer/core/exported/web_view_impl.cc
|
||||
+++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
|
||||
@@ -154,6 +154,7 @@
|
||||
#include "third_party/blink/renderer/core/timing/dom_window_performance.h"
|
||||
#include "third_party/blink/renderer/core/timing/window_performance.h"
|
||||
#include "third_party/blink/renderer/platform/fonts/font_cache.h"
|
||||
+#include "third_party/blink/renderer/platform/graphics/color.h"
|
||||
#include "third_party/blink/renderer/platform/graphics/image.h"
|
||||
#include "third_party/blink/renderer/platform/graphics/paint/cull_rect.h"
|
||||
#include "third_party/blink/renderer/platform/graphics/paint/paint_record_builder.h"
|
||||
@@ -1752,6 +1753,14 @@ void WebView::ApplyWebPreferences(const web_pref::WebPreferences& prefs,
|
||||
|
||||
RuntimeEnabledFeatures::SetTranslateServiceEnabled(
|
||||
prefs.translate_service_available);
|
||||
+
|
||||
+ SkColor color = SK_ColorTRANSPARENT;
|
||||
+ if (!prefs.guest_instance_id) { // not inside electron <webview /> tag, which is always transparent.
|
||||
+ Color blink_color;
|
||||
+ if (blink_color.SetFromString(WebString::FromASCII(prefs.background_color)))
|
||||
+ color = static_cast<SkColor>(blink_color);
|
||||
+ }
|
||||
+ web_view->SetBaseBackgroundColor(color);
|
||||
}
|
||||
|
||||
void WebViewImpl::ThemeChanged() {
|
||||
@@ -7,7 +7,7 @@ This adds a callback from the network service that's used to implement
|
||||
session.setCertificateVerifyCallback.
|
||||
|
||||
diff --git a/services/network/network_context.cc b/services/network/network_context.cc
|
||||
index db667e13f2e4d9e96e9ac28f17c61412d6279ec7..103958bba8a41b217bbaf4d8899fec3ad562aa70 100644
|
||||
index db667e13f2e4d9e96e9ac28f17c61412d6279ec7..258fc7463f81e58bdeb22c6eea465c9e97242fb0 100644
|
||||
--- a/services/network/network_context.cc
|
||||
+++ b/services/network/network_context.cc
|
||||
@@ -118,6 +118,11 @@
|
||||
@@ -116,70 +116,17 @@ index db667e13f2e4d9e96e9ac28f17c61412d6279ec7..103958bba8a41b217bbaf4d8899fec3a
|
||||
void NetworkContext::CreateURLLoaderFactory(
|
||||
mojo::PendingReceiver<mojom::URLLoaderFactory> receiver,
|
||||
mojom::URLLoaderFactoryParamsPtr params) {
|
||||
@@ -1878,8 +1963,9 @@ URLRequestContextOwner NetworkContext::MakeURLRequestContext(
|
||||
"NetworkContext should pass CertVerifierServiceRemoteParams.";
|
||||
|
||||
std::unique_ptr<net::CertVerifier> cert_verifier;
|
||||
+ std::unique_ptr<net::CertVerifier> temp_verifier;
|
||||
if (g_cert_verifier_for_testing) {
|
||||
- cert_verifier = std::make_unique<WrappedTestingCertVerifier>();
|
||||
+ temp_verifier = std::make_unique<WrappedTestingCertVerifier>();
|
||||
} else {
|
||||
if (params_->cert_verifier_params &&
|
||||
params_->cert_verifier_params->is_remote_params()) {
|
||||
@@ -1907,7 +1993,7 @@ URLRequestContextOwner NetworkContext::MakeURLRequestContext(
|
||||
cert_net_fetcher_ =
|
||||
base::MakeRefCounted<net::CertNetFetcherURLRequest>();
|
||||
|
||||
- cert_verifier = CreateCertVerifier(creation_params, cert_net_fetcher_);
|
||||
+ temp_verifier = CreateCertVerifier(creation_params, cert_net_fetcher_);
|
||||
@@ -1929,6 +2014,10 @@ URLRequestContextOwner NetworkContext::MakeURLRequestContext(
|
||||
}
|
||||
#endif // BUILDFLAG(IS_CT_SUPPORTED)
|
||||
|
||||
#if BUILDFLAG(IS_CT_SUPPORTED)
|
||||
@@ -1931,9 +2017,9 @@ URLRequestContextOwner NetworkContext::MakeURLRequestContext(
|
||||
|
||||
+ auto remote_cert_verifier = std::make_unique<RemoteCertVerifier>(std::move(cert_verifier));
|
||||
+ remote_cert_verifier_ = remote_cert_verifier.get();
|
||||
+ cert_verifier = std::move(remote_cert_verifier);
|
||||
+
|
||||
// Whether the cert verifier is remote or in-process, we should wrap it in
|
||||
// caching and coalescing layers to avoid extra verifications and IPCs.
|
||||
- cert_verifier = std::make_unique<net::CachingCertVerifier>(
|
||||
+ temp_verifier = std::make_unique<net::CachingCertVerifier>(
|
||||
std::make_unique<net::CoalescingCertVerifier>(
|
||||
- std::move(cert_verifier)));
|
||||
+ std::move(temp_verifier)));
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
cert_verifier_with_trust_anchors_ =
|
||||
@@ -1942,13 +2028,27 @@ URLRequestContextOwner NetworkContext::MakeURLRequestContext(
|
||||
UpdateAdditionalCertificates(
|
||||
std::move(params_->initial_additional_certificates));
|
||||
cert_verifier_with_trust_anchors_->InitializeOnIOThread(
|
||||
- std::move(cert_verifier));
|
||||
- cert_verifier = base::WrapUnique(cert_verifier_with_trust_anchors_);
|
||||
+ std::move(temp_verifier));
|
||||
+ temp_verifier = base::WrapUnique(cert_verifier_with_trust_anchors_);
|
||||
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
+ if (!temp_verifier) {
|
||||
+#if !defined(OS_LINUX)
|
||||
+ temp_verifier = std::make_unique<net::MultiThreadedCertVerifier>(
|
||||
+ net::CertVerifyProc::CreateSystemVerifyProc(std::move(cert_net_fetcher_)));
|
||||
+#else
|
||||
+ temp_verifier = std::make_unique<net::MultiThreadedCertVerifier>(
|
||||
+ net::CertVerifyProc::CreateBuiltinVerifyProc(std::move(cert_net_fetcher_)));
|
||||
+#endif
|
||||
+ }
|
||||
+ auto remote_cert_verifier = std::make_unique<RemoteCertVerifier>(std::move(temp_verifier));
|
||||
+ remote_cert_verifier_ = remote_cert_verifier.get();
|
||||
+ cert_verifier = std::make_unique<net::CachingCertVerifier>(std::move(remote_cert_verifier));
|
||||
}
|
||||
|
||||
- builder.SetCertVerifier(IgnoreErrorsCertVerifier::MaybeWrapCertVerifier(
|
||||
- *command_line, nullptr, std::move(cert_verifier)));
|
||||
+ cert_verifier = IgnoreErrorsCertVerifier::MaybeWrapCertVerifier(
|
||||
+ *command_line, nullptr, std::move(cert_verifier));
|
||||
+
|
||||
+ builder.SetCertVerifier(std::move(cert_verifier));
|
||||
|
||||
#if BUILDFLAG(IS_CT_SUPPORTED)
|
||||
if (params_->enforce_chrome_ct_policy) {
|
||||
cert_verifier = std::make_unique<net::CachingCertVerifier>(
|
||||
diff --git a/services/network/network_context.h b/services/network/network_context.h
|
||||
index 707cf9a7db7b81da9affef0c9ab4a934f5fd69c9..494d68d7f399152a08dd74ee4aa2d17baec81dd8 100644
|
||||
--- a/services/network/network_context.h
|
||||
|
||||
@@ -43,7 +43,7 @@ index 3122722665f1e2e4796e9628486c8bea8fdf283e..a5d58e950b91431639fb14b0e6a9bd43
|
||||
|
||||
void RenderWidgetHostImpl::ShowContextMenuAtPoint(
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index 3ea1b844a80f85da1d4e3c47d0a33d0e9eeb02ef..d20ce60c04007a83e412defbf525a756788bd0cc 100644
|
||||
index bc54b385d792eaad00c13fe43e9be1536397c5d7..a2bce274bdd70c0481a1bc75d449bfadf7b91618 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -4119,6 +4119,12 @@ TextInputManager* WebContentsImpl::GetTextInputManager() {
|
||||
@@ -60,7 +60,7 @@ index 3ea1b844a80f85da1d4e3c47d0a33d0e9eeb02ef..d20ce60c04007a83e412defbf525a756
|
||||
RenderWidgetHostImpl* render_widget_host) {
|
||||
return render_widget_host == GetMainFrame()->GetRenderWidgetHost();
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
|
||||
index 4b09bb93269a9c9d25824992660c3613119ad3d4..90d4919d793b99f73a9bad85fbb0b41b380e8845 100644
|
||||
index 84ecccc204ee33820b8a059219244a841d6d642f..357ba07b83577392a902203cd7ee50e0ba3d27dd 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.h
|
||||
+++ b/content/browser/web_contents/web_contents_impl.h
|
||||
@@ -965,6 +965,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
|
||||
|
||||
@@ -9,10 +9,10 @@ for every navigation to keep Node.js working properly. Once Native Modules in th
|
||||
are required to be NAPI or context aware (Electron v11), this patch can be removed.
|
||||
|
||||
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
|
||||
index 8268205a1db1d3a1e4344640edd47745a61c0af4..01578ce536a7fad07766e60781282b87191b1296 100644
|
||||
index 0e417d912d488a4615a584a8fc193f292da832d5..61a9fde7f712ca578eebcf1114fa0d49dcf25c49 100644
|
||||
--- a/chrome/renderer/chrome_content_renderer_client.cc
|
||||
+++ b/chrome/renderer/chrome_content_renderer_client.cc
|
||||
@@ -1282,6 +1282,25 @@ ChromeContentRendererClient::GetProtocolHandlerSecurityLevel() {
|
||||
@@ -1289,6 +1289,25 @@ ChromeContentRendererClient::GetProtocolHandlerSecurityLevel() {
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -92,10 +92,10 @@ index 357df68c64071ef7dca98ce4aab885dd936b1c49..f501a2ab0bd6d4664dad13913671c4d7
|
||||
// |url|. If the function returns a valid |new_url|, the request must be
|
||||
// updated to use it.
|
||||
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
|
||||
index eb777512e2cb36c6b4ae03cd0c0d728d76bd95fc..3f9d1ba1217c43d18322e603c7958d94497c88f6 100644
|
||||
index 2dc0c1e0d5bfc32e0d6506d75a0353a2f5c140a6..143115a151b37a9b7193a34d1564aaab6e5ca8f6 100644
|
||||
--- a/content/renderer/render_frame_impl.cc
|
||||
+++ b/content/renderer/render_frame_impl.cc
|
||||
@@ -5451,6 +5451,23 @@ void RenderFrameImpl::BeginNavigation(
|
||||
@@ -5456,6 +5456,23 @@ void RenderFrameImpl::BeginNavigation(
|
||||
// we can do a per-frame check here rather than a process-wide check.
|
||||
bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) ||
|
||||
(enabled_bindings_ & kWebUIBindingsPolicyMask);
|
||||
|
||||
@@ -9,7 +9,7 @@ is needed for OSR.
|
||||
Originally landed in https://github.com/electron/libchromiumcontent/pull/226.
|
||||
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index 81ecd2d06104aa125c95d40336e8192ec23a1206..3ea1b844a80f85da1d4e3c47d0a33d0e9eeb02ef 100644
|
||||
index eac2487f18332616b1550bd7fa1f39f5c532b079..bc54b385d792eaad00c13fe43e9be1536397c5d7 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -2725,6 +2725,12 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params) {
|
||||
|
||||
9898
patches/chromium/word_break_between_space_and_alphanumeric.patch
Normal file
9898
patches/chromium/word_break_between_space_and_alphanumeric.patch
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,6 @@ build_modify_js2c_py_to_allow_injection_of_original-fs_and_custom_embedder_js.pa
|
||||
refactor_allow_embedder_overriding_of_internal_fs_calls.patch
|
||||
chore_prevent_warn_non_context-aware_native_modules_being_loaded.patch
|
||||
chore_read_nobrowserglobals_from_global_not_process.patch
|
||||
build_bring_back_node_with_ltcg_configuration.patch
|
||||
revert_crypto_add_oaeplabel_option.patch
|
||||
enable_31_bit_smis_on_64bit_arch_and_ptr_compression.patch
|
||||
fix_use_crypto_impls_for_compat.patch
|
||||
@@ -32,3 +31,4 @@ fix_add_safeforterminationscopes_for_sigint_interruptions.patch
|
||||
remove_makeexternal_case_for_uncached_internal_strings.patch
|
||||
fix_remove_outdated_--experimental-wasm-bigint_flag.patch
|
||||
fix_parallel_test-crypto-ecdh-convert-key_to_use_compatible_group.patch
|
||||
src_inline_asynccleanuphookhandle_in_headers.patch
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Deepak Mohan <hop2deep@gmail.com>
|
||||
Date: Wed, 16 Oct 2019 13:41:12 -0700
|
||||
Subject: build: bring back node_with_ltcg configuration
|
||||
|
||||
This was moved to code node.gyp as part of https://github.com/nodejs/node/pull/25931
|
||||
which caused native modules size increase which were depending on
|
||||
this configuration transitively https://github.com/nodejs/node/issues/29501.
|
||||
THe fix for this should land in node-gyp as discussed in above issue,
|
||||
landing this as temporary patch.
|
||||
|
||||
diff --git a/common.gypi b/common.gypi
|
||||
index d37d29736ead82aca6c89cc7625ca4d9a053da32..ffb80656d4a2117b7ee4cd5bd2d7aabfef16122b 100644
|
||||
--- a/common.gypi
|
||||
+++ b/common.gypi
|
||||
@@ -19,7 +19,7 @@
|
||||
'node_use_v8_platform%': 'true',
|
||||
'node_use_bundled_v8%': 'true',
|
||||
'node_module_version%': '',
|
||||
- 'node_with_ltcg%': '',
|
||||
+ 'node_with_ltcg%': 'true',
|
||||
'node_shared_openssl%': 'false',
|
||||
|
||||
'node_tag%': '',
|
||||
@@ -232,6 +232,26 @@
|
||||
'cflags': [ '-fPIC' ],
|
||||
'ldflags': [ '-fPIC' ]
|
||||
}],
|
||||
+ ['node_with_ltcg=="true"', {
|
||||
+ 'msvs_settings': {
|
||||
+ 'VCCLCompilerTool': {
|
||||
+ 'WholeProgramOptimization': 'true' # /GL, whole program optimization, needed for LTCG
|
||||
+ },
|
||||
+ 'VCLibrarianTool': {
|
||||
+ 'AdditionalOptions': [
|
||||
+ '/LTCG:INCREMENTAL', # incremental link-time code generation
|
||||
+ ]
|
||||
+ },
|
||||
+ 'VCLinkerTool': {
|
||||
+ 'OptimizeReferences': 2, # /OPT:REF
|
||||
+ 'EnableCOMDATFolding': 2, # /OPT:ICF
|
||||
+ 'LinkIncremental': 1, # disable incremental linking
|
||||
+ 'AdditionalOptions': [
|
||||
+ '/LTCG:INCREMENTAL', # incremental link-time code generation
|
||||
+ ]
|
||||
+ }
|
||||
+ }
|
||||
+ }]
|
||||
],
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user