Dispatch WebContents events to <webview>
This commit is contained in:
parent
d63f44cd07
commit
218d69d288
3 changed files with 40 additions and 4 deletions
|
@ -2,6 +2,17 @@ ipc = require 'ipc'
|
|||
webContents = require 'web-contents'
|
||||
webViewManager = null # Doesn't exist in early initialization.
|
||||
|
||||
supportedWebViewEvents = [
|
||||
'did-finish-load'
|
||||
'did-fail-load'
|
||||
'did-frame-finish-load'
|
||||
'did-start-loading'
|
||||
'did-stop-loading'
|
||||
'did-get-redirect-request'
|
||||
'crashed'
|
||||
'destroyed'
|
||||
]
|
||||
|
||||
nextInstanceId = 0
|
||||
guestInstances = {}
|
||||
|
||||
|
@ -27,6 +38,7 @@ createGuest = (embedder, params) ->
|
|||
|
||||
# Init guest web view after attached.
|
||||
guest.once 'did-attach', (event, params) ->
|
||||
@viewInstanceId = params.instanceId
|
||||
min = width: params.minwidth, height: params.minheight
|
||||
max = width: params.maxwidth, height: params.maxheight
|
||||
@setAutoSize params.autosize, min, max
|
||||
|
@ -35,6 +47,12 @@ createGuest = (embedder, params) ->
|
|||
if params.allowtransparency?
|
||||
@setAllowTransparency params.allowtransparency
|
||||
|
||||
# Dispatch events to embedder.
|
||||
for event in supportedWebViewEvents
|
||||
do (event) ->
|
||||
guest.on event, (_, args...) ->
|
||||
embedder.send "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{guest.viewInstanceId}", event, args...
|
||||
|
||||
id
|
||||
|
||||
# Destroy an existing guest instance.
|
||||
|
|
|
@ -2,7 +2,28 @@ ipc = require 'ipc'
|
|||
|
||||
requestId = 0
|
||||
|
||||
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
|
||||
|
||||
module.exports =
|
||||
registerEvents: (webView, viewInstanceId) ->
|
||||
ipc.on "ATOM_SHELL_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-#{viewInstanceId}", (event, args...) ->
|
||||
dispatchEvent webView, event, args...
|
||||
|
||||
createGuest: (type, params, callback) ->
|
||||
requestId++
|
||||
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', type, params, requestId
|
||||
|
|
|
@ -98,6 +98,7 @@ class WebView
|
|||
@setupWebviewNodeProperties()
|
||||
|
||||
@viewInstanceId = getNextId()
|
||||
guestViewInternal.registerEvents this, @viewInstanceId
|
||||
|
||||
shadowRoot.appendChild @browserPluginNode
|
||||
|
||||
|
@ -515,10 +516,6 @@ registerWebViewElement = ->
|
|||
"executeJavaScript"
|
||||
"insertCSS"
|
||||
"send"
|
||||
# "getZoom"
|
||||
# "print"
|
||||
# "setZoom"
|
||||
# "terminate"
|
||||
]
|
||||
|
||||
# Forward proto.foo* method calls to WebView.foo*.
|
||||
|
|
Loading…
Reference in a new issue