feat: deprecate modules internally using remote.require in sandboxed renderer context (#15145)
This commit is contained in:
parent
d5d1fa8290
commit
d561c5531b
12 changed files with 71 additions and 8 deletions
|
@ -65,6 +65,39 @@ not present, then the native module will fail to load on Windows, with an error
|
||||||
message like `Cannot find module`. See the [native module
|
message like `Cannot find module`. See the [native module
|
||||||
guide](/docs/tutorial/using-native-node-modules.md) for more.
|
guide](/docs/tutorial/using-native-node-modules.md) for more.
|
||||||
|
|
||||||
|
## `electron.screen` in renderer process
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Deprecated
|
||||||
|
require('electron').screen
|
||||||
|
// Replace with
|
||||||
|
require('electron').remote.screen
|
||||||
|
```
|
||||||
|
|
||||||
|
## `require` in sandboxed renderers
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Deprecated
|
||||||
|
require('child_process')
|
||||||
|
// Replace with
|
||||||
|
require('electron').remote.require('child_process')
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
|
require('fs')
|
||||||
|
// Replace with
|
||||||
|
require('electron').remote.require('fs')
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
|
require('os')
|
||||||
|
// Replace with
|
||||||
|
require('electron').remote.require('os')
|
||||||
|
|
||||||
|
// Deprecated
|
||||||
|
require('path')
|
||||||
|
// Replace with
|
||||||
|
require('electron').remote.require('path')
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
# Breaking API Changes (3.0)
|
# Breaking API Changes (3.0)
|
||||||
|
|
||||||
|
|
|
@ -93,9 +93,7 @@ if (process.platform === 'linux') {
|
||||||
}
|
}
|
||||||
|
|
||||||
app.allowNTLMCredentialsForAllDomains = function (allow) {
|
app.allowNTLMCredentialsForAllDomains = function (allow) {
|
||||||
if (!process.noDeprecation) {
|
deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')
|
||||||
deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')
|
|
||||||
}
|
|
||||||
const domains = allow ? '*' : ''
|
const domains = allow ? '*' : ''
|
||||||
if (!this.isReady()) {
|
if (!this.isReady()) {
|
||||||
this.commandLine.appendSwitch('auth-server-whitelist', domains)
|
this.commandLine.appendSwitch('auth-server-whitelist', domains)
|
||||||
|
|
|
@ -19,7 +19,9 @@ const deprecate = {
|
||||||
setHandler: (handler) => { deprecationHandler = handler },
|
setHandler: (handler) => { deprecationHandler = handler },
|
||||||
getHandler: () => deprecationHandler,
|
getHandler: () => deprecationHandler,
|
||||||
warn: (oldName, newName) => {
|
warn: (oldName, newName) => {
|
||||||
return deprecate.log(`'${oldName}' is deprecated. Use '${newName}' instead.`)
|
if (!process.noDeprecation) {
|
||||||
|
deprecate.log(`'${oldName}' is deprecated. Use '${newName}' instead.`)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
log: (message) => {
|
log: (message) => {
|
||||||
if (typeof deprecationHandler === 'function') {
|
if (typeof deprecationHandler === 'function') {
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { deprecate } = require('electron')
|
||||||
|
|
||||||
|
deprecate.warn(`electron.screen`, `electron.remote.screen`)
|
||||||
|
|
||||||
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
||||||
module.exports = getRemoteForUsage('screen').screen
|
module.exports = getRemoteForUsage('screen').screen
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { deprecate } = require('electron')
|
||||||
|
|
||||||
|
deprecate.warn(`require('child_process')`, `remote.require('child_process')`)
|
||||||
|
|
||||||
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
||||||
module.exports = getRemoteForUsage('child_process').require('child_process')
|
module.exports = getRemoteForUsage('child_process').require('child_process')
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { deprecate } = require('electron')
|
||||||
|
|
||||||
|
deprecate.warn(`require('fs')`, `remote.require('fs')`)
|
||||||
|
|
||||||
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
||||||
module.exports = getRemoteForUsage('fs').require('fs')
|
module.exports = getRemoteForUsage('fs').require('fs')
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { deprecate } = require('electron')
|
||||||
|
|
||||||
|
deprecate.warn(`require('os')`, `remote.require('os')`)
|
||||||
|
|
||||||
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
||||||
module.exports = getRemoteForUsage('os').require('os')
|
module.exports = getRemoteForUsage('os').require('os')
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { deprecate } = require('electron')
|
||||||
|
|
||||||
|
deprecate.warn(`require('path')`, `remote.require('path')`)
|
||||||
|
|
||||||
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
||||||
module.exports = getRemoteForUsage('path').require('path')
|
module.exports = getRemoteForUsage('path').require('path')
|
||||||
|
|
|
@ -90,6 +90,15 @@ Object.assign(preloadProcess, processProps)
|
||||||
Object.assign(process, binding.process)
|
Object.assign(process, binding.process)
|
||||||
Object.assign(process, processProps)
|
Object.assign(process, processProps)
|
||||||
|
|
||||||
|
Object.defineProperty(preloadProcess, 'noDeprecation', {
|
||||||
|
get () {
|
||||||
|
return process.noDeprecation
|
||||||
|
},
|
||||||
|
set (value) {
|
||||||
|
process.noDeprecation = value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
process.on('exit', () => preloadProcess.emit('exit'))
|
process.on('exit', () => preloadProcess.emit('exit'))
|
||||||
|
|
||||||
// This is the `require` function that will be visible to the preload script
|
// This is the `require` function that will be visible to the preload script
|
||||||
|
|
|
@ -11,8 +11,8 @@ const http = require('http')
|
||||||
const { closeWindow } = require('./window-helpers')
|
const { closeWindow } = require('./window-helpers')
|
||||||
const { emittedOnce } = require('./events-helpers')
|
const { emittedOnce } = require('./events-helpers')
|
||||||
const { resolveGetters } = require('./assert-helpers')
|
const { resolveGetters } = require('./assert-helpers')
|
||||||
const { ipcRenderer, remote, screen } = require('electron')
|
const { ipcRenderer, remote } = require('electron')
|
||||||
const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, webContents } = remote
|
const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, screen, webContents } = remote
|
||||||
|
|
||||||
const features = process.atomBinding('features')
|
const features = process.atomBinding('features')
|
||||||
const { expect } = chai
|
const { expect } = chai
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const dirtyChai = require('dirty-chai')
|
const dirtyChai = require('dirty-chai')
|
||||||
const { desktopCapturer, remote, screen } = require('electron')
|
const { desktopCapturer, remote } = require('electron')
|
||||||
|
const { screen } = remote
|
||||||
const features = process.atomBinding('features')
|
const features = process.atomBinding('features')
|
||||||
|
|
||||||
const { expect } = chai
|
const { expect } = chai
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const { screen } = require('electron')
|
const { screen } = require('electron').remote
|
||||||
|
|
||||||
describe('screen module', () => {
|
describe('screen module', () => {
|
||||||
describe('screen.getCursorScreenPoint()', () => {
|
describe('screen.getCursorScreenPoint()', () => {
|
||||||
|
|
Loading…
Reference in a new issue