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

View file

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