OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // This module implements the attributes of the <webview> tag. |
| 6 |
| 7 var WebView = require('webView').WebView; |
| 8 var WebViewConstants = require('webViewConstants').WebViewConstants; |
| 9 |
| 10 // ----------------------------------------------------------------------------- |
| 11 // Attribute objects. |
| 12 |
| 13 // Default implementation of a WebView attribute. |
| 14 function WebViewAttribute(name, webViewImpl) { |
| 15 this.name = name; |
| 16 this.value = ''; |
| 17 this.webViewImpl = webViewImpl; |
| 18 } |
| 19 |
| 20 WebViewAttribute.prototype.getValue = function() { |
| 21 return this.value || ''; |
| 22 }; |
| 23 |
| 24 WebViewAttribute.prototype.setValue = function(value) { |
| 25 this.value = value; |
| 26 }; |
| 27 |
| 28 // Attribute representing the state of the storage partition. |
| 29 function Partition(webViewImpl) { |
| 30 this.validPartitionId = true; |
| 31 this.persistStorage = false; |
| 32 this.storagePartitionId = ''; |
| 33 this.webViewImpl = webViewImpl; |
| 34 } |
| 35 |
| 36 Partition.prototype = new WebViewAttribute( |
| 37 WebViewConstants.ATTRIBUTE_PARTITION); |
| 38 |
| 39 Partition.prototype.getValue = function() { |
| 40 if (!this.validPartitionId) { |
| 41 return ''; |
| 42 } |
| 43 return (this.persistStorage ? 'persist:' : '') + this.storagePartitionId; |
| 44 }; |
| 45 |
| 46 Partition.prototype.setValue = function(value) { |
| 47 var result = {}; |
| 48 var hasNavigated = !this.webViewImpl.beforeFirstNavigation; |
| 49 if (hasNavigated) { |
| 50 result.error = WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED; |
| 51 return result; |
| 52 } |
| 53 if (!value) { |
| 54 value = ''; |
| 55 } |
| 56 |
| 57 var LEN = 'persist:'.length; |
| 58 if (value.substr(0, LEN) == 'persist:') { |
| 59 value = value.substr(LEN); |
| 60 if (!value) { |
| 61 this.validPartitionId = false; |
| 62 result.error = WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE; |
| 63 return result; |
| 64 } |
| 65 this.persistStorage = true; |
| 66 } else { |
| 67 this.persistStorage = false; |
| 68 } |
| 69 |
| 70 this.storagePartitionId = value; |
| 71 return result; |
| 72 }; |
| 73 |
| 74 // ----------------------------------------------------------------------------- |
| 75 |
| 76 // Sets up all of the webview attributes. |
| 77 WebView.prototype.setupWebViewAttributes = function() { |
| 78 this.attributes = {}; |
| 79 |
| 80 // Initialize the attributes with special behavior (and custom attribute |
| 81 // objects). |
| 82 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION] = new Partition(this); |
| 83 |
| 84 // Initialize the remaining attributes, which have default behavior. |
| 85 var defaultAttributes = [WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, |
| 86 WebViewConstants.ATTRIBUTE_AUTOSIZE, |
| 87 WebViewConstants.ATTRIBUTE_MAXHEIGHT, |
| 88 WebViewConstants.ATTRIBUTE_MAXWIDTH, |
| 89 WebViewConstants.ATTRIBUTE_MINHEIGHT, |
| 90 WebViewConstants.ATTRIBUTE_MINWIDTH, |
| 91 WebViewConstants.ATTRIBUTE_NAME, |
| 92 WebViewConstants.ATTRIBUTE_SRC]; |
| 93 for (var i = 0; defaultAttributes[i]; ++i) { |
| 94 this.attributes[defaultAttributes[i]] = |
| 95 new WebViewAttribute(defaultAttributes[i], this); |
| 96 } |
| 97 }; |
OLD | NEW |