2014-10-23 09:54:52 +00:00
|
|
|
ipc = require 'ipc'
|
2014-12-08 16:05:34 +00:00
|
|
|
webFrame = require 'web-frame'
|
2014-10-23 09:54:52 +00:00
|
|
|
|
|
|
|
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': []
|
2015-04-08 13:44:47 +00:00
|
|
|
'did-get-response-details': ['status', 'newUrl', 'originalUrl',
|
2015-05-20 12:35:54 +00:00
|
|
|
'httpResponseCode', 'requestMethod', 'referrer']
|
2014-10-25 01:05:50 +00:00
|
|
|
'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
|
2015-04-29 13:49:31 +00:00
|
|
|
'dom-ready': []
|
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': []
|
2015-05-12 19:35:56 +00:00
|
|
|
'gpu-crashed': []
|
|
|
|
'plugin-crashed': ['name', 'version']
|
2014-10-25 01:05:50 +00:00
|
|
|
'destroyed': []
|
2015-04-05 09:20:42 +00:00
|
|
|
'page-title-set': ['title', 'explicitSet']
|
2015-04-20 06:50:04 +00:00
|
|
|
'page-favicon-updated': ['favicons']
|
2014-10-25 01:05:50 +00:00
|
|
|
|
|
|
|
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-12-17 05:10:53 +00:00
|
|
|
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
|
|
|
|
|
2014-12-13 01:16:12 +00:00
|
|
|
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_SIZE_CHANGED-#{viewInstanceId}", (args...) ->
|
2014-10-25 07:48:59 +00:00
|
|
|
domEvent = new Event('size-changed')
|
|
|
|
for f, i in ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
|
|
|
|
domEvent[f] = args[i]
|
|
|
|
webView.onSizeChanged domEvent
|
|
|
|
|
2015-03-23 15:07:53 +00:00
|
|
|
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}"
|
|
|
|
|
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
|
2014-12-08 16:05:34 +00:00
|
|
|
ipc.once "ATOM_SHELL_RESPONSE_#{requestId}", callback
|
|
|
|
|
2015-01-12 22:17:49 +00:00
|
|
|
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
|
2014-10-23 09:54:52 +00:00
|
|
|
|
|
|
|
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
|