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 IdGenerator = requireNative('id_generator'); | 10 var IdGenerator = requireNative('id_generator'); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 this.element.addEventListener('focus', function(e) { | 74 this.element.addEventListener('focus', function(e) { |
75 // Focus the BrowserPlugin when the GuestViewContainer takes focus. | 75 // Focus the BrowserPlugin when the GuestViewContainer takes focus. |
76 privates(this).browserPluginElement.focus(); | 76 privates(this).browserPluginElement.focus(); |
77 }.bind(this)); | 77 }.bind(this)); |
78 this.element.addEventListener('blur', function(e) { | 78 this.element.addEventListener('blur', function(e) { |
79 // Blur the BrowserPlugin when the GuestViewContainer loses focus. | 79 // Blur the BrowserPlugin when the GuestViewContainer loses focus. |
80 privates(this).browserPluginElement.blur(); | 80 privates(this).browserPluginElement.blur(); |
81 }.bind(this)); | 81 }.bind(this)); |
82 }; | 82 }; |
83 | 83 |
| 84 GuestViewContainer.prototype.attach = function() { |
| 85 // Augment the attach parameters with the element size, so that the guestview |
| 86 // can fit the element initially. |
| 87 var attachParams = this.buildAttachParams(); |
| 88 attachParams['elementWidth'] = parseInt(this.element.offsetWidth); |
| 89 attachParams['elementHeight'] = parseInt(this.element.offsetHeight); |
| 90 |
| 91 this.guest.attach(this.internalInstanceId, this.viewInstanceId, attachParams); |
| 92 }; |
| 93 |
84 GuestViewContainer.prototype.attachWindow = function() { | 94 GuestViewContainer.prototype.attachWindow = function() { |
85 if (!this.internalInstanceId) { | 95 if (!this.internalInstanceId) { |
86 return true; | 96 return true; |
87 } | 97 } |
88 | 98 |
89 this.guest.attach(this.internalInstanceId, | 99 this.attach(); |
90 this.viewInstanceId, | |
91 this.buildAttachParams()); | |
92 return true; | 100 return true; |
93 }; | 101 }; |
94 | 102 |
95 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = | 103 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = |
96 function(name, oldValue, newValue) { | 104 function(name, oldValue, newValue) { |
97 if (name == 'internalinstanceid' && !oldValue && !!newValue) { | 105 if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
98 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); | 106 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); |
99 this.internalInstanceId = parseInt(newValue); | 107 this.internalInstanceId = parseInt(newValue); |
100 | 108 |
101 if (!this.guest.getId()) { | 109 if (!this.guest.getId()) { |
102 return; | 110 return; |
103 } | 111 } |
104 this.guest.attach(this.internalInstanceId, | 112 this.attach(); |
105 this.viewInstanceId, | |
106 this.buildAttachParams()); | |
107 } | 113 } |
108 }; | 114 }; |
109 | 115 |
110 // Implemented by the specific view type, if needed. | 116 // Implemented by the specific view type, if needed. |
111 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; | 117 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; |
112 GuestViewContainer.prototype.handleAttributeMutation = function() {}; | 118 GuestViewContainer.prototype.handleAttributeMutation = function() {}; |
113 GuestViewContainer.prototype.onElementAttached = function() {}; | 119 GuestViewContainer.prototype.onElementAttached = function() {}; |
114 GuestViewContainer.prototype.onElementDetached = function() { | 120 GuestViewContainer.prototype.onElementDetached = function() { |
115 this.guest.destroy(); | 121 this.guest.destroy(); |
116 }; | 122 }; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Delete the callbacks so developers cannot call them and produce unexpected | 206 // Delete the callbacks so developers cannot call them and produce unexpected |
201 // behavior. | 207 // behavior. |
202 delete proto.createdCallback; | 208 delete proto.createdCallback; |
203 delete proto.attachedCallback; | 209 delete proto.attachedCallback; |
204 delete proto.detachedCallback; | 210 delete proto.detachedCallback; |
205 delete proto.attributeChangedCallback; | 211 delete proto.attributeChangedCallback; |
206 } | 212 } |
207 | 213 |
208 // Exports. | 214 // Exports. |
209 exports.GuestViewContainer = GuestViewContainer; | 215 exports.GuestViewContainer = GuestViewContainer; |
OLD | NEW |