2014-10-23 09:54:52 +00:00
|
|
|
ipc = require 'ipc'
|
|
|
|
webContents = require 'web-contents'
|
2014-10-23 15:08:48 +00:00
|
|
|
webViewManager = null # Doesn't exist in early initialization.
|
2014-10-23 09:54:52 +00:00
|
|
|
|
|
|
|
nextInstanceId = 0
|
|
|
|
guestInstances = {}
|
|
|
|
|
|
|
|
# Generate guestInstanceId.
|
|
|
|
getNextInstanceId = (webContents) ->
|
|
|
|
++nextInstanceId
|
|
|
|
|
|
|
|
# Create a new guest instance.
|
|
|
|
createGuest = (embedder, params) ->
|
2014-10-23 15:08:48 +00:00
|
|
|
webViewManager ?= process.atomBinding 'web_view_manager'
|
|
|
|
|
2014-10-23 09:54:52 +00:00
|
|
|
id = getNextInstanceId embedder
|
2014-10-24 08:19:00 +00:00
|
|
|
guest = webContents.create
|
2014-10-23 15:08:48 +00:00
|
|
|
isGuest: true
|
|
|
|
guestInstanceId: id
|
|
|
|
storagePartitionId: params.storagePartitionId
|
2014-10-24 08:19:00 +00:00
|
|
|
guestInstances[id] = guest
|
|
|
|
webViewManager.addGuest id, embedder, guest
|
|
|
|
|
|
|
|
# Destroy guest when the embedder is gone.
|
2014-10-24 08:48:21 +00:00
|
|
|
embedder.once 'render-view-deleted', ->
|
|
|
|
destroyGuest id
|
|
|
|
|
|
|
|
# Init guest web view after attached.
|
2014-10-24 10:44:15 +00:00
|
|
|
guest.once 'did-attach', (event, params) ->
|
2014-10-24 08:48:21 +00:00
|
|
|
min = width: params.minwidth, height: params.minheight
|
|
|
|
max = width: params.maxwidth, height: params.maxheight
|
|
|
|
@setAutoSize params.autosize, min, max
|
|
|
|
if params.src
|
|
|
|
@loadUrl params.src
|
|
|
|
if params.allowtransparency?
|
|
|
|
@setAllowTransparency params.allowtransparency
|
2014-10-24 08:19:00 +00:00
|
|
|
|
2014-10-23 09:54:52 +00:00
|
|
|
id
|
|
|
|
|
|
|
|
# Destroy an existing guest instance.
|
|
|
|
destroyGuest = (id) ->
|
2014-10-23 15:08:48 +00:00
|
|
|
webViewManager.removeGuest id
|
2014-10-23 09:54:52 +00:00
|
|
|
guestInstances[id].destroy()
|
|
|
|
delete guestInstances[id]
|
|
|
|
|
|
|
|
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', (event, type, params, requestId) ->
|
2014-10-23 15:08:48 +00:00
|
|
|
event.sender.send "ATOM_SHELL_RESPONSE_#{requestId}", createGuest(event.sender, params)
|
2014-10-23 09:54:52 +00:00
|
|
|
|
2014-10-24 08:48:21 +00:00
|
|
|
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, id) ->
|
|
|
|
destroyGuest id
|
2014-10-24 06:37:14 +00:00
|
|
|
|
2014-10-24 08:48:21 +00:00
|
|
|
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_AUTO_SIZE', (event, id, params) ->
|
2014-10-24 06:37:14 +00:00
|
|
|
guestInstances[id]?.setAutoSize params.enableAutoSize, params.min, params.max
|
2014-10-24 08:48:21 +00:00
|
|
|
|
|
|
|
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_ALLOW_TRANSPARENCY', (event, id, allowtransparency) ->
|
|
|
|
guestInstances[id]?.setAllowTransparency allowtransparency
|