feat: deprecate modules internally using remote.require in sandboxed renderer context (#15145)

This commit is contained in:
Milan Burda 2018-12-05 10:34:09 +01:00 коммит произвёл Alexey Kuzmin
Родитель d5d1fa8290
Коммит d561c5531b
12 изменённых файлов: 71 добавлений и 8 удалений

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

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

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

@ -93,9 +93,7 @@ if (process.platform === 'linux') {
}
app.allowNTLMCredentialsForAllDomains = function (allow) {
if (!process.noDeprecation) {
deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')
}
deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')
const domains = allow ? '*' : ''
if (!this.isReady()) {
this.commandLine.appendSwitch('auth-server-whitelist', domains)

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

@ -19,7 +19,9 @@ const deprecate = {
setHandler: (handler) => { deprecationHandler = handler },
getHandler: () => deprecationHandler,
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) => {
if (typeof deprecationHandler === 'function') {

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

@ -1,4 +1,8 @@
'use strict'
const { deprecate } = require('electron')
deprecate.warn(`electron.screen`, `electron.remote.screen`)
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
module.exports = getRemoteForUsage('screen').screen

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

@ -1,4 +1,8 @@
'use strict'
const { deprecate } = require('electron')
deprecate.warn(`require('child_process')`, `remote.require('child_process')`)
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
module.exports = getRemoteForUsage('child_process').require('child_process')

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

@ -1,4 +1,8 @@
'use strict'
const { deprecate } = require('electron')
deprecate.warn(`require('fs')`, `remote.require('fs')`)
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
module.exports = getRemoteForUsage('fs').require('fs')

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

@ -1,4 +1,8 @@
'use strict'
const { deprecate } = require('electron')
deprecate.warn(`require('os')`, `remote.require('os')`)
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
module.exports = getRemoteForUsage('os').require('os')

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

@ -1,4 +1,8 @@
'use strict'
const { deprecate } = require('electron')
deprecate.warn(`require('path')`, `remote.require('path')`)
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
module.exports = getRemoteForUsage('path').require('path')

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

@ -90,6 +90,15 @@ Object.assign(preloadProcess, processProps)
Object.assign(process, binding.process)
Object.assign(process, processProps)
Object.defineProperty(preloadProcess, 'noDeprecation', {
get () {
return process.noDeprecation
},
set (value) {
process.noDeprecation = value
}
})
process.on('exit', () => preloadProcess.emit('exit'))
// 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 { emittedOnce } = require('./events-helpers')
const { resolveGetters } = require('./assert-helpers')
const { ipcRenderer, remote, screen } = require('electron')
const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, webContents } = remote
const { ipcRenderer, remote } = require('electron')
const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, screen, webContents } = remote
const features = process.atomBinding('features')
const { expect } = chai

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

@ -1,6 +1,7 @@
const chai = require('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 { expect } = chai

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

@ -1,5 +1,5 @@
const assert = require('assert')
const { screen } = require('electron')
const { screen } = require('electron').remote
describe('screen module', () => {
describe('screen.getCursorScreenPoint()', () => {