Automated the definitions of webview attributes as properties on the webview node.
Review URL: https://codereview.chromium.org/706473002
Cr-Commit-Position: refs/heads/master@{#302720}
diff --git a/extensions/renderer/resources/guest_view/web_view.js b/extensions/renderer/resources/guest_view/web_view.js
index 31f4b531..958f97a 100644
--- a/extensions/renderer/resources/guest_view/web_view.js
+++ b/extensions/renderer/resources/guest_view/web_view.js
@@ -125,35 +125,10 @@
}
};
-WebView.prototype.setupAutoSizeProperties = function() {
- $Array.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) {
- Object.defineProperty(this.webviewNode, attributeName, {
- get: function() {
- return this.attributes[attributeName].getValue();
- }.bind(this),
- set: function(value) {
- this.attributes[attributeName].setValue(value);
- }.bind(this),
- enumerable: true
- });
- }.bind(this), this);
-};
-
WebView.prototype.setupWebviewNodeProperties = function() {
- this.setupAutoSizeProperties();
-
- Object.defineProperty(this.webviewNode,
- WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, {
- get: function() {
- return this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY].
- getValue();
- }.bind(this),
- set: function(value) {
- this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY].
- setValue(value);
- }.bind(this),
- enumerable: true
- });
+ for (var attributeName in this.attributes) {
+ this.attributes[attributeName].define();
+ }
// We cannot use {writable: true} property descriptor because we want a
// dynamic getter value.
@@ -168,37 +143,6 @@
// No setter.
enumerable: true
});
-
- Object.defineProperty(this.webviewNode, WebViewConstants.ATTRIBUTE_NAME, {
- get: function() {
- return this.attributes[WebViewConstants.ATTRIBUTE_NAME].getValue();
- }.bind(this),
- set: function(value) {
- this.attributes[WebViewConstants.ATTRIBUTE_NAME].setValue(value);
- }.bind(this),
- enumerable: true
- });
-
- Object.defineProperty(this.webviewNode,
- WebViewConstants.ATTRIBUTE_PARTITION, {
- get: function() {
- return this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].getValue();
- }.bind(this),
- set: function(value) {
- this.attributes[WebViewConstants.ATTRIBUTE_PARTITION].setValue(value);
- }.bind(this),
- enumerable: true
- });
-
- Object.defineProperty(this.webviewNode, WebViewConstants.ATTRIBUTE_SRC, {
- get: function() {
- return this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue();
- }.bind(this),
- set: function(value) {
- this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValue(value);
- }.bind(this),
- enumerable: true
- });
};
// The purpose of this mutation observer is to catch assignment to the src
diff --git a/extensions/renderer/resources/guest_view/web_view_attributes.js b/extensions/renderer/resources/guest_view/web_view_attributes.js
index 1e02b89..1144b2e 100644
--- a/extensions/renderer/resources/guest_view/web_view_attributes.js
+++ b/extensions/renderer/resources/guest_view/web_view_attributes.js
@@ -27,10 +27,23 @@
this.webViewImpl.webviewNode.setAttribute(this.name, value || '');
};
-// Called when the attribute's value changes.
-WebViewAttribute.prototype.handleMutation = function() {}
+// Defines this attribute as a property on the webview node.
+WebViewAttribute.prototype.define = function() {
+ Object.defineProperty(this.webViewImpl.webviewNode, this.name, {
+ get: function() {
+ return this.getValue();
+ }.bind(this),
+ set: function(value) {
+ this.setValue(value);
+ }.bind(this),
+ enumerable: true
+ });
+};
-// Attribute specifying whether transparency is allowed in the webview.
+// Called when the attribute's value changes.
+WebViewAttribute.prototype.handleMutation = function(oldValue, newValue) {};
+
+// An attribute that is treated as a Boolean.
function BooleanAttribute(name, webViewImpl) {
WebViewAttribute.call(this, name, webViewImpl);
}
@@ -38,9 +51,8 @@
BooleanAttribute.prototype = new WebViewAttribute();
BooleanAttribute.prototype.getValue = function() {
- // This attribute is treated as a boolean, and is retrieved as such.
return this.webViewImpl.webviewNode.hasAttribute(this.name);
-}
+};
BooleanAttribute.prototype.setValue = function(value) {
if (!value) {
@@ -48,7 +60,7 @@
} else {
this.webViewImpl.webviewNode.setAttribute(this.name, '');
}
-}
+};
// Attribute representing the state of the storage partition.
function Partition(webViewImpl) {
@@ -75,7 +87,7 @@
window.console.error(
WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE);
}
-}
+};
// -----------------------------------------------------------------------------