2014-10-23 09:54:52 +00:00
|
|
|
ipc = require 'ipc'
|
|
|
|
|
|
|
|
requestId = 0
|
|
|
|
|
2014-10-25 01:05:50 +00:00
|
|
|
WEB_VIEW_EVENTS =
|
|
|
|
'did-finish-load': []
|
|
|
|
'did-fail-load': ['errorCode', 'errorDescription']
|
|
|
|
'did-frame-finish-load': ['isMainFrame']
|
|
|
|
'did-start-loading': []
|
|
|
|
'did-stop-loading': []
|
|
|
|
'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
|
|
|
|
'crashed': []
|
|
|
|
'destroyed': []
|
|
|
|
|
|
|
|
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.webviewNode.dispatchEvent domEvent
|
|
|
|
|
2014-10-23 09:54:52 +00:00
|
|
|
module.exports =
|
2014-10-25 01:05:50 +00:00
|
|
|
registerEvents: (webView, viewInstanceId) ->
|
|
|
|
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, args...) ->
|
|
|
|
dispatchEvent webView, event, args...
|
|
|
|
|
2014-10-23 09:54:52 +00:00
|
|
|
createGuest: (type, params, callback) ->
|
|
|
|
requestId++
|
|
|
|
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', type, params, requestId
|
|
|
|
ipc.on "ATOM_SHELL_RESPONSE_#{requestId}", callback
|
|
|
|
|
|
|
|
destroyGuest: (guestInstanceId) ->
|
|
|
|
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId
|
2014-10-24 06:37:14 +00:00
|
|
|
|
|
|
|
setAutoSize: (guestInstanceId, params) ->
|
|
|
|
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_AUTO_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
|