OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This module implements the shared functionality for different guestview | 5 // This module implements the shared functionality for different guestview |
6 // containers, such as web_view, app_view, etc. | 6 // containers, such as web_view, app_view, etc. |
7 | 7 |
8 var DocumentNatives = requireNative('document_natives'); | 8 var DocumentNatives = requireNative('document_natives'); |
9 var GuestView = require('guestView').GuestView; | 9 var GuestView = require('guestView').GuestView; |
10 var GuestViewInternalNatives = requireNative('guest_view_internal'); | 10 var GuestViewInternalNatives = requireNative('guest_view_internal'); |
11 var IdGenerator = requireNative('id_generator'); | 11 var IdGenerator = requireNative('id_generator'); |
| 12 var MessagingNatives = requireNative('messaging_natives'); |
12 | 13 |
13 function GuestViewContainer(element, viewType) { | 14 function GuestViewContainer(element, viewType) { |
14 privates(element).internal = this; | 15 privates(element).internal = this; |
15 this.attributes = {}; | 16 this.attributes = {}; |
16 this.element = element; | 17 this.element = element; |
17 this.elementAttached = false; | 18 this.elementAttached = false; |
18 this.viewInstanceId = IdGenerator.GetNextId(); | 19 this.viewInstanceId = IdGenerator.GetNextId(); |
19 this.viewType = viewType; | 20 this.viewType = viewType; |
20 | 21 |
21 this.setupGuestProperty(); | 22 this.setupGuestProperty(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 if (!this.internalInstanceId) { | 116 if (!this.internalInstanceId) { |
116 return true; | 117 return true; |
117 } | 118 } |
118 | 119 |
119 this.guest.attach(this.internalInstanceId, | 120 this.guest.attach(this.internalInstanceId, |
120 this.viewInstanceId, | 121 this.viewInstanceId, |
121 this.buildParams()); | 122 this.buildParams()); |
122 return true; | 123 return true; |
123 }; | 124 }; |
124 | 125 |
| 126 GuestViewContainer.prototype.makeGCOwnContainer = function(internalInstanceId) { |
| 127 MessagingNatives.BindToGC(this, function() { |
| 128 GuestViewInternalNatives.DestroyContainer(internalInstanceId); |
| 129 }, -1); |
| 130 }; |
| 131 |
125 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = | 132 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = |
126 function(name, oldValue, newValue) { | 133 function(name, oldValue, newValue) { |
127 if (name == 'internalinstanceid' && !oldValue && !!newValue) { | 134 if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
128 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); | 135 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); |
129 this.internalInstanceId = parseInt(newValue); | 136 this.internalInstanceId = parseInt(newValue); |
130 | 137 |
| 138 this.makeGCOwnContainer(this.internalInstanceId); |
| 139 |
131 // Track when the element resizes using the element resize callback. | 140 // Track when the element resizes using the element resize callback. |
132 GuestViewInternalNatives.RegisterElementResizeCallback( | 141 GuestViewInternalNatives.RegisterElementResizeCallback( |
133 this.internalInstanceId, this.weakWrapper(this.onElementResize)); | 142 this.internalInstanceId, this.weakWrapper(this.onElementResize)); |
134 | 143 |
135 if (!this.guest.getId()) { | 144 if (!this.guest.getId()) { |
136 return; | 145 return; |
137 } | 146 } |
138 this.guest.attach(this.internalInstanceId, | 147 this.guest.attach(this.internalInstanceId, |
139 this.viewInstanceId, | 148 this.viewInstanceId, |
140 this.buildParams()); | 149 this.buildParams()); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // Delete the callbacks so developers cannot call them and produce unexpected | 283 // Delete the callbacks so developers cannot call them and produce unexpected |
275 // behavior. | 284 // behavior. |
276 delete proto.createdCallback; | 285 delete proto.createdCallback; |
277 delete proto.attachedCallback; | 286 delete proto.attachedCallback; |
278 delete proto.detachedCallback; | 287 delete proto.detachedCallback; |
279 delete proto.attributeChangedCallback; | 288 delete proto.attributeChangedCallback; |
280 } | 289 } |
281 | 290 |
282 // Exports. | 291 // Exports. |
283 exports.GuestViewContainer = GuestViewContainer; | 292 exports.GuestViewContainer = GuestViewContainer; |
OLD | NEW |