electron/atom/renderer/lib/web-view/guest-view-internal.coffee

87 lines
3.5 KiB
CoffeeScript
Raw Normal View History

{ipcRenderer, webFrame} = require 'electron'
requestId = 0
WEB_VIEW_EVENTS =
2015-08-05 11:50:23 +00:00
'load-commit': ['url', 'isMainFrame']
'did-finish-load': []
2015-11-13 08:03:40 +00:00
'did-fail-load': ['errorCode', 'errorDescription', 'validatedURL']
'did-frame-finish-load': ['isMainFrame']
'did-start-loading': []
'did-stop-loading': []
2015-11-13 08:03:40 +00:00
'did-get-response-details': ['status', 'newURL', 'originalURL',
'httpResponseCode', 'requestMethod', 'referrer',
'headers']
2015-11-13 08:03:40 +00:00
'did-get-redirect-request': ['oldURL', 'newURL', 'isMainFrame']
2015-04-29 13:49:31 +00:00
'dom-ready': []
'console-message': ['level', 'message', 'line', 'sourceId']
'devtools-opened': []
'devtools-closed': []
'devtools-focused': []
2015-09-22 15:39:31 +00:00
'new-window': ['url', 'frameName', 'disposition', 'options']
'close': []
'crashed': []
'gpu-crashed': []
'plugin-crashed': ['name', 'version']
2015-12-20 03:16:22 +00:00
'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': []
2015-12-17 23:10:42 +00:00
'found-in-page': ['result']
DEPRECATED_EVENTS =
'page-title-updated': 'page-title-set'
dispatchEvent = (webView, eventName, eventKey, args...) ->
if DEPRECATED_EVENTS[eventName]?
dispatchEvent webView, DEPRECATED_EVENTS[eventName], eventKey, args...
domEvent = new Event(eventName)
for f, i in WEB_VIEW_EVENTS[eventKey]
domEvent[f] = args[i]
webView.dispatchEvent domEvent
webView.onLoadCommit domEvent if eventName is 'load-commit'
module.exports =
registerEvents: (webView, viewInstanceId) ->
ipcRenderer.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, eventName, args...) ->
dispatchEvent webView, eventName, eventName, args...
ipcRenderer.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}", (event, channel, args...) ->
domEvent = new Event('ipc-message')
domEvent.channel = channel
domEvent.args = [args...]
webView.dispatchEvent domEvent
ipcRenderer.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}", (event, args...) ->
domEvent = new Event('size-changed')
for f, i in ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
domEvent[f] = args[i]
webView.onSizeChanged domEvent
deregisterEvents: (viewInstanceId) ->
ipcRenderer.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}"
ipcRenderer.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}"
ipcRenderer.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}"
2015-05-29 03:44:49 +00:00
createGuest: (params, callback) ->
requestId++
ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId
ipcRenderer.once "ATOM_SHELL_RESPONSE_#{requestId}", callback
2014-12-08 16:05:34 +00:00
attachGuest: (elementInstanceId, guestInstanceId, params) ->
ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params
2014-12-08 16:05:34 +00:00
webFrame.attachGuest elementInstanceId
destroyGuest: (guestInstanceId) ->
ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId
setSize: (guestInstanceId, params) ->
ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params
2014-10-24 08:48:21 +00:00
setAllowTransparency: (guestInstanceId, allowtransparency) ->
ipcRenderer.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', guestInstanceId, allowtransparency