Skip to content

Commit

Permalink
feat: deprecate modules internally using remote.require in sandboxed …
Browse files Browse the repository at this point in the history
…renderer context (#15145)
  • Loading branch information
miniak authored and alexeykuzmin committed Dec 5, 2018
1 parent d5d1fa8 commit d561c55
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 8 deletions.
33 changes: 33 additions & 0 deletions docs/api/breaking-changes.md
Expand Up @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions lib/browser/api/app.js
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion lib/common/api/deprecate.js
Expand Up @@ -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') {
Expand Down
4 changes: 4 additions & 0 deletions lib/renderer/api/screen.js
@@ -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
4 changes: 4 additions & 0 deletions lib/sandboxed_renderer/api/exports/child_process.js
@@ -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')
4 changes: 4 additions & 0 deletions lib/sandboxed_renderer/api/exports/fs.js
@@ -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')
4 changes: 4 additions & 0 deletions lib/sandboxed_renderer/api/exports/os.js
@@ -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')
4 changes: 4 additions & 0 deletions lib/sandboxed_renderer/api/exports/path.js
@@ -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')
9 changes: 9 additions & 0 deletions lib/sandboxed_renderer/init.js
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/api-browser-window-spec.js
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/api-desktop-capturer-spec.js
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/api-screen-spec.js
@@ -1,5 +1,5 @@
const assert = require('assert')
const { screen } = require('electron')
const { screen } = require('electron').remote

describe('screen module', () => {
describe('screen.getCursorScreenPoint()', () => {
Expand Down

0 comments on commit d561c55

Please sign in to comment.