Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: extensions/renderer/resources/guest_view/web_view_attributes.js

Issue 698973003: Got rid of the internal copies of webview attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 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 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 WebView = require('webView').WebView; 7 var WebView = require('webView').WebView;
8 var WebViewConstants = require('webViewConstants').WebViewConstants; 8 var WebViewConstants = require('webViewConstants').WebViewConstants;
9 9
10 // ----------------------------------------------------------------------------- 10 // -----------------------------------------------------------------------------
11 // Attribute objects. 11 // Attribute objects.
12 12
13 // Default implementation of a WebView attribute. 13 // Default implementation of a WebView attribute.
14 function WebViewAttribute(name, webViewImpl) { 14 function WebViewAttribute(name, webViewImpl) {
15 this.name = name; 15 this.name = name;
16 this.value = '';
17 this.webViewImpl = webViewImpl; 16 this.webViewImpl = webViewImpl;
17 this.ignoreNextMutation = false;
18 } 18 }
19 19
20 // Retrieves and returns the attribute's value.
20 WebViewAttribute.prototype.getValue = function() { 21 WebViewAttribute.prototype.getValue = function() {
21 return this.value || ''; 22 return this.webViewImpl.webviewNode.getAttribute(this.name);
22 }; 23 };
23 24
25 // Sets the attribute's value.
24 WebViewAttribute.prototype.setValue = function(value) { 26 WebViewAttribute.prototype.setValue = function(value) {
25 this.value = value; 27 this.webViewImpl.webviewNode.setAttribute(this.name, !value ? '' : value);
26 }; 28 };
27 29
30 // Called when the attribute's value changes.
31 WebViewAttribute.prototype.handleMutation = function() {}
32
33 // Attribute specifying whether transparency is allowed in the webview.
34 function BooleanAttribute(name, webViewImpl) {
35 WebViewAttribute.call(this, name, webViewImpl);
36 }
37
38 BooleanAttribute.prototype = new WebViewAttribute();
39
40 BooleanAttribute.prototype.getValue = function() {
41 // This attribute is treated as a boolean, and is retrieved as such.
42 return this.webViewImpl.webviewNode.hasAttribute(this.name);
43 }
44
45 BooleanAttribute.prototype.setValue = function(value) {
46 if (!value) {
47 this.webViewImpl.webviewNode.removeAttribute(this.name);
48 } else {
49 this.webViewImpl.webviewNode.setAttribute(this.name, '');
50 }
51 }
52
28 // Attribute representing the state of the storage partition. 53 // Attribute representing the state of the storage partition.
29 function Partition(webViewImpl) { 54 function Partition(webViewImpl) {
55 WebViewAttribute.call(this,
56 WebViewConstants.ATTRIBUTE_PARTITION,
57 webViewImpl);
30 this.validPartitionId = true; 58 this.validPartitionId = true;
31 this.persistStorage = false; 59 this.persistStorage = false;
32 this.storagePartitionId = ''; 60 this.storagePartitionId = '';
33 this.webViewImpl = webViewImpl;
34 } 61 }
35 62
36 Partition.prototype = new WebViewAttribute( 63 Partition.prototype = new WebViewAttribute();
37 WebViewConstants.ATTRIBUTE_PARTITION);
38 64
39 Partition.prototype.getValue = function() { 65 Partition.prototype.handleMutation = function(oldValue, newValue) {
40 if (!this.validPartitionId) { 66 newValue = newValue || '';
41 return ''; 67
68 // Set |persistStorage| and |storagePartitionId| from |newValue|.
69 var LEN = 'persist:'.length;
70 this.persistStorage = newValue.substr(0, LEN) == 'persist:';
71 this.storagePartitionId = this.persistStorage ? newValue.substr(LEN) :
72 newValue;
Fady Samuel 2014/11/03 22:38:18 It doesn't seem like you need both persistStorage
paulmeyer 2014/11/03 22:58:19 Done.
73
74 // The partition cannot change if the webview has already navigated.
75 if (!this.webViewImpl.beforeFirstNavigation) {
76 window.console.error(WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED);
77 this.ignoreNextMutation = true;
78 this.webViewImpl.webviewNode.setAttribute(this.name, oldValue);
79 return;
42 } 80 }
43 return (this.persistStorage ? 'persist:' : '') + this.storagePartitionId; 81 if (newValue == 'persist:') {
44 }; 82 this.validPartitionId = false;
45 83 window.console.error(
46 Partition.prototype.setValue = function(value) { 84 WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE);
47 var result = {};
48 var hasNavigated = !this.webViewImpl.beforeFirstNavigation;
49 if (hasNavigated) {
50 result.error = WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED;
51 return result;
52 } 85 }
53 if (!value) { 86 }
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 87
74 // ----------------------------------------------------------------------------- 88 // -----------------------------------------------------------------------------
75 89
76 // Sets up all of the webview attributes. 90 // Sets up all of the webview attributes.
77 WebView.prototype.setupWebViewAttributes = function() { 91 WebView.prototype.setupWebViewAttributes = function() {
78 this.attributes = {}; 92 this.attributes = {};
79 93
80 // Initialize the attributes with special behavior (and custom attribute 94 // Initialize the attributes with special behavior (and custom attribute
81 // objects). 95 // objects).
96 this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] =
97 new BooleanAttribute(WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, this);
98 this.attributes[WebViewConstants.ATTRIBUTE_AUTOSIZE] =
99 new BooleanAttribute(WebViewConstants.ATTRIBUTE_AUTOSIZE, this);
82 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION] = new Partition(this); 100 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION] = new Partition(this);
83 101
84 // Initialize the remaining attributes, which have default behavior. 102 // Initialize the remaining attributes, which have default behavior.
85 var defaultAttributes = [WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, 103 var defaultAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT,
86 WebViewConstants.ATTRIBUTE_AUTOSIZE,
87 WebViewConstants.ATTRIBUTE_MAXHEIGHT,
88 WebViewConstants.ATTRIBUTE_MAXWIDTH, 104 WebViewConstants.ATTRIBUTE_MAXWIDTH,
89 WebViewConstants.ATTRIBUTE_MINHEIGHT, 105 WebViewConstants.ATTRIBUTE_MINHEIGHT,
90 WebViewConstants.ATTRIBUTE_MINWIDTH, 106 WebViewConstants.ATTRIBUTE_MINWIDTH,
91 WebViewConstants.ATTRIBUTE_NAME, 107 WebViewConstants.ATTRIBUTE_NAME,
92 WebViewConstants.ATTRIBUTE_SRC]; 108 WebViewConstants.ATTRIBUTE_SRC];
93 for (var i = 0; defaultAttributes[i]; ++i) { 109 for (var i = 0; defaultAttributes[i]; ++i) {
94 this.attributes[defaultAttributes[i]] = 110 this.attributes[defaultAttributes[i]] =
95 new WebViewAttribute(defaultAttributes[i], this); 111 new WebViewAttribute(defaultAttributes[i], this);
96 } 112 }
97 }; 113 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698