| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 this.element.addEventListener('focus', function(e) { | 75 this.element.addEventListener('focus', function(e) { |
| 76 // Focus the BrowserPlugin when the GuestViewContainer takes focus. | 76 // Focus the BrowserPlugin when the GuestViewContainer takes focus. |
| 77 privates(this).browserPluginElement.focus(); | 77 privates(this).browserPluginElement.focus(); |
| 78 }.bind(this)); | 78 }.bind(this)); |
| 79 this.element.addEventListener('blur', function(e) { | 79 this.element.addEventListener('blur', function(e) { |
| 80 // Blur the BrowserPlugin when the GuestViewContainer loses focus. | 80 // Blur the BrowserPlugin when the GuestViewContainer loses focus. |
| 81 privates(this).browserPluginElement.blur(); | 81 privates(this).browserPluginElement.blur(); |
| 82 }.bind(this)); | 82 }.bind(this)); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 GuestViewContainer.prototype.attach = function() { | |
| 86 // Augment the attach parameters with the element size, so that the guestview | |
| 87 // can fit the element initially. | |
| 88 var attachParams = this.buildAttachParams(); | |
| 89 attachParams['elementWidth'] = parseInt(this.element.offsetWidth); | |
| 90 attachParams['elementHeight'] = parseInt(this.element.offsetHeight); | |
| 91 | |
| 92 this.guest.attach(this.internalInstanceId, this.viewInstanceId, attachParams); | |
| 93 }; | |
| 94 | |
| 95 GuestViewContainer.prototype.attachWindow = function() { | 85 GuestViewContainer.prototype.attachWindow = function() { |
| 96 if (!this.internalInstanceId) { | 86 if (!this.internalInstanceId) { |
| 97 return true; | 87 return true; |
| 98 } | 88 } |
| 99 | 89 |
| 100 this.attach(); | 90 this.guest.attach(this.internalInstanceId, |
| 91 this.viewInstanceId, |
| 92 this.buildParams()); |
| 101 return true; | 93 return true; |
| 102 }; | 94 }; |
| 103 | 95 |
| 104 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = | 96 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = |
| 105 function(name, oldValue, newValue) { | 97 function(name, oldValue, newValue) { |
| 106 if (name == 'internalinstanceid' && !oldValue && !!newValue) { | 98 if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
| 107 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); | 99 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); |
| 108 this.internalInstanceId = parseInt(newValue); | 100 this.internalInstanceId = parseInt(newValue); |
| 109 | 101 |
| 110 // Track when the element resizes using the element resize callback. | 102 // Track when the element resizes using the element resize callback. |
| 111 GuestViewInternalNatives.RegisterElementResizeCallback( | 103 GuestViewInternalNatives.RegisterElementResizeCallback( |
| 112 this.internalInstanceId, this.onElementResize.bind(this)); | 104 this.internalInstanceId, this.onElementResize.bind(this)); |
| 113 | 105 |
| 114 if (!this.guest.getId()) { | 106 if (!this.guest.getId()) { |
| 115 return; | 107 return; |
| 116 } | 108 } |
| 117 this.attach(); | 109 this.guest.attach(this.internalInstanceId, |
| 110 this.viewInstanceId, |
| 111 this.buildParams()); |
| 118 } | 112 } |
| 119 }; | 113 }; |
| 120 | 114 |
| 115 GuestViewContainer.prototype.buildParams = function() { |
| 116 var params = this.buildContainerParams(); |
| 117 params['instanceId'] = this.viewInstanceId; |
| 118 params['elementWidth'] = parseInt(this.element.offsetWidth); |
| 119 params['elementHeight'] = parseInt(this.element.offsetHeight); |
| 120 return params; |
| 121 }; |
| 122 |
| 121 // Implemented by the specific view type, if needed. | 123 // Implemented by the specific view type, if needed. |
| 122 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; | 124 GuestViewContainer.prototype.buildContainerParams = function() { return {}; }; |
| 123 GuestViewContainer.prototype.handleAttributeMutation = function() {}; | 125 GuestViewContainer.prototype.handleAttributeMutation = function() {}; |
| 124 GuestViewContainer.prototype.onElementAttached = function() {}; | 126 GuestViewContainer.prototype.onElementAttached = function() {}; |
| 125 GuestViewContainer.prototype.onElementDetached = function() { | 127 GuestViewContainer.prototype.onElementDetached = function() { |
| 126 this.guest.destroy(); | 128 this.guest.destroy(); |
| 127 }; | 129 }; |
| 128 GuestViewContainer.prototype.onElementResize = function(oldWidth, oldHeight, | 130 GuestViewContainer.prototype.onElementResize = function(oldWidth, oldHeight, |
| 129 newWidth, newHeight) {}; | 131 newWidth, newHeight) {}; |
| 130 | 132 |
| 131 // Registers the browser plugin <object> custom element. |viewType| is the | 133 // Registers the browser plugin <object> custom element. |viewType| is the |
| 132 // name of the specific guestview container (e.g. 'webview'). | 134 // name of the specific guestview container (e.g. 'webview'). |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 191 } |
| 190 internal.handleAttributeMutation(name, oldValue, newValue); | 192 internal.handleAttributeMutation(name, oldValue, newValue); |
| 191 }; | 193 }; |
| 192 | 194 |
| 193 proto.detachedCallback = function() { | 195 proto.detachedCallback = function() { |
| 194 var internal = privates(this).internal; | 196 var internal = privates(this).internal; |
| 195 if (!internal) { | 197 if (!internal) { |
| 196 return; | 198 return; |
| 197 } | 199 } |
| 198 internal.elementAttached = false; | 200 internal.elementAttached = false; |
| 201 internal.internalInstanceId = 0; |
| 199 internal.onElementDetached(); | 202 internal.onElementDetached(); |
| 200 }; | 203 }; |
| 201 | 204 |
| 202 // Let the specific view type add extra functionality to its custom element | 205 // Let the specific view type add extra functionality to its custom element |
| 203 // through |proto|. | 206 // through |proto|. |
| 204 if (guestViewContainerType.setupElement) { | 207 if (guestViewContainerType.setupElement) { |
| 205 guestViewContainerType.setupElement(proto); | 208 guestViewContainerType.setupElement(proto); |
| 206 } | 209 } |
| 207 | 210 |
| 208 window[guestViewContainerType.VIEW_TYPE] = | 211 window[guestViewContainerType.VIEW_TYPE] = |
| 209 DocumentNatives.RegisterElement( | 212 DocumentNatives.RegisterElement( |
| 210 guestViewContainerType.VIEW_TYPE.toLowerCase(), | 213 guestViewContainerType.VIEW_TYPE.toLowerCase(), |
| 211 {prototype: proto}); | 214 {prototype: proto}); |
| 212 | 215 |
| 213 // Delete the callbacks so developers cannot call them and produce unexpected | 216 // Delete the callbacks so developers cannot call them and produce unexpected |
| 214 // behavior. | 217 // behavior. |
| 215 delete proto.createdCallback; | 218 delete proto.createdCallback; |
| 216 delete proto.attachedCallback; | 219 delete proto.attachedCallback; |
| 217 delete proto.detachedCallback; | 220 delete proto.detachedCallback; |
| 218 delete proto.attributeChangedCallback; | 221 delete proto.attributeChangedCallback; |
| 219 } | 222 } |
| 220 | 223 |
| 221 // Exports. | 224 // Exports. |
| 222 exports.GuestViewContainer = GuestViewContainer; | 225 exports.GuestViewContainer = GuestViewContainer; |
| OLD | NEW |