refactor: implement <webview> methods via dedicated IPCs without the remote module (#14377)

This commit is contained in:
Milan Burda 2018-10-01 03:07:50 +02:00 committed by Cheng Zhao
parent ce38be74df
commit d48f9bcf7f
4 changed files with 73 additions and 48 deletions

View file

@ -1,8 +1,9 @@
'use strict'
const { ipcRenderer } = require('electron')
const WebViewImpl = require('@electron/internal/renderer/web-view/web-view')
const webViewConstants = require('@electron/internal/renderer/web-view/web-view-constants')
const { remote } = require('electron')
const errorUtils = require('@electron/internal/common/error-utils')
// Helper function to resolve url set in attribute.
const a = document.createElement('a')
@ -180,8 +181,15 @@ class SrcAttribute extends WebViewAttribute {
if (useragent) {
opts.userAgent = useragent
}
const guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId)
guestContents.loadURL(this.getValue(), opts)
const guestInstanceId = this.webViewImpl.guestInstanceId
const method = 'loadURL'
const args = [this.getValue(), opts]
const [error] = ipcRenderer.sendSync('ELECTRON_BROWSER_SYNC_CALL_TO_GUEST_VIEW', guestInstanceId, method, args)
if (error) {
throw errorUtils.deserialize(error)
}
}
}