Index: chrome/renderer/resources/extensions/app_view.js |
diff --git a/chrome/renderer/resources/extensions/app_view.js b/chrome/renderer/resources/extensions/app_view.js |
index 968340b1f46a79271c6d924ffbe0680394507d3a..2cadb5933d62bbfe1bdfc2f6c4e30039d8c9681c 100644 |
--- a/chrome/renderer/resources/extensions/app_view.js |
+++ b/chrome/renderer/resources/extensions/app_view.js |
@@ -70,16 +70,45 @@ AppViewInternal.prototype.connect = function(app, data, callback) { |
AppViewInternal.prototype.attachWindow = function(guestInstanceId) { |
this.guestInstanceId = guestInstanceId; |
+ if (!this.internalInstanceId) { |
+ return; |
+ } |
var params = { |
- 'instanceId': this.viewInstanceId, |
+ 'instanceId': this.viewInstanceId |
}; |
this.browserPluginNode.style.visibility = 'visible'; |
return guestViewInternalNatives.AttachGuest( |
- parseInt(this.browserPluginNode.getAttribute('internalinstanceid')), |
+ this.internalInstanceId, |
guestInstanceId, |
params); |
}; |
+AppViewInternal.prototype.handleBrowserPluginAttributeMutation = |
+ function(name, oldValue, newValue) { |
+ if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
+ this.browserPluginNode.removeAttribute('internalinstanceid'); |
+ this.internalInstanceId = parseInt(newValue); |
+ |
+ if (!!this.guestInstanceId && this.guestInstanceId != 0) { |
+ var params = { |
+ 'instanceId': this.viewInstanceId |
+ }; |
+ guestViewInternalNatives.AttachGuest( |
+ this.internalInstanceId, |
+ this.guestInstanceId, |
+ params); |
+ } |
+ return; |
+ } |
+}; |
+ |
+AppViewInternal.prototype.reset = function() { |
+ if (this.guestInstanceId) { |
+ GuestViewInternal.destroyGuest(this.guestInstanceId); |
+ this.guestInstanceId = undefined; |
+ } |
+}; |
+ |
function registerBrowserPluginElement() { |
var proto = Object.create(HTMLObjectElement.prototype); |
@@ -94,6 +123,14 @@ function registerBrowserPluginElement() { |
var unused = this.nonExistentAttribute; |
}; |
+ proto.attributeChangedCallback = function(name, oldValue, newValue) { |
+ var internal = privates(this).internal; |
+ if (!internal) { |
+ return; |
+ } |
+ internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue); |
+ }; |
+ |
AppViewInternal.BrowserPlugin = |
DocumentNatives.RegisterElement('appplugin', {extends: 'object', |
prototype: proto}); |
@@ -111,10 +148,19 @@ function registerAppViewElement() { |
new AppViewInternal(this); |
}; |
+ proto.detachedCallback = function() { |
+ var internal = privates(this).internal; |
+ if (!internal) { |
+ return; |
+ } |
+ internal.reset(); |
+ }; |
+ |
proto.connect = function() { |
var internal = privates(this).internal; |
$Function.apply(internal.connect, internal, arguments); |
} |
+ |
window.AppView = |
DocumentNatives.RegisterElement('appview', {prototype: proto}); |