| 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 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 this.buildAttachParams()); | 92 this.buildAttachParams()); |
| 92 return true; | 93 return true; |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = | 96 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = |
| 96 function(name, oldValue, newValue) { | 97 function(name, oldValue, newValue) { |
| 97 if (name == 'internalinstanceid' && !oldValue && !!newValue) { | 98 if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
| 98 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); | 99 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); |
| 99 this.internalInstanceId = parseInt(newValue); | 100 this.internalInstanceId = parseInt(newValue); |
| 100 | 101 |
| 102 // Track when the element resizes using the element resize callback. |
| 103 GuestViewInternalNatives.RegisterElementResizeCallback( |
| 104 this.internalInstanceId, this.onElementResize.bind(this)); |
| 105 |
| 101 if (!this.guest.getId()) { | 106 if (!this.guest.getId()) { |
| 102 return; | 107 return; |
| 103 } | 108 } |
| 104 this.guest.attach(this.internalInstanceId, | 109 this.guest.attach(this.internalInstanceId, |
| 105 this.viewInstanceId, | 110 this.viewInstanceId, |
| 106 this.buildAttachParams()); | 111 this.buildAttachParams()); |
| 107 } | 112 } |
| 108 }; | 113 }; |
| 109 | 114 |
| 110 // Implemented by the specific view type, if needed. | 115 // Implemented by the specific view type, if needed. |
| 111 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; | 116 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; |
| 112 GuestViewContainer.prototype.handleAttributeMutation = function() {}; | 117 GuestViewContainer.prototype.handleAttributeMutation = function() {}; |
| 113 GuestViewContainer.prototype.onElementAttached = function() {}; | 118 GuestViewContainer.prototype.onElementAttached = function() {}; |
| 114 GuestViewContainer.prototype.onElementDetached = function() { | 119 GuestViewContainer.prototype.onElementDetached = function() { |
| 115 this.guest.destroy(); | 120 this.guest.destroy(); |
| 116 }; | 121 }; |
| 122 GuestViewContainer.prototype.onElementResize = function(oldWidth, oldHeight, |
| 123 newWidth, newHeight) { |
| 124 // TODO(paulmeyer): If any code is entered here, and this function is called |
| 125 // while the dev-tools inspect window is open, chrome will crash. |
| 126 }; |
| 117 | 127 |
| 118 // Registers the browser plugin <object> custom element. |viewType| is the | 128 // Registers the browser plugin <object> custom element. |viewType| is the |
| 119 // name of the specific guestview container (e.g. 'webview'). | 129 // name of the specific guestview container (e.g. 'webview'). |
| 120 function registerBrowserPluginElement(viewType) { | 130 function registerBrowserPluginElement(viewType) { |
| 121 var proto = Object.create(HTMLObjectElement.prototype); | 131 var proto = Object.create(HTMLObjectElement.prototype); |
| 122 | 132 |
| 123 proto.createdCallback = function() { | 133 proto.createdCallback = function() { |
| 124 this.setAttribute('type', 'application/browser-plugin'); | 134 this.setAttribute('type', 'application/browser-plugin'); |
| 125 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); | 135 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); |
| 126 this.style.width = '100%'; | 136 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 | 210 // Delete the callbacks so developers cannot call them and produce unexpected |
| 201 // behavior. | 211 // behavior. |
| 202 delete proto.createdCallback; | 212 delete proto.createdCallback; |
| 203 delete proto.attachedCallback; | 213 delete proto.attachedCallback; |
| 204 delete proto.detachedCallback; | 214 delete proto.detachedCallback; |
| 205 delete proto.attributeChangedCallback; | 215 delete proto.attributeChangedCallback; |
| 206 } | 216 } |
| 207 | 217 |
| 208 // Exports. | 218 // Exports. |
| 209 exports.GuestViewContainer = GuestViewContainer; | 219 exports.GuestViewContainer = GuestViewContainer; |
| OLD | NEW |