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 attributes of the <webview> tag. | 5 // This module implements the attributes of the <webview> tag. |
6 | 6 |
7 var GuestViewInternal = | 7 var GuestViewInternal = |
8 require('binding').Binding.create('guestViewInternal').generate(); | 8 require('binding').Binding.create('guestViewInternal').generate(); |
9 var WebViewImpl = require('webView').WebViewImpl; | 9 var WebViewImpl = require('webView').WebViewImpl; |
10 var WebViewConstants = require('webViewConstants').WebViewConstants; | 10 var WebViewConstants = require('webViewConstants').WebViewConstants; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 NameAttribute.prototype.handleMutation = function(oldValue, newValue) { | 177 NameAttribute.prototype.handleMutation = function(oldValue, newValue) { |
178 oldValue = oldValue || ''; | 178 oldValue = oldValue || ''; |
179 newValue = newValue || ''; | 179 newValue = newValue || ''; |
180 if (oldValue === newValue || !this.webViewImpl.guest.getId()) { | 180 if (oldValue === newValue || !this.webViewImpl.guest.getId()) { |
181 return; | 181 return; |
182 } | 182 } |
183 | 183 |
184 WebViewInternal.setName(this.webViewImpl.guest.getId(), newValue); | 184 WebViewInternal.setName(this.webViewImpl.guest.getId(), newValue); |
185 }; | 185 }; |
186 | 186 |
| 187 NameAttribute.prototype.setValue = function(value) { |
| 188 value = value || ''; |
| 189 if (value === '') { |
| 190 this.webViewImpl.element.removeAttribute(this.name); |
| 191 } else { |
| 192 this.webViewImpl.element.setAttribute(this.name, value); |
| 193 } |
| 194 }; |
| 195 |
187 // Attribute representing the state of the storage partition. | 196 // Attribute representing the state of the storage partition. |
188 function PartitionAttribute(webViewImpl) { | 197 function PartitionAttribute(webViewImpl) { |
189 WebViewAttribute.call( | 198 WebViewAttribute.call( |
190 this, WebViewConstants.ATTRIBUTE_PARTITION, webViewImpl); | 199 this, WebViewConstants.ATTRIBUTE_PARTITION, webViewImpl); |
191 this.validPartitionId = true; | 200 this.validPartitionId = true; |
192 } | 201 } |
193 | 202 |
194 PartitionAttribute.prototype.__proto__ = WebViewAttribute.prototype; | 203 PartitionAttribute.prototype.__proto__ = WebViewAttribute.prototype; |
195 | 204 |
196 PartitionAttribute.prototype.handleMutation = function(oldValue, newValue) { | 205 PartitionAttribute.prototype.handleMutation = function(oldValue, newValue) { |
(...skipping 20 matching lines...) Expand all Loading... |
217 // Attribute that handles the location and navigation of the webview. | 226 // Attribute that handles the location and navigation of the webview. |
218 function SrcAttribute(webViewImpl) { | 227 function SrcAttribute(webViewImpl) { |
219 WebViewAttribute.call(this, WebViewConstants.ATTRIBUTE_SRC, webViewImpl); | 228 WebViewAttribute.call(this, WebViewConstants.ATTRIBUTE_SRC, webViewImpl); |
220 this.setupMutationObserver(); | 229 this.setupMutationObserver(); |
221 this.beforeFirstNavigation = true; | 230 this.beforeFirstNavigation = true; |
222 } | 231 } |
223 | 232 |
224 SrcAttribute.prototype.__proto__ = WebViewAttribute.prototype; | 233 SrcAttribute.prototype.__proto__ = WebViewAttribute.prototype; |
225 | 234 |
226 SrcAttribute.prototype.setValueIgnoreMutation = function(value) { | 235 SrcAttribute.prototype.setValueIgnoreMutation = function(value) { |
| 236 WebViewAttribute.prototype.setValueIgnoreMutation.call(this, value); |
227 // takeRecords() is needed to clear queued up src mutations. Without it, it is | 237 // takeRecords() is needed to clear queued up src mutations. Without it, it is |
228 // possible for this change to get picked up asyncronously by src's mutation | 238 // possible for this change to get picked up asyncronously by src's mutation |
229 // observer |observer|, and then get handled even though we do not want to | 239 // observer |observer|, and then get handled even though we do not want to |
230 // handle this mutation. | 240 // handle this mutation. |
231 this.observer.takeRecords(); | 241 this.observer.takeRecords(); |
232 WebViewAttribute.prototype.setValueIgnoreMutation.call(this, value); | |
233 } | 242 } |
234 | 243 |
235 SrcAttribute.prototype.handleMutation = function(oldValue, newValue) { | 244 SrcAttribute.prototype.handleMutation = function(oldValue, newValue) { |
236 // Once we have navigated, we don't allow clearing the src attribute. | 245 // Once we have navigated, we don't allow clearing the src attribute. |
237 // Once <webview> enters a navigated state, it cannot return to a | 246 // Once <webview> enters a navigated state, it cannot return to a |
238 // placeholder state. | 247 // placeholder state. |
239 if (!newValue && oldValue) { | 248 if (!newValue && oldValue) { |
240 // src attribute changes normally initiate a navigation. We suppress | 249 // src attribute changes normally initiate a navigation. We suppress |
241 // the next src attribute handler call to avoid reloading the page | 250 // the next src attribute handler call to avoid reloading the page |
242 // on every guest-initiated navigation. | 251 // on every guest-initiated navigation. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 324 |
316 var autosizeAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT, | 325 var autosizeAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT, |
317 WebViewConstants.ATTRIBUTE_MAXWIDTH, | 326 WebViewConstants.ATTRIBUTE_MAXWIDTH, |
318 WebViewConstants.ATTRIBUTE_MINHEIGHT, | 327 WebViewConstants.ATTRIBUTE_MINHEIGHT, |
319 WebViewConstants.ATTRIBUTE_MINWIDTH]; | 328 WebViewConstants.ATTRIBUTE_MINWIDTH]; |
320 for (var i = 0; autosizeAttributes[i]; ++i) { | 329 for (var i = 0; autosizeAttributes[i]; ++i) { |
321 this.attributes[autosizeAttributes[i]] = | 330 this.attributes[autosizeAttributes[i]] = |
322 new AutosizeDimensionAttribute(autosizeAttributes[i], this); | 331 new AutosizeDimensionAttribute(autosizeAttributes[i], this); |
323 } | 332 } |
324 }; | 333 }; |
OLD | NEW |