electron/atom/browser/lib/guest-view-manager.coffee

38 lines
1.2 KiB
CoffeeScript
Raw Normal View History

ipc = require 'ipc'
webContents = require 'web-contents'
2014-10-23 15:08:48 +00:00
webViewManager = null # Doesn't exist in early initialization.
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'
id = getNextInstanceId embedder
2014-10-23 15:08:48 +00:00
guestInstances[id] = webContents.create
isGuest: true
guestInstanceId: id
storagePartitionId: params.storagePartitionId
webViewManager.addGuest id, embedder, guestInstances[id]
id
# Destroy an existing guest instance.
destroyGuest = (id) ->
2014-10-23 15:08:48 +00:00
webViewManager.removeGuest id
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)
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_DESTROY_GUEST', (event, guestInstanceId) ->
destroyGuest guestInstanceId
ipc.on 'ATOM_SHELL_GUEST_VIEW_MANAGER_SET_AUTO_SIZE', (event, guestInstanceId, params) ->
guestInstances[id]?.setAutoSize params.enableAutoSize, params.min, params.max