diff options
-rw-r--r-- | extensions/renderer/resources/guest_view/guest_view.js | 20 | ||||
-rw-r--r-- | extensions/renderer/resources/guest_view/guest_view_container.js | 2 |
2 files changed, 18 insertions, 4 deletions
diff --git a/extensions/renderer/resources/guest_view/guest_view.js b/extensions/renderer/resources/guest_view/guest_view.js index 27368a4..a09f7c6 100644 --- a/extensions/renderer/resources/guest_view/guest_view.js +++ b/extensions/renderer/resources/guest_view/guest_view.js @@ -130,6 +130,20 @@ GuestViewImpl.prototype.checkState = function(action) { return true; }; +// Returns a wrapper function for |func| with a weak reference to |this|. This +// implementation of weakWrapper() requires a provided |viewInstanceId| since +// GuestViewImpl does not store this ID. +GuestViewImpl.prototype.weakWrapper = function(func, viewInstanceId) { + return function() { + var view = GuestViewInternalNatives.GetViewFromID(viewInstanceId); + if (view && view.guest) { + return $Function.apply(func, + privates(view.guest).internal, + $Array.slice(arguments)); + } + }; +}; + // Internal implementation of attach(). GuestViewImpl.prototype.attachImpl = function( internalInstanceId, viewInstanceId, attachParams, callback) { @@ -165,8 +179,8 @@ GuestViewImpl.prototype.attachImpl = function( this.state = GUEST_STATE_ATTACHED; // Detach automatically when the container is destroyed. - GuestViewInternalNatives.RegisterDestructionCallback(internalInstanceId, - function() { + GuestViewInternalNatives.RegisterDestructionCallback( + internalInstanceId, this.weakWrapper(function() { if (this.state != GUEST_STATE_ATTACHED || this.internalInstanceId != internalInstanceId) { return; @@ -174,7 +188,7 @@ GuestViewImpl.prototype.attachImpl = function( this.internalInstanceId = 0; this.state = GUEST_STATE_CREATED; - }.bind(this)); + }, viewInstanceId)); }; // Internal implementation of create(). diff --git a/extensions/renderer/resources/guest_view/guest_view_container.js b/extensions/renderer/resources/guest_view/guest_view_container.js index 9b052c6..ebcc313 100644 --- a/extensions/renderer/resources/guest_view/guest_view_container.js +++ b/extensions/renderer/resources/guest_view/guest_view_container.js @@ -130,7 +130,7 @@ GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = // Track when the element resizes using the element resize callback. GuestViewInternalNatives.RegisterElementResizeCallback( - this.internalInstanceId, this.onElementResize.bind(this)); + this.internalInstanceId, this.weakWrapper(this.onElementResize)); if (!this.guest.getId()) { return; |