Commit aef58f49 authored by paulmeyer's avatar paulmeyer Committed by Commit bot

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}
parent 4b9c829d
...@@ -125,35 +125,10 @@ WebView.prototype.validateExecuteCodeCall = function() { ...@@ -125,35 +125,10 @@ WebView.prototype.validateExecuteCodeCall = function() {
} }
}; };
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() { WebView.prototype.setupWebviewNodeProperties = function() {
this.setupAutoSizeProperties(); for (var attributeName in this.attributes) {
this.attributes[attributeName].define();
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
});
// We cannot use {writable: true} property descriptor because we want a // We cannot use {writable: true} property descriptor because we want a
// dynamic getter value. // dynamic getter value.
...@@ -168,37 +143,6 @@ WebView.prototype.setupWebviewNodeProperties = function() { ...@@ -168,37 +143,6 @@ WebView.prototype.setupWebviewNodeProperties = function() {
// No setter. // No setter.
enumerable: true 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 // The purpose of this mutation observer is to catch assignment to the src
......
...@@ -27,10 +27,23 @@ WebViewAttribute.prototype.setValue = function(value) { ...@@ -27,10 +27,23 @@ WebViewAttribute.prototype.setValue = function(value) {
this.webViewImpl.webviewNode.setAttribute(this.name, value || ''); this.webViewImpl.webviewNode.setAttribute(this.name, value || '');
}; };
// 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
});
};
// Called when the attribute's value changes. // Called when the attribute's value changes.
WebViewAttribute.prototype.handleMutation = function() {} WebViewAttribute.prototype.handleMutation = function(oldValue, newValue) {};
// Attribute specifying whether transparency is allowed in the webview. // An attribute that is treated as a Boolean.
function BooleanAttribute(name, webViewImpl) { function BooleanAttribute(name, webViewImpl) {
WebViewAttribute.call(this, name, webViewImpl); WebViewAttribute.call(this, name, webViewImpl);
} }
...@@ -38,9 +51,8 @@ function BooleanAttribute(name, webViewImpl) { ...@@ -38,9 +51,8 @@ function BooleanAttribute(name, webViewImpl) {
BooleanAttribute.prototype = new WebViewAttribute(); BooleanAttribute.prototype = new WebViewAttribute();
BooleanAttribute.prototype.getValue = function() { BooleanAttribute.prototype.getValue = function() {
// This attribute is treated as a boolean, and is retrieved as such.
return this.webViewImpl.webviewNode.hasAttribute(this.name); return this.webViewImpl.webviewNode.hasAttribute(this.name);
} };
BooleanAttribute.prototype.setValue = function(value) { BooleanAttribute.prototype.setValue = function(value) {
if (!value) { if (!value) {
...@@ -48,7 +60,7 @@ BooleanAttribute.prototype.setValue = function(value) { ...@@ -48,7 +60,7 @@ BooleanAttribute.prototype.setValue = function(value) {
} else { } else {
this.webViewImpl.webviewNode.setAttribute(this.name, ''); this.webViewImpl.webviewNode.setAttribute(this.name, '');
} }
} };
// Attribute representing the state of the storage partition. // Attribute representing the state of the storage partition.
function Partition(webViewImpl) { function Partition(webViewImpl) {
...@@ -75,7 +87,7 @@ Partition.prototype.handleMutation = function(oldValue, newValue) { ...@@ -75,7 +87,7 @@ Partition.prototype.handleMutation = function(oldValue, newValue) {
window.console.error( window.console.error(
WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE); WebViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE);
} }
} };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment