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

75 lines
2.9 KiB
CoffeeScript
Raw Normal View History

ipc = require 'ipc'
2014-12-08 16:05:34 +00:00
webFrame = require 'web-frame'
requestId = 0
WEB_VIEW_EVENTS =
'did-finish-load': []
'did-fail-load': ['errorCode', 'errorDescription']
'did-frame-finish-load': ['isMainFrame']
'did-start-loading': []
'did-stop-loading': []
'did-get-response-details': ['status', 'newUrl', 'originalUrl',
'httpResponseCode', 'requestMethod', 'referrer',
'headers']
'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
2015-04-29 13:49:31 +00:00
'dom-ready': []
'console-message': ['level', 'message', 'line', 'sourceId']
'new-window': ['url', 'frameName', 'disposition']
'close': []
'crashed': []
'gpu-crashed': []
'plugin-crashed': ['name', 'version']
'destroyed': []
2015-04-05 09:20:42 +00:00
'page-title-set': ['title', 'explicitSet']
'page-favicon-updated': ['favicons']
'enter-html-full-screen': []
'leave-html-full-screen': []
dispatchEvent = (webView, event, args...) ->
throw new Error("Unkown event #{event}") unless WEB_VIEW_EVENTS[event]?
domEvent = new Event(event)
for f, i in WEB_VIEW_EVENTS[event]
domEvent[f] = args[i]
webView.dispatchEvent domEvent
module.exports =
registerEvents: (webView, viewInstanceId) ->
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, args...) ->
dispatchEvent webView, event, args...
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}", (channel, args...) ->
domEvent = new Event('ipc-message')
domEvent.channel = channel
domEvent.args = [args...]
webView.dispatchEvent domEvent
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}", (args...) ->
domEvent = new Event('size-changed')
for f, i in ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
domEvent[f] = args[i]
webView.onSizeChanged domEvent
deregisterEvents: (viewInstanceId) ->
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}"
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_IPC_MESSAGE-#{viewInstanceId}"
ipc.removeAllListeners "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}"
2015-05-29 03:44:49 +00:00
createGuest: (params, callback) ->
requestId++
2015-05-29 03:44:49 +00:00
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId
2014-12-08 16:05:34 +00:00
ipc.once "ATOM_SHELL_RESPONSE_#{requestId}", callback
attachGuest: (elementInstanceId, guestInstanceId, params) ->
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params
2014-12-08 16:05:34 +00:00
webFrame.attachGuest elementInstanceId
destroyGuest: (guestInstanceId) ->
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId
setSize: (guestInstanceId, params) ->
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params
2014-10-24 08:48:21 +00:00
setAllowTransparency: (guestInstanceId, allowtransparency) ->
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', guestInstanceId, allowtransparency