From d46c64f64b0168cf74e5fb9f1140ca5869a5e75c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Mar 2015 23:07:53 +0800 Subject: [PATCH] Clean up WebView's ipc listeners when detached, fix #1185 --- atom/renderer/lib/web-view/guest-view-internal.coffee | 5 +++++ atom/renderer/lib/web-view/web-view.coffee | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/atom/renderer/lib/web-view/guest-view-internal.coffee b/atom/renderer/lib/web-view/guest-view-internal.coffee index 860d53ed6788..99401784f599 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.coffee +++ b/atom/renderer/lib/web-view/guest-view-internal.coffee @@ -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 diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index 996ab176056a..3058863f7b52 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -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()