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 var DocumentNatives = requireNative('document_natives'); | 5 var DocumentNatives = requireNative('document_natives'); |
6 var GuestViewInternal = | 6 var GuestViewInternal = |
7 require('binding').Binding.create('guestViewInternal').generate(); | 7 require('binding').Binding.create('guestViewInternal').generate(); |
8 var IdGenerator = requireNative('id_generator'); | 8 var IdGenerator = requireNative('id_generator'); |
9 var guestViewInternalNatives = requireNative('guest_view_internal'); | 9 var guestViewInternalNatives = requireNative('guest_view_internal'); |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 this.attachWindow(guestInstanceId); | 63 this.attachWindow(guestInstanceId); |
64 if (callback) { | 64 if (callback) { |
65 callback(true); | 65 callback(true); |
66 } | 66 } |
67 }.bind(this) | 67 }.bind(this) |
68 ); | 68 ); |
69 }; | 69 }; |
70 | 70 |
71 AppViewInternal.prototype.attachWindow = function(guestInstanceId) { | 71 AppViewInternal.prototype.attachWindow = function(guestInstanceId) { |
72 this.guestInstanceId = guestInstanceId; | 72 this.guestInstanceId = guestInstanceId; |
| 73 if (!this.internalInstanceId) { |
| 74 return; |
| 75 } |
73 var params = { | 76 var params = { |
74 'instanceId': this.viewInstanceId, | 77 'instanceId': this.viewInstanceId |
75 }; | 78 }; |
76 this.browserPluginNode.style.visibility = 'visible'; | 79 this.browserPluginNode.style.visibility = 'visible'; |
77 return guestViewInternalNatives.AttachGuest( | 80 return guestViewInternalNatives.AttachGuest( |
78 parseInt(this.browserPluginNode.getAttribute('internalinstanceid')), | 81 this.internalInstanceId, |
79 guestInstanceId, | 82 guestInstanceId, |
80 params); | 83 params); |
81 }; | 84 }; |
82 | 85 |
| 86 AppViewInternal.prototype.handleBrowserPluginAttributeMutation = |
| 87 function(name, oldValue, newValue) { |
| 88 if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
| 89 this.browserPluginNode.removeAttribute('internalinstanceid'); |
| 90 this.internalInstanceId = parseInt(newValue); |
| 91 |
| 92 if (!!this.guestInstanceId && this.guestInstanceId != 0) { |
| 93 var params = { |
| 94 'instanceId': this.viewInstanceId |
| 95 }; |
| 96 guestViewInternalNatives.AttachGuest( |
| 97 this.internalInstanceId, |
| 98 this.guestInstanceId, |
| 99 params); |
| 100 } |
| 101 return; |
| 102 } |
| 103 }; |
| 104 |
| 105 AppViewInternal.prototype.reset = function() { |
| 106 if (this.guestInstanceId) { |
| 107 GuestViewInternal.destroyGuest(this.guestInstanceId); |
| 108 this.guestInstanceId = undefined; |
| 109 } |
| 110 }; |
| 111 |
83 function registerBrowserPluginElement() { | 112 function registerBrowserPluginElement() { |
84 var proto = Object.create(HTMLObjectElement.prototype); | 113 var proto = Object.create(HTMLObjectElement.prototype); |
85 | 114 |
86 proto.createdCallback = function() { | 115 proto.createdCallback = function() { |
87 this.setAttribute('type', 'application/browser-plugin'); | 116 this.setAttribute('type', 'application/browser-plugin'); |
88 this.style.width = '100%'; | 117 this.style.width = '100%'; |
89 this.style.height = '100%'; | 118 this.style.height = '100%'; |
90 }; | 119 }; |
91 | 120 |
92 proto.attachedCallback = function() { | 121 proto.attachedCallback = function() { |
93 // Load the plugin immediately. | 122 // Load the plugin immediately. |
94 var unused = this.nonExistentAttribute; | 123 var unused = this.nonExistentAttribute; |
95 }; | 124 }; |
96 | 125 |
| 126 proto.attributeChangedCallback = function(name, oldValue, newValue) { |
| 127 var internal = privates(this).internal; |
| 128 if (!internal) { |
| 129 return; |
| 130 } |
| 131 internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue); |
| 132 }; |
| 133 |
97 AppViewInternal.BrowserPlugin = | 134 AppViewInternal.BrowserPlugin = |
98 DocumentNatives.RegisterElement('appplugin', {extends: 'object', | 135 DocumentNatives.RegisterElement('appplugin', {extends: 'object', |
99 prototype: proto}); | 136 prototype: proto}); |
100 | 137 |
101 delete proto.createdCallback; | 138 delete proto.createdCallback; |
102 delete proto.attachedCallback; | 139 delete proto.attachedCallback; |
103 delete proto.detachedCallback; | 140 delete proto.detachedCallback; |
104 delete proto.attributeChangedCallback; | 141 delete proto.attributeChangedCallback; |
105 } | 142 } |
106 | 143 |
107 function registerAppViewElement() { | 144 function registerAppViewElement() { |
108 var proto = Object.create(HTMLElement.prototype); | 145 var proto = Object.create(HTMLElement.prototype); |
109 | 146 |
110 proto.createdCallback = function() { | 147 proto.createdCallback = function() { |
111 new AppViewInternal(this); | 148 new AppViewInternal(this); |
112 }; | 149 }; |
113 | 150 |
| 151 proto.detachedCallback = function() { |
| 152 var internal = privates(this).internal; |
| 153 if (!internal) { |
| 154 return; |
| 155 } |
| 156 internal.reset(); |
| 157 }; |
| 158 |
114 proto.connect = function() { | 159 proto.connect = function() { |
115 var internal = privates(this).internal; | 160 var internal = privates(this).internal; |
116 $Function.apply(internal.connect, internal, arguments); | 161 $Function.apply(internal.connect, internal, arguments); |
117 } | 162 } |
| 163 |
118 window.AppView = | 164 window.AppView = |
119 DocumentNatives.RegisterElement('appview', {prototype: proto}); | 165 DocumentNatives.RegisterElement('appview', {prototype: proto}); |
120 | 166 |
121 // Delete the callbacks so developers cannot call them and produce unexpected | 167 // Delete the callbacks so developers cannot call them and produce unexpected |
122 // behavior. | 168 // behavior. |
123 delete proto.createdCallback; | 169 delete proto.createdCallback; |
124 delete proto.attachedCallback; | 170 delete proto.attachedCallback; |
125 delete proto.detachedCallback; | 171 delete proto.detachedCallback; |
126 delete proto.attributeChangedCallback; | 172 delete proto.attributeChangedCallback; |
127 } | 173 } |
128 | 174 |
129 var useCapture = true; | 175 var useCapture = true; |
130 window.addEventListener('readystatechange', function listener(event) { | 176 window.addEventListener('readystatechange', function listener(event) { |
131 if (document.readyState == 'loading') | 177 if (document.readyState == 'loading') |
132 return; | 178 return; |
133 | 179 |
134 registerBrowserPluginElement(); | 180 registerBrowserPluginElement(); |
135 registerAppViewElement(); | 181 registerAppViewElement(); |
136 window.removeEventListener(event.type, listener, useCapture); | 182 window.removeEventListener(event.type, listener, useCapture); |
137 }, useCapture); | 183 }, useCapture); |
OLD | NEW |