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'); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 GuestViewContainer.prototype.createBrowserPluginElement = function() { | 85 GuestViewContainer.prototype.createBrowserPluginElement = function() { |
86 // We create BrowserPlugin as a custom element in order to observe changes | 86 // We create BrowserPlugin as a custom element in order to observe changes |
87 // to attributes synchronously. | 87 // to attributes synchronously. |
88 var browserPluginElement = | 88 var browserPluginElement = |
89 new GuestViewContainer[this.viewType + 'BrowserPlugin'](); | 89 new GuestViewContainer[this.viewType + 'BrowserPlugin'](); |
90 privates(browserPluginElement).internal = this; | 90 privates(browserPluginElement).internal = this; |
91 return browserPluginElement; | 91 return browserPluginElement; |
92 }; | 92 }; |
93 | 93 |
| 94 GuestViewContainer.prototype.getBrowserPluginElement = function() { |
| 95 return privates(this).browserPluginElement; |
| 96 }; |
| 97 |
94 GuestViewContainer.prototype.setupFocusPropagation = function() { | 98 GuestViewContainer.prototype.setupFocusPropagation = function() { |
95 if (!this.element.hasAttribute('tabIndex')) { | 99 if (!this.element.hasAttribute('tabIndex')) { |
96 // GuestViewContainer needs a tabIndex in order to be focusable. | 100 // GuestViewContainer needs a tabIndex in order to be focusable. |
97 // TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute | 101 // TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute |
98 // to allow GuestViewContainer to be focusable. | 102 // to allow GuestViewContainer to be focusable. |
99 // See http://crbug.com/231664. | 103 // See http://crbug.com/231664. |
100 this.element.setAttribute('tabIndex', -1); | 104 this.element.setAttribute('tabIndex', -1); |
101 } | 105 } |
102 this.element.addEventListener('focus', function(e) { | 106 this.element.addEventListener('focus', function(e) { |
103 // Focus the BrowserPlugin when the GuestViewContainer takes focus. | 107 // Focus the BrowserPlugin when the GuestViewContainer takes focus. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 181 |
178 // Implemented by the specific view type, if needed. | 182 // Implemented by the specific view type, if needed. |
179 GuestViewContainer.prototype.buildContainerParams = function() { return {}; }; | 183 GuestViewContainer.prototype.buildContainerParams = function() { return {}; }; |
180 GuestViewContainer.prototype.onElementAttached = function() {}; | 184 GuestViewContainer.prototype.onElementAttached = function() {}; |
181 GuestViewContainer.prototype.onElementDetached = function() {}; | 185 GuestViewContainer.prototype.onElementDetached = function() {}; |
182 GuestViewContainer.prototype.setupAttributes = function() {}; | 186 GuestViewContainer.prototype.setupAttributes = function() {}; |
183 | 187 |
184 // Registers the browser plugin <object> custom element. |viewType| is the | 188 // Registers the browser plugin <object> custom element. |viewType| is the |
185 // name of the specific guestview container (e.g. 'webview'). | 189 // name of the specific guestview container (e.g. 'webview'). |
186 function registerBrowserPluginElement(viewType) { | 190 function registerBrowserPluginElement(viewType) { |
187 var proto = Object.create(HTMLObjectElement.prototype); | 191 //var proto = Object.create(HTMLObjectElement.prototype); |
| 192 var proto = Object.create(HTMLIFrameElement.prototype); |
| 193 |
| 194 var isSitePerProcess = GuestViewInternalNatives.IsSitePerProcess(); |
| 195 window.console.log('isSitePerProcess: ' + isSitePerProcess); |
188 | 196 |
189 proto.createdCallback = function() { | 197 proto.createdCallback = function() { |
190 this.setAttribute('type', 'application/browser-plugin'); | 198 if (!isSitePerProcess) { |
191 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); | 199 this.setAttribute('type', 'application/browser-plugin'); |
| 200 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); |
| 201 } |
192 this.style.width = '100%'; | 202 this.style.width = '100%'; |
193 this.style.height = '100%'; | 203 this.style.height = '100%'; |
194 }; | 204 }; |
195 | 205 |
196 proto.attachedCallback = function() { | 206 proto.attachedCallback = function() { |
197 // Load the plugin immediately. | 207 // Load the plugin immediately. |
198 var unused = this.nonExistentAttribute; | 208 var unused = this.nonExistentAttribute; |
199 }; | 209 }; |
200 | 210 |
201 proto.attributeChangedCallback = function(name, oldValue, newValue) { | 211 if (!isSitePerProcess) { |
202 var internal = privates(this).internal; | 212 proto.attributeChangedCallback = function(name, oldValue, newValue) { |
203 if (!internal) { | 213 var internal = privates(this).internal; |
204 return; | 214 if (!internal) { |
205 } | 215 return; |
206 internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue); | 216 } |
207 }; | 217 internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue); |
| 218 }; |
| 219 } |
208 | 220 |
| 221 var options = {prototype: proto}; |
| 222 options.extends = isSitePerProcess ? 'iframe' : 'object'; |
209 GuestViewContainer[viewType + 'BrowserPlugin'] = | 223 GuestViewContainer[viewType + 'BrowserPlugin'] = |
210 DocumentNatives.RegisterElement(viewType + 'browserplugin', | 224 DocumentNatives.RegisterElement(viewType + 'browserplugin', options); |
211 {extends: 'object', prototype: proto}); | |
212 | 225 |
213 delete proto.createdCallback; | 226 delete proto.createdCallback; |
214 delete proto.attachedCallback; | 227 delete proto.attachedCallback; |
215 delete proto.detachedCallback; | 228 delete proto.detachedCallback; |
216 delete proto.attributeChangedCallback; | 229 delete proto.attributeChangedCallback; |
217 }; | 230 }; |
218 | 231 |
219 // Registers the guestview container as a custom element. | 232 // Registers the guestview container as a custom element. |
220 // |guestViewContainerType| is the type of guestview container | 233 // |guestViewContainerType| is the type of guestview container |
221 // (e.g.WebViewImpl). | 234 // (e.g.WebViewImpl). |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // Delete the callbacks so developers cannot call them and produce unexpected | 283 // Delete the callbacks so developers cannot call them and produce unexpected |
271 // behavior. | 284 // behavior. |
272 delete proto.createdCallback; | 285 delete proto.createdCallback; |
273 delete proto.attachedCallback; | 286 delete proto.attachedCallback; |
274 delete proto.detachedCallback; | 287 delete proto.detachedCallback; |
275 delete proto.attributeChangedCallback; | 288 delete proto.attributeChangedCallback; |
276 } | 289 } |
277 | 290 |
278 // Exports. | 291 // Exports. |
279 exports.GuestViewContainer = GuestViewContainer; | 292 exports.GuestViewContainer = GuestViewContainer; |
OLD | NEW |