2016-03-25 19:57:17 +00:00
|
|
|
'use strict'
|
2016-03-18 18:51:02 +00:00
|
|
|
|
2016-03-25 19:57:17 +00:00
|
|
|
const ipcRenderer = require('electron').ipcRenderer
|
|
|
|
const webFrame = require('electron').webFrame
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-25 19:57:17 +00:00
|
|
|
var requestId = 0
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 22:20:06 +00:00
|
|
|
var WEB_VIEW_EVENTS = {
|
2016-01-12 02:40:23 +00:00
|
|
|
'load-commit': ['url', 'isMainFrame'],
|
|
|
|
'did-finish-load': [],
|
2016-04-05 02:24:58 +00:00
|
|
|
'did-fail-load': ['errorCode', 'errorDescription', 'validatedURL', 'isMainFrame'],
|
2016-01-12 02:40:23 +00:00
|
|
|
'did-frame-finish-load': ['isMainFrame'],
|
|
|
|
'did-start-loading': [],
|
|
|
|
'did-stop-loading': [],
|
2016-04-08 19:55:20 +00:00
|
|
|
'did-get-response-details': ['status', 'newURL', 'originalURL', 'httpResponseCode', 'requestMethod', 'referrer', 'headers', 'resourceType'],
|
2016-01-12 02:40:23 +00:00
|
|
|
'did-get-redirect-request': ['oldURL', 'newURL', 'isMainFrame'],
|
|
|
|
'dom-ready': [],
|
|
|
|
'console-message': ['level', 'message', 'line', 'sourceId'],
|
|
|
|
'devtools-opened': [],
|
|
|
|
'devtools-closed': [],
|
|
|
|
'devtools-focused': [],
|
|
|
|
'new-window': ['url', 'frameName', 'disposition', 'options'],
|
|
|
|
'will-navigate': ['url'],
|
|
|
|
'did-navigate': ['url'],
|
|
|
|
'did-navigate-in-page': ['url'],
|
|
|
|
'close': [],
|
|
|
|
'crashed': [],
|
|
|
|
'gpu-crashed': [],
|
|
|
|
'plugin-crashed': ['name', 'version'],
|
|
|
|
'media-started-playing': [],
|
|
|
|
'media-paused': [],
|
|
|
|
'did-change-theme-color': ['themeColor'],
|
|
|
|
'destroyed': [],
|
|
|
|
'page-title-updated': ['title', 'explicitSet'],
|
|
|
|
'page-favicon-updated': ['favicons'],
|
|
|
|
'enter-html-full-screen': [],
|
|
|
|
'leave-html-full-screen': [],
|
|
|
|
'found-in-page': ['result']
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 22:20:06 +00:00
|
|
|
var DEPRECATED_EVENTS = {
|
2016-01-12 02:40:23 +00:00
|
|
|
'page-title-updated': 'page-title-set'
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-25 19:57:17 +00:00
|
|
|
var dispatchEvent = function (webView, eventName, eventKey, ...args) {
|
|
|
|
var domEvent, f, i, j, len, ref1
|
2016-01-12 02:40:23 +00:00
|
|
|
if (DEPRECATED_EVENTS[eventName] != null) {
|
2016-03-25 19:57:17 +00:00
|
|
|
dispatchEvent.apply(null, [webView, DEPRECATED_EVENTS[eventName], eventKey].concat(args))
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
domEvent = new Event(eventName)
|
|
|
|
ref1 = WEB_VIEW_EVENTS[eventKey]
|
2016-01-12 02:40:23 +00:00
|
|
|
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
2016-03-25 19:57:17 +00:00
|
|
|
f = ref1[i]
|
|
|
|
domEvent[f] = args[i]
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
webView.dispatchEvent(domEvent)
|
2016-01-12 02:40:23 +00:00
|
|
|
if (eventName === 'load-commit') {
|
2016-03-25 19:57:17 +00:00
|
|
|
return webView.onLoadCommit(domEvent)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2016-03-25 19:57:17 +00:00
|
|
|
registerEvents: function (webView, viewInstanceId) {
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId, function (event, eventName, ...args) {
|
2016-03-25 19:57:17 +00:00
|
|
|
return dispatchEvent.apply(null, [webView, eventName, eventName].concat(args))
|
|
|
|
})
|
2016-03-18 18:51:02 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId, function (event, channel, ...args) {
|
2016-03-25 19:57:17 +00:00
|
|
|
var domEvent = new Event('ipc-message')
|
|
|
|
domEvent.channel = channel
|
|
|
|
domEvent.args = args
|
|
|
|
return webView.dispatchEvent(domEvent)
|
|
|
|
})
|
2016-03-18 18:51:02 +00:00
|
|
|
|
2016-04-06 23:21:26 +00:00
|
|
|
return ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId, function (event, ...args) {
|
2016-03-25 19:57:17 +00:00
|
|
|
var domEvent, f, i, j, len, ref1
|
|
|
|
domEvent = new Event('size-changed')
|
|
|
|
ref1 = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
|
2016-01-12 02:40:23 +00:00
|
|
|
for (i = j = 0, len = ref1.length; j < len; i = ++j) {
|
2016-03-25 19:57:17 +00:00
|
|
|
f = ref1[i]
|
|
|
|
domEvent[f] = args[i]
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
return webView.onSizeChanged(domEvent)
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
},
|
2016-03-25 19:57:17 +00:00
|
|
|
deregisterEvents: function (viewInstanceId) {
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId)
|
|
|
|
ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId)
|
|
|
|
return ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId)
|
2016-01-12 02:40:23 +00:00
|
|
|
},
|
2016-03-25 19:57:17 +00:00
|
|
|
createGuest: function (params, callback) {
|
|
|
|
requestId++
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId)
|
|
|
|
return ipcRenderer.once('ELECTRON_RESPONSE_' + requestId, callback)
|
2016-01-12 02:40:23 +00:00
|
|
|
},
|
2016-03-25 19:57:17 +00:00
|
|
|
attachGuest: function (elementInstanceId, guestInstanceId, params) {
|
2016-04-06 23:21:26 +00:00
|
|
|
ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params)
|
2016-03-25 19:57:17 +00:00
|
|
|
return webFrame.attachGuest(elementInstanceId)
|
2016-01-12 02:40:23 +00:00
|
|
|
},
|
2016-03-25 19:57:17 +00:00
|
|
|
destroyGuest: function (guestInstanceId) {
|
2016-04-06 23:21:26 +00:00
|
|
|
return ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId)
|
2016-01-12 02:40:23 +00:00
|
|
|
},
|
2016-03-25 19:57:17 +00:00
|
|
|
setSize: function (guestInstanceId, params) {
|
2016-04-06 23:21:26 +00:00
|
|
|
return ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params)
|
2016-03-28 23:36:08 +00:00
|
|
|
}
|
2016-03-25 19:57:17 +00:00
|
|
|
}
|