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 | |
94 GuestViewContainer.prototype.attachWindow = function() { | 84 GuestViewContainer.prototype.attachWindow = function() { |
95 if (!this.internalInstanceId) { | 85 if (!this.internalInstanceId) { |
96 return true; | 86 return true; |
97 } | 87 } |
98 | 88 |
99 this.attach(); | 89 this.guest.attach(this.internalInstanceId, |
| 90 this.viewInstanceId, |
| 91 this.buildAttachParams()); |
100 return true; | 92 return true; |
101 }; | 93 }; |
102 | 94 |
103 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = | 95 GuestViewContainer.prototype.handleBrowserPluginAttributeMutation = |
104 function(name, oldValue, newValue) { | 96 function(name, oldValue, newValue) { |
105 if (name == 'internalinstanceid' && !oldValue && !!newValue) { | 97 if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
106 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); | 98 privates(this).browserPluginElement.removeAttribute('internalinstanceid'); |
107 this.internalInstanceId = parseInt(newValue); | 99 this.internalInstanceId = parseInt(newValue); |
108 | 100 |
109 if (!this.guest.getId()) { | 101 if (!this.guest.getId()) { |
110 return; | 102 return; |
111 } | 103 } |
112 this.attach(); | 104 this.guest.attach(this.internalInstanceId, |
| 105 this.viewInstanceId, |
| 106 this.buildAttachParams()); |
113 } | 107 } |
114 }; | 108 }; |
115 | 109 |
116 // Implemented by the specific view type, if needed. | 110 // Implemented by the specific view type, if needed. |
117 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; | 111 GuestViewContainer.prototype.buildAttachParams = function() { return {}; }; |
118 GuestViewContainer.prototype.handleAttributeMutation = function() {}; | 112 GuestViewContainer.prototype.handleAttributeMutation = function() {}; |
119 GuestViewContainer.prototype.onElementAttached = function() {}; | 113 GuestViewContainer.prototype.onElementAttached = function() {}; |
120 GuestViewContainer.prototype.onElementDetached = function() { | 114 GuestViewContainer.prototype.onElementDetached = function() { |
121 this.guest.destroy(); | 115 this.guest.destroy(); |
122 }; | 116 }; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // Delete the callbacks so developers cannot call them and produce unexpected | 200 // Delete the callbacks so developers cannot call them and produce unexpected |
207 // behavior. | 201 // behavior. |
208 delete proto.createdCallback; | 202 delete proto.createdCallback; |
209 delete proto.attachedCallback; | 203 delete proto.attachedCallback; |
210 delete proto.detachedCallback; | 204 delete proto.detachedCallback; |
211 delete proto.attributeChangedCallback; | 205 delete proto.attributeChangedCallback; |
212 } | 206 } |
213 | 207 |
214 // Exports. | 208 // Exports. |
215 exports.GuestViewContainer = GuestViewContainer; | 209 exports.GuestViewContainer = GuestViewContainer; |
OLD | NEW |