OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 WebView (<webview>) as a custom element that wraps a | 5 // This module implements WebView (<webview>) as a custom element that wraps a |
6 // BrowserPlugin object element. The object element is hidden within | 6 // BrowserPlugin object element. The object element is hidden within |
7 // the shadow DOM of the WebView element. | 7 // the shadow DOM of the WebView element. |
8 | 8 |
9 var DocumentNatives = requireNative('document_natives'); | 9 var DocumentNatives = requireNative('document_natives'); |
10 var GuestView = require('guestView').GuestView; | 10 var GuestView = require('guestView').GuestView; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 WebViewImpl.prototype.onElementAttached = function() { | 67 WebViewImpl.prototype.onElementAttached = function() { |
68 this.attributes[WebViewConstants.ATTRIBUTE_SRC].parse(); | 68 this.attributes[WebViewConstants.ATTRIBUTE_SRC].parse(); |
69 }; | 69 }; |
70 | 70 |
71 // Resets some state upon detaching <webview> element from the DOM. | 71 // Resets some state upon detaching <webview> element from the DOM. |
72 WebViewImpl.prototype.onElementDetached = function() { | 72 WebViewImpl.prototype.onElementDetached = function() { |
73 this.guest.destroy(); | 73 this.guest.destroy(); |
74 this.beforeFirstNavigation = true; | 74 this.beforeFirstNavigation = true; |
75 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].validPartitionId = | 75 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].validPartitionId = |
76 true; | 76 true; |
77 this.internalInstanceId = 0; | |
78 }; | 77 }; |
79 | 78 |
80 // Sets the <webview>.request property. | 79 // Sets the <webview>.request property. |
81 WebViewImpl.prototype.setRequestPropertyOnWebViewElement = function(request) { | 80 WebViewImpl.prototype.setRequestPropertyOnWebViewElement = function(request) { |
82 Object.defineProperty( | 81 Object.defineProperty( |
83 this.element, | 82 this.element, |
84 'request', | 83 'request', |
85 { | 84 { |
86 value: request, | 85 value: request, |
87 enumerable: true | 86 enumerable: true |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 newHeight <= maxHeight)) { | 146 newHeight <= maxHeight)) { |
148 element.style.width = newWidth + 'px'; | 147 element.style.width = newWidth + 'px'; |
149 element.style.height = newHeight + 'px'; | 148 element.style.height = newHeight + 'px'; |
150 // Only fire the DOM event if the size of the <webview> has actually | 149 // Only fire the DOM event if the size of the <webview> has actually |
151 // changed. | 150 // changed. |
152 this.dispatchEvent(webViewEvent); | 151 this.dispatchEvent(webViewEvent); |
153 } | 152 } |
154 }; | 153 }; |
155 | 154 |
156 WebViewImpl.prototype.createGuest = function() { | 155 WebViewImpl.prototype.createGuest = function() { |
157 var params = { | 156 this.guest.create(this.buildParams(), function() { |
158 'instanceId': this.viewInstanceId, | |
159 'userAgentOverride': this.userAgentOverride, | |
160 'width': this.element.offsetWidth, | |
161 'height': this.element.offsetHeight, | |
162 }; | |
163 for (var i in this.attributes) { | |
164 params[i] = this.attributes[i].getValue(); | |
165 } | |
166 | |
167 this.guest.create(params, function() { | |
168 this.attachWindow(); | 157 this.attachWindow(); |
169 }.bind(this)); | 158 }.bind(this)); |
170 }; | 159 }; |
171 | 160 |
172 WebViewImpl.prototype.onFrameNameChanged = function(name) { | 161 WebViewImpl.prototype.onFrameNameChanged = function(name) { |
173 name = name || ''; | 162 name = name || ''; |
174 if (name === '') { | 163 if (name === '') { |
175 this.element.removeAttribute(WebViewConstants.ATTRIBUTE_NAME); | 164 this.element.removeAttribute(WebViewConstants.ATTRIBUTE_NAME); |
176 } else { | 165 } else { |
177 this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValue(name); | 166 this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValue(name); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation( | 207 this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation( |
219 newValue); | 208 newValue); |
220 } | 209 } |
221 }; | 210 }; |
222 | 211 |
223 WebViewImpl.prototype.onAttach = function(storagePartitionId) { | 212 WebViewImpl.prototype.onAttach = function(storagePartitionId) { |
224 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValue( | 213 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValue( |
225 storagePartitionId); | 214 storagePartitionId); |
226 }; | 215 }; |
227 | 216 |
228 WebViewImpl.prototype.buildAttachParams = function() { | 217 WebViewImpl.prototype.buildContainerParams = function() { |
229 var params = { 'userAgentOverride': this.userAgentOverride }; | 218 var params = { 'userAgentOverride': this.userAgentOverride }; |
230 for (var i in this.attributes) { | 219 for (var i in this.attributes) { |
231 params[i] = this.attributes[i].getValue(); | 220 params[i] = this.attributes[i].getValue(); |
232 } | 221 } |
233 return params; | 222 return params; |
234 }; | 223 }; |
235 | 224 |
236 WebViewImpl.prototype.attachWindow = function(opt_guestInstanceId) { | 225 WebViewImpl.prototype.attachWindow = function(opt_guestInstanceId) { |
237 // If |opt_guestInstanceId| was provided, then a different existing guest is | 226 // If |opt_guestInstanceId| was provided, then a different existing guest is |
238 // being attached to this webview, and the current one will get destroyed. | 227 // being attached to this webview, and the current one will get destroyed. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 WebViewImpl.prototype.setupExperimentalContextMenus = function() {}; | 262 WebViewImpl.prototype.setupExperimentalContextMenus = function() {}; |
274 WebViewImpl.prototype.maybeSetupExperimentalChromeWebViewEvents = | 263 WebViewImpl.prototype.maybeSetupExperimentalChromeWebViewEvents = |
275 function(request) { | 264 function(request) { |
276 return request; | 265 return request; |
277 }; | 266 }; |
278 | 267 |
279 GuestViewContainer.registerElement(WebViewImpl); | 268 GuestViewContainer.registerElement(WebViewImpl); |
280 | 269 |
281 // Exports. | 270 // Exports. |
282 exports.WebViewImpl = WebViewImpl; | 271 exports.WebViewImpl = WebViewImpl; |
OLD | NEW |