Merge pull request #6685 from electron/document-contents-zoom
Implement and Document the zoom methods that are mapped to the webContents object
This commit is contained in:
commit
56b1abd64a
3 changed files with 60 additions and 5 deletions
|
@ -89,6 +89,11 @@ const webFrameMethods = [
|
|||
'setZoomLevelLimits'
|
||||
]
|
||||
|
||||
const webFrameMethodsWithResult = [
|
||||
'getZoomFactor',
|
||||
'getZoomLevel'
|
||||
]
|
||||
|
||||
// Add JavaScript wrappers for WebContents class.
|
||||
const wrapWebContents = function (webContents) {
|
||||
// webContents is an EventEmitter.
|
||||
|
@ -120,6 +125,20 @@ const wrapWebContents = function (webContents) {
|
|||
}
|
||||
}
|
||||
|
||||
const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
|
||||
this.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', requestId, method, args)
|
||||
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
||||
if (callback) callback(result)
|
||||
})
|
||||
}
|
||||
|
||||
const syncWebFrameMethods = function (requestId, method, callback, ...args) {
|
||||
this.send('ELECTRON_INTERNAL_RENDERER_SYNC_WEB_FRAME_METHOD', requestId, method, args)
|
||||
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_SYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
||||
if (callback) callback(result)
|
||||
})
|
||||
}
|
||||
|
||||
// Mapping webFrame methods.
|
||||
for (const method of webFrameMethods) {
|
||||
webContents[method] = function (...args) {
|
||||
|
@ -127,11 +146,12 @@ const wrapWebContents = function (webContents) {
|
|||
}
|
||||
}
|
||||
|
||||
const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
|
||||
this.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', requestId, method, args)
|
||||
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
||||
if (callback) callback(result)
|
||||
})
|
||||
for (const method of webFrameMethodsWithResult) {
|
||||
webContents[method] = function (...args) {
|
||||
const callback = args[args.length - 1]
|
||||
const actualArgs = args.slice(0, args.length - 2)
|
||||
syncWebFrameMethods.call(this, getNextId(), method, callback, ...actualArgs)
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure webContents.executeJavaScript would run the code only when the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue