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

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: Small fix. 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 || '');
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;
32 this.storagePartitionId = '';
33 this.webViewImpl = webViewImpl;
34 } 59 }
35 60
36 Partition.prototype = new WebViewAttribute( 61 Partition.prototype = new WebViewAttribute();
37 WebViewConstants.ATTRIBUTE_PARTITION);
38 62
39 Partition.prototype.getValue = function() { 63 Partition.prototype.handleMutation = function(oldValue, newValue) {
40 if (!this.validPartitionId) { 64 newValue = newValue || '';
41 return ''; 65
66 // The partition cannot change if the webview has already navigated.
67 if (!this.webViewImpl.beforeFirstNavigation) {
68 window.console.error(WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED);
69 this.ignoreNextMutation = true;
70 this.webViewImpl.webviewNode.setAttribute(this.name, oldValue);
71 return;
42 } 72 }
43 return (this.persistStorage ? 'persist:' : '') + this.storagePartitionId; 73 if (newValue == 'persist:') {
44 }; 74 this.validPartitionId = false;
45 75 window.console.error(
46 Partition.prototype.setValue = function(value) { 76 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 } 77 }
53 if (!value) { 78 }
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 79
74 // ----------------------------------------------------------------------------- 80 // -----------------------------------------------------------------------------
75 81
76 // Sets up all of the webview attributes. 82 // Sets up all of the webview attributes.
77 WebView.prototype.setupWebViewAttributes = function() { 83 WebView.prototype.setupWebViewAttributes = function() {
78 this.attributes = {}; 84 this.attributes = {};
79 85
80 // Initialize the attributes with special behavior (and custom attribute 86 // Initialize the attributes with special behavior (and custom attribute
81 // objects). 87 // objects).
88 this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] =
89 new BooleanAttribute(WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, this);
90 this.attributes[WebViewConstants.ATTRIBUTE_AUTOSIZE] =
91 new BooleanAttribute(WebViewConstants.ATTRIBUTE_AUTOSIZE, this);
82 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION] = new Partition(this); 92 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION] = new Partition(this);
83 93
84 // Initialize the remaining attributes, which have default behavior. 94 // Initialize the remaining attributes, which have default behavior.
85 var defaultAttributes = [WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, 95 var defaultAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT,
86 WebViewConstants.ATTRIBUTE_AUTOSIZE,
87 WebViewConstants.ATTRIBUTE_MAXHEIGHT,
88 WebViewConstants.ATTRIBUTE_MAXWIDTH, 96 WebViewConstants.ATTRIBUTE_MAXWIDTH,
89 WebViewConstants.ATTRIBUTE_MINHEIGHT, 97 WebViewConstants.ATTRIBUTE_MINHEIGHT,
90 WebViewConstants.ATTRIBUTE_MINWIDTH, 98 WebViewConstants.ATTRIBUTE_MINWIDTH,
91 WebViewConstants.ATTRIBUTE_NAME, 99 WebViewConstants.ATTRIBUTE_NAME,
92 WebViewConstants.ATTRIBUTE_SRC]; 100 WebViewConstants.ATTRIBUTE_SRC];
93 for (var i = 0; defaultAttributes[i]; ++i) { 101 for (var i = 0; defaultAttributes[i]; ++i) {
94 this.attributes[defaultAttributes[i]] = 102 this.attributes[defaultAttributes[i]] =
95 new WebViewAttribute(defaultAttributes[i], this); 103 new WebViewAttribute(defaultAttributes[i], this);
96 } 104 }
97 }; 105 };
OLDNEW
« no previous file with comments | « extensions/renderer/resources/guest_view/web_view.js ('k') | extensions/test/data/web_view/apitest/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698