Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
When a guest detaches from an embedder (e.g. a window's WebContents),…
Browse files Browse the repository at this point in the history
… stop forwarding events to the embedder

Fix #515
  • Loading branch information
petemill committed Mar 1, 2018
1 parent 32ebe0b commit b05c1f8
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/browser/guest-view-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ let supportedWebViewEvents = [
]

let guests = {}
// ensure webcontent events (from guest) are fired to embedder (window) so they can be forwarded to webview / interested-party
const registerGuest = function (guest, embedder) {
const tabId = guest.getId()

Expand All @@ -61,8 +62,9 @@ const registerGuest = function (guest, embedder) {
}

// Dispatch events to embedder.
const fn = function (event) {
guest.on(event, function (_, ...args) {
const guestHandlersThisEmbedder = { }
for (const event of supportedWebViewEvents) {
guestHandlersThisEmbedder[event] = function (_, ...args) {
const embedder = guests[tabId]

if (!embedder || embedder.isDestroyed())
Expand All @@ -73,16 +75,21 @@ const registerGuest = function (guest, embedder) {
delete guests[tabId]
forceSend = true
}
if (event === 'did-detach') {

This comment has been minimized.

Copy link
@petemill

petemill Mar 1, 2018

Author Member

This won't work since we attach / detach every time the guest is attached to a webview, even though we still want the window to get events. We need an event whenever the contents gets its first windowId, and whenever that changes.

for (const event in guestHandlersThisEmbedder) {
guest.removeListener(event, guestHandlersThisEmbedder[event])
}
}

if (guest.isDestroyed() && !forceSend)
return

embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT', tabId, event].concat(args))
})
}
for (const event of supportedWebViewEvents) {
fn(event)
}
guest.on(event, guestHandlersThisEmbedder[event])
}



// Dispatch guest's IPC messages to embedder.
guest.on('ipc-message-host', function (_, [channel, ...args]) {
Expand Down

1 comment on commit b05c1f8

@petemill
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this commit, it's been replaced

Please sign in to comment.