Unlisten the zoom-level-changed event when webview is detached
authorCheng Zhao <zcbenz@gmail.com>
Wed, 13 Jan 2016 06:58:16 +0000 (14:58 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 13 Jan 2016 06:58:16 +0000 (14:58 +0800)
atom/renderer/lib/web-view/web-view.js

index 458e79a..cb0a5dd 100644 (file)
@@ -43,9 +43,10 @@ WebViewImpl = (function() {
     shadowRoot.appendChild(this.browserPluginNode);
 
     // Subscribe to host's zoom level changes.
-    webFrame.on('zoom-level-changed', (zoomLevel) => {
+    this.onZoomLevelChanged = (zoomLevel) => {
       this.webviewNode.setZoomLevel(zoomLevel);
-    });
+    }
+    webFrame.on('zoom-level-changed', this.onZoomLevelChanged);
   }
 
   WebViewImpl.prototype.createBrowserPluginNode = function() {
@@ -64,6 +65,8 @@ WebViewImpl = (function() {
   /* Resets some state upon reattaching <webview> element to the DOM. */
 
   WebViewImpl.prototype.reset = function() {
+    // Unlisten the zoom-level-changed event.
+    webFrame.removeListener('zoom-level-changed', this.onZoomLevelChanged);
 
     /*
       If guestInstanceId is defined then the <webview> has navigated and has