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']
|
2014-10-25 02:01:19 +00:00
|
|
|
'console-message': ['level', 'message', 'line', 'sourceId']
|
2014-11-04 09:59:15 +00:00
|
|
|
'new-window': ['url', 'frameName', 'disposition']
|
2014-10-25 02:01:19 +00:00
|
|
|
'close': []
|
2014-10-25 01:05:50 +00:00
|
|
|
'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]
|
2014-10-25 07:48:59 +00:00
|
|
|
webView.dispatchEvent domEvent
|
2014-10-25 01:05:50 +00:00
|
|
|
|
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-25 07:48:59 +00:00
|
|
|
ipc.on 'ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED', (args...) ->
|
|
|
|
domEvent = new Event('size-changed')
|
|
|
|
for f, i in ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
|
|
|
|
domEvent[f] = args[i]
|
|
|
|
webView.onSizeChanged domEvent
|
|
|
|
|
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
|