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

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

Issue 706473002: Automated the definitions of webview attributes as properties on the webview node. (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
« no previous file with comments | « extensions/renderer/resources/guest_view/web_view.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.webViewImpl = webViewImpl; 16 this.webViewImpl = webViewImpl;
17 this.ignoreNextMutation = false; 17 this.ignoreNextMutation = false;
18 } 18 }
19 19
20 // Retrieves and returns the attribute's value. 20 // Retrieves and returns the attribute's value.
21 WebViewAttribute.prototype.getValue = function() { 21 WebViewAttribute.prototype.getValue = function() {
22 return this.webViewImpl.webviewNode.getAttribute(this.name) || ''; 22 return this.webViewImpl.webviewNode.getAttribute(this.name) || '';
23 }; 23 };
24 24
25 // Sets the attribute's value. 25 // Sets the attribute's value.
26 WebViewAttribute.prototype.setValue = function(value) { 26 WebViewAttribute.prototype.setValue = function(value) {
27 this.webViewImpl.webviewNode.setAttribute(this.name, value || ''); 27 this.webViewImpl.webviewNode.setAttribute(this.name, value || '');
28 }; 28 };
29 29
30 // Defines this attribute as a property on the webview node.
31 WebViewAttribute.prototype.define = function() {
32 Object.defineProperty(this.webViewImpl.webviewNode, this.name, {
33 get: function() {
34 return this.getValue();
35 }.bind(this),
36 set: function(value) {
37 this.setValue(value);
38 }.bind(this),
39 enumerable: true
40 });
41 };
42
30 // Called when the attribute's value changes. 43 // Called when the attribute's value changes.
31 WebViewAttribute.prototype.handleMutation = function() {} 44 WebViewAttribute.prototype.handleMutation = function(oldValue, newValue) {};
32 45
33 // Attribute specifying whether transparency is allowed in the webview. 46 // An attribute that is treated as a Boolean.
34 function BooleanAttribute(name, webViewImpl) { 47 function BooleanAttribute(name, webViewImpl) {
35 WebViewAttribute.call(this, name, webViewImpl); 48 WebViewAttribute.call(this, name, webViewImpl);
36 } 49 }
37 50
38 BooleanAttribute.prototype = new WebViewAttribute(); 51 BooleanAttribute.prototype = new WebViewAttribute();
39 52
40 BooleanAttribute.prototype.getValue = function() { 53 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); 54 return this.webViewImpl.webviewNode.hasAttribute(this.name);
43 } 55 };
44 56
45 BooleanAttribute.prototype.setValue = function(value) { 57 BooleanAttribute.prototype.setValue = function(value) {
46 if (!value) { 58 if (!value) {
47 this.webViewImpl.webviewNode.removeAttribute(this.name); 59 this.webViewImpl.webviewNode.removeAttribute(this.name);
48 } else { 60 } else {
49 this.webViewImpl.webviewNode.setAttribute(this.name, ''); 61 this.webViewImpl.webviewNode.setAttribute(this.name, '');
50 } 62 }
51 } 63 };
52 64
53 // Attribute representing the state of the storage partition. 65 // Attribute representing the state of the storage partition.
54 function Partition(webViewImpl) { 66 function Partition(webViewImpl) {
55 WebViewAttribute.call(this, 67 WebViewAttribute.call(this,
56 WebViewConstants.ATTRIBUTE_PARTITION, 68 WebViewConstants.ATTRIBUTE_PARTITION,
57 webViewImpl); 69 webViewImpl);
58 this.validPartitionId = true; 70 this.validPartitionId = true;
59 } 71 }
60 72
61 Partition.prototype = new WebViewAttribute(); 73 Partition.prototype = new WebViewAttribute();
62 74
63 Partition.prototype.handleMutation = function(oldValue, newValue) { 75 Partition.prototype.handleMutation = function(oldValue, newValue) {
64 newValue = newValue || ''; 76 newValue = newValue || '';
65 77
66 // The partition cannot change if the webview has already navigated. 78 // The partition cannot change if the webview has already navigated.
67 if (!this.webViewImpl.beforeFirstNavigation) { 79 if (!this.webViewImpl.beforeFirstNavigation) {
68 window.console.error(WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED); 80 window.console.error(WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED);
69 this.ignoreNextMutation = true; 81 this.ignoreNextMutation = true;
70 this.webViewImpl.webviewNode.setAttribute(this.name, oldValue); 82 this.webViewImpl.webviewNode.setAttribute(this.name, oldValue);
71 return; 83 return;
72 } 84 }
73 if (newValue == 'persist:') { 85 if (newValue == 'persist:') {
74 this.validPartitionId = false; 86 this.validPartitionId = false;
75 window.console.error( 87 window.console.error(
76 WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE); 88 WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE);
77 } 89 }
78 } 90 };
79 91
80 // ----------------------------------------------------------------------------- 92 // -----------------------------------------------------------------------------
81 93
82 // Sets up all of the webview attributes. 94 // Sets up all of the webview attributes.
83 WebView.prototype.setupWebViewAttributes = function() { 95 WebView.prototype.setupWebViewAttributes = function() {
84 this.attributes = {}; 96 this.attributes = {};
85 97
86 // Initialize the attributes with special behavior (and custom attribute 98 // Initialize the attributes with special behavior (and custom attribute
87 // objects). 99 // objects).
88 this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] = 100 this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] =
89 new BooleanAttribute(WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, this); 101 new BooleanAttribute(WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, this);
90 this.attributes[WebViewConstants.ATTRIBUTE_AUTOSIZE] = 102 this.attributes[WebViewConstants.ATTRIBUTE_AUTOSIZE] =
91 new BooleanAttribute(WebViewConstants.ATTRIBUTE_AUTOSIZE, this); 103 new BooleanAttribute(WebViewConstants.ATTRIBUTE_AUTOSIZE, this);
92 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION] = new Partition(this); 104 this.attributes[WebViewConstants.ATTRIBUTE_PARTITION] = new Partition(this);
93 105
94 // Initialize the remaining attributes, which have default behavior. 106 // Initialize the remaining attributes, which have default behavior.
95 var defaultAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT, 107 var defaultAttributes = [WebViewConstants.ATTRIBUTE_MAXHEIGHT,
96 WebViewConstants.ATTRIBUTE_MAXWIDTH, 108 WebViewConstants.ATTRIBUTE_MAXWIDTH,
97 WebViewConstants.ATTRIBUTE_MINHEIGHT, 109 WebViewConstants.ATTRIBUTE_MINHEIGHT,
98 WebViewConstants.ATTRIBUTE_MINWIDTH, 110 WebViewConstants.ATTRIBUTE_MINWIDTH,
99 WebViewConstants.ATTRIBUTE_NAME, 111 WebViewConstants.ATTRIBUTE_NAME,
100 WebViewConstants.ATTRIBUTE_SRC]; 112 WebViewConstants.ATTRIBUTE_SRC];
101 for (var i = 0; defaultAttributes[i]; ++i) { 113 for (var i = 0; defaultAttributes[i]; ++i) {
102 this.attributes[defaultAttributes[i]] = 114 this.attributes[defaultAttributes[i]] =
103 new WebViewAttribute(defaultAttributes[i], this); 115 new WebViewAttribute(defaultAttributes[i], this);
104 } 116 }
105 }; 117 };
OLDNEW
« no previous file with comments | « extensions/renderer/resources/guest_view/web_view.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698