| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 params['elementHeight'] = parseInt(elementRect.height); | 161 params['elementHeight'] = parseInt(elementRect.height); |
| 162 return params; | 162 return params; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 GuestViewContainer.prototype.dispatchEvent = function(event) { | 165 GuestViewContainer.prototype.dispatchEvent = function(event) { |
| 166 return this.element.dispatchEvent(event); | 166 return this.element.dispatchEvent(event); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Implemented by the specific view type, if needed. | 169 // Implemented by the specific view type, if needed. |
| 170 GuestViewContainer.prototype.buildContainerParams = function() { return {}; }; | 170 GuestViewContainer.prototype.buildContainerParams = function() { return {}; }; |
| 171 GuestViewContainer.prototype.handleAttributeMutation = function() {}; | 171 // TODO(paulmeyer): remove once all view types use attribute objects. |
| 172 GuestViewContainer.prototype.handleAttributeMutation = function( |
| 173 attributeName, oldValue, newValue) {}; |
| 172 GuestViewContainer.prototype.onElementAttached = function() {}; | 174 GuestViewContainer.prototype.onElementAttached = function() {}; |
| 173 GuestViewContainer.prototype.onElementDetached = function() { | 175 GuestViewContainer.prototype.onElementDetached = function() {}; |
| 174 this.guest.destroy(); | |
| 175 }; | |
| 176 | 176 |
| 177 // Registers the browser plugin <object> custom element. |viewType| is the | 177 // Registers the browser plugin <object> custom element. |viewType| is the |
| 178 // name of the specific guestview container (e.g. 'webview'). | 178 // name of the specific guestview container (e.g. 'webview'). |
| 179 function registerBrowserPluginElement(viewType) { | 179 function registerBrowserPluginElement(viewType) { |
| 180 var proto = Object.create(HTMLObjectElement.prototype); | 180 var proto = Object.create(HTMLObjectElement.prototype); |
| 181 | 181 |
| 182 proto.createdCallback = function() { | 182 proto.createdCallback = function() { |
| 183 this.setAttribute('type', 'application/browser-plugin'); | 183 this.setAttribute('type', 'application/browser-plugin'); |
| 184 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); | 184 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); |
| 185 this.style.width = '100%'; | 185 this.style.width = '100%'; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 internal.handleAttributeMutation(name, oldValue, newValue); | 236 internal.handleAttributeMutation(name, oldValue, newValue); |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 proto.detachedCallback = function() { | 239 proto.detachedCallback = function() { |
| 240 var internal = privates(this).internal; | 240 var internal = privates(this).internal; |
| 241 if (!internal) { | 241 if (!internal) { |
| 242 return; | 242 return; |
| 243 } | 243 } |
| 244 internal.elementAttached = false; | 244 internal.elementAttached = false; |
| 245 internal.internalInstanceId = 0; | 245 internal.internalInstanceId = 0; |
| 246 internal.guest.destroy(); |
| 246 internal.onElementDetached(); | 247 internal.onElementDetached(); |
| 247 }; | 248 }; |
| 248 | 249 |
| 249 // Let the specific view type add extra functionality to its custom element | 250 // Let the specific view type add extra functionality to its custom element |
| 250 // through |proto|. | 251 // through |proto|. |
| 251 if (guestViewContainerType.setupElement) { | 252 if (guestViewContainerType.setupElement) { |
| 252 guestViewContainerType.setupElement(proto); | 253 guestViewContainerType.setupElement(proto); |
| 253 } | 254 } |
| 254 | 255 |
| 255 window[guestViewContainerType.VIEW_TYPE] = | 256 window[guestViewContainerType.VIEW_TYPE] = |
| 256 DocumentNatives.RegisterElement( | 257 DocumentNatives.RegisterElement( |
| 257 guestViewContainerType.VIEW_TYPE.toLowerCase(), | 258 guestViewContainerType.VIEW_TYPE.toLowerCase(), |
| 258 {prototype: proto}); | 259 {prototype: proto}); |
| 259 | 260 |
| 260 // Delete the callbacks so developers cannot call them and produce unexpected | 261 // Delete the callbacks so developers cannot call them and produce unexpected |
| 261 // behavior. | 262 // behavior. |
| 262 delete proto.createdCallback; | 263 delete proto.createdCallback; |
| 263 delete proto.attachedCallback; | 264 delete proto.attachedCallback; |
| 264 delete proto.detachedCallback; | 265 delete proto.detachedCallback; |
| 265 delete proto.attributeChangedCallback; | 266 delete proto.attributeChangedCallback; |
| 266 } | 267 } |
| 267 | 268 |
| 268 // Exports. | 269 // Exports. |
| 269 exports.GuestViewContainer = GuestViewContainer; | 270 exports.GuestViewContainer = GuestViewContainer; |
| OLD | NEW |