Clean up WebView's ipc listeners when detached, fix #1185

This commit is contained in:
Cheng Zhao 2015-03-23 23:07:53 +08:00
parent 5bd3cfc4f6
commit d46c64f64b
2 changed files with 7 additions and 2 deletions

View file

@ -40,6 +40,11 @@ module.exports =
domEvent[f] = args[i]
webView.onSizeChanged domEvent
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}"
createGuest: (type, params, callback) ->
requestId++
ipc.send 'ATOM_SHELL_GUEST_VIEW_MANAGER_CREATE_GUEST', type, params, requestId

View file

@ -28,8 +28,6 @@ class WebViewImpl
@viewInstanceId = getNextId()
guestViewInternal.registerEvents this, @viewInstanceId
shadowRoot.appendChild @browserPluginNode
createBrowserPluginNode: ->
@ -222,6 +220,7 @@ registerWebViewElement = ->
proto.detachedCallback = ->
internal = v8Util.getHiddenValue this, 'internal'
return unless internal
guestViewInternal.deregisterEvents internal.viewInstanceId
internal.elementAttached = false
internal.reset()
@ -229,6 +228,7 @@ registerWebViewElement = ->
internal = v8Util.getHiddenValue this, 'internal'
return unless internal
unless internal.elementAttached
guestViewInternal.registerEvents internal, internal.viewInstanceId
internal.elementAttached = true
internal.attributes[webViewConstants.ATTRIBUTE_SRC].parse()