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 IdGenerator = requireNative('id_generator'); | 11 var IdGenerator = requireNative('id_generator'); |
11 | 12 |
12 function GuestViewContainer(element, viewType) { | 13 function GuestViewContainer(element, viewType) { |
13 privates(element).internal = this; | 14 privates(element).internal = this; |
14 this.element = element; | 15 this.element = element; |
15 this.elementAttached = false; | 16 this.elementAttached = false; |
16 this.guest = new GuestView(viewType); | 17 this.guest = new GuestView(viewType); |
17 this.viewInstanceId = IdGenerator.GetNextId(); | 18 this.viewInstanceId = IdGenerator.GetNextId(); |
18 this.viewType = viewType; | 19 this.viewType = viewType; |
19 | 20 |
20 privates(this).browserPluginElement = this.createBrowserPluginElement(); | 21 privates(this).browserPluginElement = this.createBrowserPluginElement(); |
21 this.setupFocusPropagation(); | 22 this.setupFocusPropagation(); |
22 | 23 |
23 var shadowRoot = this.element.createShadowRoot(); | 24 var shadowRoot = this.element.createShadowRoot(); |
24 shadowRoot.appendChild(privates(this).browserPluginElement); | 25 shadowRoot.appendChild(privates(this).browserPluginElement); |
26 | |
27 // Track when the element resizes using the element resize callback. | |
28 if (this.internalInstanceId) { | |
29 GuestViewInternalNatives.RegisterElementResizeCallback( | |
Fady Samuel
2015/01/19 23:57:01
nit: spacing.
Fady Samuel
2015/01/20 00:04:25
This needs to be called every time we get a new in
paulmeyer
2015/01/20 00:24:38
Done.
paulmeyer
2015/01/20 00:24:38
Done.
| |
30 this.internalInstanceId, this.onElementResize.bind(this)); | |
31 } | |
25 } | 32 } |
26 | 33 |
27 // Forward public API methods from |proto| to their internal implementations. | 34 // Forward public API methods from |proto| to their internal implementations. |
28 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) { | 35 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) { |
29 var createProtoHandler = function(m) { | 36 var createProtoHandler = function(m) { |
30 return function(var_args) { | 37 return function(var_args) { |
31 var internal = privates(this).internal; | 38 var internal = privates(this).internal; |
32 return $Function.apply(internal[m], internal, arguments); | 39 return $Function.apply(internal[m], internal, arguments); |
33 }; | 40 }; |
34 }; | 41 }; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 this.buildAttachParams()); | 113 this.buildAttachParams()); |
107 } | 114 } |
108 }; | 115 }; |
109 | 116 |
110 // Implemented by the specific view type, if needed. | 117 // Implemented by the specific view type, if needed. |
111 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; | 118 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; |
112 GuestViewContainer.prototype.handleAttributeMutation = function() {}; | 119 GuestViewContainer.prototype.handleAttributeMutation = function() {}; |
113 GuestViewContainer.prototype.onElementAttached = function() {}; | 120 GuestViewContainer.prototype.onElementAttached = function() {}; |
114 GuestViewContainer.prototype.onElementDetached = function() { | 121 GuestViewContainer.prototype.onElementDetached = function() { |
115 this.guest.destroy(); | 122 this.guest.destroy(); |
116 }; | 123 }; |
Fady Samuel
2015/01/19 23:57:01
nit: Add a blank line after this.
paulmeyer
2015/01/20 00:24:38
onElementResize() is still a function that will be
| |
124 GuestViewContainer.prototype.onElementResize = function(oldWidth, oldHeight, | |
125 newWidth, newHeight) { | |
126 // TODO(paulmeyer): If any code is entered here, and this function is called | |
127 // while the dev-tool inspect window is open, chrome will crash. | |
128 }; | |
117 | 129 |
118 // Registers the browser plugin <object> custom element. |viewType| is the | 130 // Registers the browser plugin <object> custom element. |viewType| is the |
119 // name of the specific guestview container (e.g. 'webview'). | 131 // name of the specific guestview container (e.g. 'webview'). |
120 function registerBrowserPluginElement(viewType) { | 132 function registerBrowserPluginElement(viewType) { |
121 var proto = Object.create(HTMLObjectElement.prototype); | 133 var proto = Object.create(HTMLObjectElement.prototype); |
122 | 134 |
123 proto.createdCallback = function() { | 135 proto.createdCallback = function() { |
124 this.setAttribute('type', 'application/browser-plugin'); | 136 this.setAttribute('type', 'application/browser-plugin'); |
125 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); | 137 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); |
126 this.style.width = '100%'; | 138 this.style.width = '100%'; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 // Delete the callbacks so developers cannot call them and produce unexpected | 212 // Delete the callbacks so developers cannot call them and produce unexpected |
201 // behavior. | 213 // behavior. |
202 delete proto.createdCallback; | 214 delete proto.createdCallback; |
203 delete proto.attachedCallback; | 215 delete proto.attachedCallback; |
204 delete proto.detachedCallback; | 216 delete proto.detachedCallback; |
205 delete proto.attributeChangedCallback; | 217 delete proto.attributeChangedCallback; |
206 } | 218 } |
207 | 219 |
208 // Exports. | 220 // Exports. |
209 exports.GuestViewContainer = GuestViewContainer; | 221 exports.GuestViewContainer = GuestViewContainer; |
OLD | NEW |