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 | 12 |
13 function GuestViewContainer(element, viewType) { | 13 function GuestViewContainer(element, viewType) { |
14 privates(element).internal = this; | 14 privates(element).internal = this; |
| 15 this.attributes = {}; |
15 this.element = element; | 16 this.element = element; |
16 this.elementAttached = false; | 17 this.elementAttached = false; |
17 this.viewInstanceId = IdGenerator.GetNextId(); | 18 this.viewInstanceId = IdGenerator.GetNextId(); |
18 this.viewType = viewType; | 19 this.viewType = viewType; |
19 | 20 |
20 this.setupGuestProperty(); | 21 this.setupGuestProperty(); |
21 this.guest = new GuestView(viewType); | 22 this.guest = new GuestView(viewType); |
| 23 this.setupAttributes(); |
22 | 24 |
23 privates(this).browserPluginElement = this.createBrowserPluginElement(); | 25 privates(this).browserPluginElement = this.createBrowserPluginElement(); |
24 this.setupFocusPropagation(); | 26 this.setupFocusPropagation(); |
25 | |
26 var shadowRoot = this.element.createShadowRoot(); | 27 var shadowRoot = this.element.createShadowRoot(); |
27 shadowRoot.appendChild(privates(this).browserPluginElement); | 28 shadowRoot.appendChild(privates(this).browserPluginElement); |
28 } | 29 } |
29 | 30 |
30 // Forward public API methods from |proto| to their internal implementations. | 31 // Forward public API methods from |proto| to their internal implementations. |
31 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) { | 32 GuestViewContainer.forwardApiMethods = function(proto, apiMethods) { |
32 var createProtoHandler = function(m) { | 33 var createProtoHandler = function(m) { |
33 return function(var_args) { | 34 return function(var_args) { |
34 var internal = privates(this).internal; | 35 var internal = privates(this).internal; |
35 return $Function.apply(internal[m], internal, arguments); | 36 return $Function.apply(internal[m], internal, arguments); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 params['elementHeight'] = parseInt(elementRect.height); | 162 params['elementHeight'] = parseInt(elementRect.height); |
162 return params; | 163 return params; |
163 }; | 164 }; |
164 | 165 |
165 GuestViewContainer.prototype.dispatchEvent = function(event) { | 166 GuestViewContainer.prototype.dispatchEvent = function(event) { |
166 return this.element.dispatchEvent(event); | 167 return this.element.dispatchEvent(event); |
167 } | 168 } |
168 | 169 |
169 // Implemented by the specific view type, if needed. | 170 // Implemented by the specific view type, if needed. |
170 GuestViewContainer.prototype.buildContainerParams = function() { return {}; }; | 171 GuestViewContainer.prototype.buildContainerParams = function() { return {}; }; |
171 // TODO(paulmeyer): remove once all view types use attribute objects. | |
172 GuestViewContainer.prototype.handleAttributeMutation = function( | |
173 attributeName, oldValue, newValue) {}; | |
174 GuestViewContainer.prototype.onElementAttached = function() {}; | 172 GuestViewContainer.prototype.onElementAttached = function() {}; |
175 GuestViewContainer.prototype.onElementDetached = function() {}; | 173 GuestViewContainer.prototype.onElementDetached = function() {}; |
| 174 GuestViewContainer.prototype.setupAttributes = function() {}; |
176 | 175 |
177 // Registers the browser plugin <object> custom element. |viewType| is the | 176 // Registers the browser plugin <object> custom element. |viewType| is the |
178 // name of the specific guestview container (e.g. 'webview'). | 177 // name of the specific guestview container (e.g. 'webview'). |
179 function registerBrowserPluginElement(viewType) { | 178 function registerBrowserPluginElement(viewType) { |
180 var proto = Object.create(HTMLObjectElement.prototype); | 179 var proto = Object.create(HTMLObjectElement.prototype); |
181 | 180 |
182 proto.createdCallback = function() { | 181 proto.createdCallback = function() { |
183 this.setAttribute('type', 'application/browser-plugin'); | 182 this.setAttribute('type', 'application/browser-plugin'); |
184 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); | 183 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); |
185 this.style.width = '100%'; | 184 this.style.width = '100%'; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 var internal = privates(this).internal; | 222 var internal = privates(this).internal; |
224 if (!internal) { | 223 if (!internal) { |
225 return; | 224 return; |
226 } | 225 } |
227 internal.elementAttached = true; | 226 internal.elementAttached = true; |
228 internal.onElementAttached(); | 227 internal.onElementAttached(); |
229 }; | 228 }; |
230 | 229 |
231 proto.attributeChangedCallback = function(name, oldValue, newValue) { | 230 proto.attributeChangedCallback = function(name, oldValue, newValue) { |
232 var internal = privates(this).internal; | 231 var internal = privates(this).internal; |
233 if (!internal) { | 232 if (!internal || !internal.attributes[name]) { |
234 return; | 233 return; |
235 } | 234 } |
236 internal.handleAttributeMutation(name, oldValue, newValue); | 235 |
| 236 // Let the changed attribute handle its own mutation. |
| 237 internal.attributes[name].maybeHandleMutation(oldValue, newValue); |
237 }; | 238 }; |
238 | 239 |
239 proto.detachedCallback = function() { | 240 proto.detachedCallback = function() { |
240 var internal = privates(this).internal; | 241 var internal = privates(this).internal; |
241 if (!internal) { | 242 if (!internal) { |
242 return; | 243 return; |
243 } | 244 } |
244 internal.elementAttached = false; | 245 internal.elementAttached = false; |
245 internal.internalInstanceId = 0; | 246 internal.internalInstanceId = 0; |
246 internal.guest.destroy(); | 247 internal.guest.destroy(); |
(...skipping 14 matching lines...) Expand all Loading... |
261 // Delete the callbacks so developers cannot call them and produce unexpected | 262 // Delete the callbacks so developers cannot call them and produce unexpected |
262 // behavior. | 263 // behavior. |
263 delete proto.createdCallback; | 264 delete proto.createdCallback; |
264 delete proto.attachedCallback; | 265 delete proto.attachedCallback; |
265 delete proto.detachedCallback; | 266 delete proto.detachedCallback; |
266 delete proto.attributeChangedCallback; | 267 delete proto.attributeChangedCallback; |
267 } | 268 } |
268 | 269 |
269 // Exports. | 270 // Exports. |
270 exports.GuestViewContainer = GuestViewContainer; | 271 exports.GuestViewContainer = GuestViewContainer; |
OLD | NEW |