PR 44648: Enabling creation on webview with node-integration disabled and raising events
- Enabling creation on webview with node-integration disabled and raising events Conflicts: lib/browser/guest-view-manager.js
This commit is contained in:
parent
b712521056
commit
b4a8ed01f1
6 changed files with 51 additions and 23 deletions
|
@ -406,6 +406,9 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
|
||||||
|
|
||||||
Init(isolate);
|
Init(isolate);
|
||||||
AttachAsUserData(web_contents);
|
AttachAsUserData(web_contents);
|
||||||
|
|
||||||
|
if (IsGuest())
|
||||||
|
Emit("did-create-webview");
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContents::~WebContents() {
|
WebContents::~WebContents() {
|
||||||
|
|
|
@ -218,6 +218,17 @@ When in-page navigation happens, the page URL changes but does not cause
|
||||||
navigation outside of the page. Examples of this occurring are when anchor links
|
navigation outside of the page. Examples of this occurring are when anchor links
|
||||||
are clicked or when the DOM `hashchange` event is triggered.
|
are clicked or when the DOM `hashchange` event is triggered.
|
||||||
|
|
||||||
|
#### Event: 'will-create-webview'
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
* `event` Event
|
||||||
|
* `params` Object
|
||||||
|
|
||||||
|
Emitted when web-view will be created.
|
||||||
|
|
||||||
|
Use this event to remove preload scripts or stop creating webviews.
|
||||||
|
|
||||||
#### Event: 'crashed'
|
#### Event: 'crashed'
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
|
@ -15,9 +15,6 @@ between your app and embedded content will be asynchronous. This keeps your app
|
||||||
safe from the embedded content. **Note:** Most methods called on the
|
safe from the embedded content. **Note:** Most methods called on the
|
||||||
webview from the host page require a syncronous call to the main process.
|
webview from the host page require a syncronous call to the main process.
|
||||||
|
|
||||||
For security purposes, `webview` can only be used in `BrowserWindow`s that have
|
|
||||||
`nodeIntegration` enabled.
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
To embed a web page in your app, add the `webview` tag to your app's embedder
|
To embed a web page in your app, add the `webview` tag to your app's embedder
|
||||||
|
|
|
@ -297,7 +297,10 @@ ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_CREATE_GUEST', function (event, params,
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST', function (event, elementInstanceId, guestInstanceId, params) {
|
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST', function (event, elementInstanceId, guestInstanceId, params) {
|
||||||
attachGuest(event, elementInstanceId, guestInstanceId, params)
|
event.sender.emit('will-create-webview', event, params)
|
||||||
|
if (!event.defaultPrevented) {
|
||||||
|
attachGuest(event, elementInstanceId, guestInstanceId, params)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', function (event, guestInstanceId) {
|
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', function (event, guestInstanceId) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ if (window.location.protocol === 'chrome-devtools:') {
|
||||||
require('./content-scripts-injector')
|
require('./content-scripts-injector')
|
||||||
|
|
||||||
// Load webview tag implementation.
|
// Load webview tag implementation.
|
||||||
if (nodeIntegration === 'true' && process.guestInstanceId == null) {
|
if (process.guestInstanceId == null) {
|
||||||
require('./web-view/web-view')
|
require('./web-view/web-view')
|
||||||
require('./web-view/web-view-attributes')
|
require('./web-view/web-view-attributes')
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,24 +36,6 @@ describe('<webview> tag', function () {
|
||||||
w.loadURL('file://' + fixtures + '/pages/webview-no-script.html')
|
w.loadURL('file://' + fixtures + '/pages/webview-no-script.html')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('is disabled when nodeIntegration is disabled', function (done) {
|
|
||||||
w = new BrowserWindow({
|
|
||||||
show: false,
|
|
||||||
webPreferences: {
|
|
||||||
nodeIntegration: false,
|
|
||||||
preload: path.join(fixtures, 'module', 'preload-webview.js')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
ipcMain.once('webview', function (event, type) {
|
|
||||||
if (type === 'undefined') {
|
|
||||||
done()
|
|
||||||
} else {
|
|
||||||
done('WebView still exists')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
w.loadURL('file://' + fixtures + '/pages/webview-no-script.html')
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('src attribute', function () {
|
describe('src attribute', function () {
|
||||||
it('specifies the page to load', function (done) {
|
it('specifies the page to load', function (done) {
|
||||||
webview.addEventListener('console-message', function (e) {
|
webview.addEventListener('console-message', function (e) {
|
||||||
|
@ -64,6 +46,38 @@ describe('<webview> tag', function () {
|
||||||
document.body.appendChild(webview)
|
document.body.appendChild(webview)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('disables node integration when disabled on the parent BrowserWindow', function (done) {
|
||||||
|
ipcMain.once('answer', function (event, typeofProcess) {
|
||||||
|
try {
|
||||||
|
assert.equal(typeofProcess, 'undefined')
|
||||||
|
done()
|
||||||
|
} finally {
|
||||||
|
b.close()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
var windowUrl = require('url').format({
|
||||||
|
pathname: `${fixtures}/pages/webview-no-node-integration-on-window.html`,
|
||||||
|
protocol: 'file',
|
||||||
|
query: {
|
||||||
|
p: `${fixtures}/pages/web-view-log-process.html`
|
||||||
|
},
|
||||||
|
slashes: true
|
||||||
|
})
|
||||||
|
var preload = path.join(fixtures, 'module', 'answer.js')
|
||||||
|
|
||||||
|
var b = new BrowserWindow({
|
||||||
|
height: 400,
|
||||||
|
width: 400,
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
preload: preload,
|
||||||
|
nodeIntegration: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
b.loadURL(windowUrl)
|
||||||
|
})
|
||||||
|
|
||||||
it('navigates to new page when changed', function (done) {
|
it('navigates to new page when changed', function (done) {
|
||||||
var listener = function () {
|
var listener = function () {
|
||||||
webview.src = 'file://' + fixtures + '/pages/b.html'
|
webview.src = 'file://' + fixtures + '/pages/b.html'
|
||||||
|
|
Loading…
Reference in a new issue