feat: add webPreferences.enableRemoteModule option (#13028)
This commit is contained in:
parent
72db5ed7cb
commit
d3efc52745
36 changed files with 303 additions and 45 deletions
|
@ -1,6 +1,9 @@
|
|||
'use strict'
|
||||
|
||||
const features = process.atomBinding('features')
|
||||
const v8Util = process.atomBinding('v8_util')
|
||||
|
||||
const enableRemoteModule = v8Util.getHiddenValue(global, 'enableRemoteModule')
|
||||
|
||||
// Renderer side modules, please sort alphabetically.
|
||||
// A module is `enabled` if there is no explicit condition defined.
|
||||
|
@ -11,8 +14,8 @@ module.exports = [
|
|||
file: 'desktop-capturer',
|
||||
enabled: features.isDesktopCapturerEnabled()
|
||||
},
|
||||
{ name: 'ipcRenderer', file: 'ipc-renderer', enabled: true },
|
||||
{ name: 'remote', file: 'remote', enabled: true },
|
||||
{ name: 'screen', file: 'screen', enabled: true },
|
||||
{ name: 'webFrame', file: 'web-frame', enabled: true }
|
||||
{ name: 'ipcRenderer', file: 'ipc-renderer' },
|
||||
{ name: 'remote', file: 'remote', enabled: enableRemoteModule },
|
||||
{ name: 'screen', file: 'screen' },
|
||||
{ name: 'webFrame', file: 'web-frame' }
|
||||
]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict'
|
||||
|
||||
module.exports = require('electron').remote.screen
|
||||
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
||||
module.exports = getRemoteForUsage('screen').screen
|
||||
|
|
10
lib/renderer/remote.js
Normal file
10
lib/renderer/remote.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
'use strict'
|
||||
|
||||
const { remote } = require('electron')
|
||||
|
||||
exports.getRemoteForUsage = function (usage) {
|
||||
if (!remote) {
|
||||
throw new Error(`${usage} requires remote, which is not enabled`)
|
||||
}
|
||||
return remote
|
||||
}
|
|
@ -248,6 +248,20 @@ class WebPreferencesAttribute extends WebViewAttribute {
|
|||
}
|
||||
}
|
||||
|
||||
class EnableRemoteModuleAttribute extends WebViewAttribute {
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_ENABLEREMOTEMODULE, webViewImpl)
|
||||
}
|
||||
|
||||
getValue () {
|
||||
return this.webViewImpl.webviewNode.getAttribute(this.name) !== 'false'
|
||||
}
|
||||
|
||||
setValue (value) {
|
||||
this.webViewImpl.webviewNode.setAttribute(this.name, value ? 'true' : 'false')
|
||||
}
|
||||
}
|
||||
|
||||
// Sets up all of the webview attributes.
|
||||
WebViewImpl.prototype.setupWebViewAttributes = function () {
|
||||
this.attributes = {}
|
||||
|
@ -259,6 +273,7 @@ WebViewImpl.prototype.setupWebViewAttributes = function () {
|
|||
this.attributes[webViewConstants.ATTRIBUTE_PLUGINS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_PLUGINS, this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_DISABLEWEBSECURITY] = new BooleanAttribute(webViewConstants.ATTRIBUTE_DISABLEWEBSECURITY, this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_ALLOWPOPUPS] = new BooleanAttribute(webViewConstants.ATTRIBUTE_ALLOWPOPUPS, this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_ENABLEREMOTEMODULE] = new EnableRemoteModuleAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_BLINKFEATURES] = new BlinkFeaturesAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_DISABLEBLINKFEATURES] = new DisableBlinkFeaturesAttribute(this)
|
||||
|
|
|
@ -7,6 +7,7 @@ module.exports = {
|
|||
ATTRIBUTE_SRC: 'src',
|
||||
ATTRIBUTE_HTTPREFERRER: 'httpreferrer',
|
||||
ATTRIBUTE_NODEINTEGRATION: 'nodeintegration',
|
||||
ATTRIBUTE_ENABLEREMOTEMODULE: 'enableremotemodule',
|
||||
ATTRIBUTE_PLUGINS: 'plugins',
|
||||
ATTRIBUTE_DISABLEWEBSECURITY: 'disablewebsecurity',
|
||||
ATTRIBUTE_ALLOWPOPUPS: 'allowpopups',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict'
|
||||
|
||||
const { remote, webFrame } = require('electron')
|
||||
const { webFrame } = require('electron')
|
||||
|
||||
const v8Util = process.atomBinding('v8_util')
|
||||
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
|
||||
|
@ -337,6 +337,8 @@ const registerWebViewElement = function () {
|
|||
|
||||
// WebContents associated with this webview.
|
||||
proto.getWebContents = function () {
|
||||
const { getRemoteForUsage } = require('@electron/internal/renderer/remote')
|
||||
const remote = getRemoteForUsage('getWebContents()')
|
||||
const internal = v8Util.getHiddenValue(this, 'internal')
|
||||
if (!internal.guestInstanceId) {
|
||||
internal.createGuestSync()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue