| Index: extensions/renderer/resources/guest_view/web_view/web_view_attributes.js
|
| diff --git a/extensions/renderer/resources/guest_view/web_view/web_view_attributes.js b/extensions/renderer/resources/guest_view/web_view/web_view_attributes.js
|
| index a70e9f9a15e46e35e79720db7674d7c101434994..3b666a24e54754e0db67326aede9717a782566f4 100644
|
| --- a/extensions/renderer/resources/guest_view/web_view/web_view_attributes.js
|
| +++ b/extensions/renderer/resources/guest_view/web_view/web_view_attributes.js
|
| @@ -4,212 +4,147 @@
|
|
|
| // This module implements the attributes of the <webview> tag.
|
|
|
| -var GuestViewInternal =
|
| - require('binding').Binding.create('guestViewInternal').generate();
|
| +var GuestViewAttributes = require('guestViewAttributes').GuestViewAttributes;
|
| var WebViewImpl = require('webView').WebViewImpl;
|
| var WebViewConstants = require('webViewConstants').WebViewConstants;
|
| var WebViewInternal = require('webViewInternal').WebViewInternal;
|
|
|
| // -----------------------------------------------------------------------------
|
| -// Attribute objects.
|
| +// AllowScalingAttribute object.
|
|
|
| -// Default implementation of a WebView attribute.
|
| -function WebViewAttribute(name, webViewImpl) {
|
| - this.name = name;
|
| - this.webViewImpl = webViewImpl;
|
| - this.ignoreMutation = false;
|
| -
|
| - this.defineProperty();
|
| -}
|
| -
|
| -// Retrieves and returns the attribute's value.
|
| -WebViewAttribute.prototype.getValue = function() {
|
| - return this.webViewImpl.element.getAttribute(this.name) || '';
|
| -};
|
| -
|
| -// Sets the attribute's value.
|
| -WebViewAttribute.prototype.setValue = function(value) {
|
| - this.webViewImpl.element.setAttribute(this.name, value || '');
|
| -};
|
| -
|
| -// Changes the attribute's value without triggering its mutation handler.
|
| -WebViewAttribute.prototype.setValueIgnoreMutation = function(value) {
|
| - this.ignoreMutation = true;
|
| - this.setValue(value);
|
| - this.ignoreMutation = false;
|
| +// Attribute that specifies whether scaling is allowed in the webview.
|
| +function AllowScalingAttribute(view) {
|
| + GuestViewAttributes.BooleanAttribute.call(
|
| + this, WebViewConstants.ATTRIBUTE_ALLOWSCALING, view);
|
| }
|
|
|
| -// Defines this attribute as a property on the webview node.
|
| -WebViewAttribute.prototype.defineProperty = function() {
|
| - Object.defineProperty(this.webViewImpl.element, 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.
|
| -WebViewAttribute.prototype.maybeHandleMutation = function(oldValue, newValue) {
|
| - if (this.ignoreMutation) {
|
| - return;
|
| - }
|
| -
|
| - this.handleMutation(oldValue, newValue);
|
| -};
|
| -
|
| -// Called when a change that isn't ignored occurs to the attribute's value.
|
| -WebViewAttribute.prototype.handleMutation = function(oldValue, newValue) {};
|
| -
|
| -// Called when the <webview> element is attached to the DOM tree.
|
| -WebViewAttribute.prototype.attach = function() {};
|
| -
|
| -// Called when the <webview> element is detached from the DOM tree.
|
| -WebViewAttribute.prototype.detach = function() {};
|
| +AllowScalingAttribute.prototype.__proto__ =
|
| + GuestViewAttributes.BooleanAttribute.prototype;
|
|
|
| -// An attribute that is treated as a Boolean.
|
| -function BooleanAttribute(name, webViewImpl) {
|
| - WebViewAttribute.call(this, name, webViewImpl);
|
| -}
|
| -
|
| -BooleanAttribute.prototype.__proto__ = WebViewAttribute.prototype;
|
| +AllowScalingAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
| + if (!this.view.guest.getId())
|
| + return;
|
|
|
| -BooleanAttribute.prototype.getValue = function() {
|
| - return this.webViewImpl.element.hasAttribute(this.name);
|
| + WebViewInternal.setAllowScaling(this.view.guest.getId(), this.getValue());
|
| };
|
|
|
| -BooleanAttribute.prototype.setValue = function(value) {
|
| - if (!value) {
|
| - this.webViewImpl.element.removeAttribute(this.name);
|
| - } else {
|
| - this.webViewImpl.element.setAttribute(this.name, '');
|
| - }
|
| -};
|
| +// -----------------------------------------------------------------------------
|
| +// AllowTransparencyAttribute object.
|
|
|
| // Attribute that specifies whether transparency is allowed in the webview.
|
| -function AllowTransparencyAttribute(webViewImpl) {
|
| - BooleanAttribute.call(
|
| - this, WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, webViewImpl);
|
| +function AllowTransparencyAttribute(view) {
|
| + GuestViewAttributes.BooleanAttribute.call(
|
| + this, WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY, view);
|
| }
|
|
|
| -AllowTransparencyAttribute.prototype.__proto__ = BooleanAttribute.prototype;
|
| +AllowTransparencyAttribute.prototype.__proto__ =
|
| + GuestViewAttributes.BooleanAttribute.prototype;
|
|
|
| AllowTransparencyAttribute.prototype.handleMutation = function(oldValue,
|
| newValue) {
|
| - if (!this.webViewImpl.guest.getId()) {
|
| + if (!this.view.guest.getId())
|
| return;
|
| - }
|
|
|
| - WebViewInternal.setAllowTransparency(this.webViewImpl.guest.getId(),
|
| + WebViewInternal.setAllowTransparency(this.view.guest.getId(),
|
| this.getValue());
|
| };
|
|
|
| -// Attribute that specifies whether transparency is allowed in the webview.
|
| -function AllowScalingAttribute(webViewImpl) {
|
| - BooleanAttribute.call(
|
| - this, WebViewConstants.ATTRIBUTE_ALLOWSCALING, webViewImpl);
|
| -}
|
| -
|
| -AllowScalingAttribute.prototype.__proto__ = BooleanAttribute.prototype;
|
| -
|
| -AllowScalingAttribute.prototype.handleMutation = function(oldValue,
|
| - newValue) {
|
| - if (!this.webViewImpl.guest.getId()) {
|
| - return;
|
| - }
|
| -
|
| - WebViewInternal.setAllowScaling(this.webViewImpl.guest.getId(),
|
| - this.getValue());
|
| -};
|
| +// -----------------------------------------------------------------------------
|
| +// AutosizeDimensionAttribute object.
|
|
|
| // Attribute used to define the demension limits of autosizing.
|
| -function AutosizeDimensionAttribute(name, webViewImpl) {
|
| - WebViewAttribute.call(this, name, webViewImpl);
|
| +function AutosizeDimensionAttribute(name, view) {
|
| + GuestViewAttributes.IntegerAttribute.call(this, name, view);
|
| }
|
|
|
| -AutosizeDimensionAttribute.prototype.__proto__ = WebViewAttribute.prototype;
|
| -
|
| -AutosizeDimensionAttribute.prototype.getValue = function() {
|
| - return parseInt(this.webViewImpl.element.getAttribute(this.name)) || 0;
|
| -};
|
| +AutosizeDimensionAttribute.prototype.__proto__ =
|
| + GuestViewAttributes.IntegerAttribute.prototype;
|
|
|
| AutosizeDimensionAttribute.prototype.handleMutation = function(
|
| oldValue, newValue) {
|
| - if (!this.webViewImpl.guest.getId()) {
|
| + if (!this.view.guest.getId())
|
| return;
|
| - }
|
| - this.webViewImpl.guest.setSize({
|
| - 'enableAutoSize': this.webViewImpl.attributes[
|
| - WebViewConstants.ATTRIBUTE_AUTOSIZE].getValue(),
|
| +
|
| + this.view.guest.setSize({
|
| + 'enableAutoSize': this.view.attributes[
|
| + WebViewConstants.ATTRIBUTE_AUTOSIZE].getValue(),
|
| 'min': {
|
| - 'width': this.webViewImpl.attributes[
|
| + 'width': this.view.attributes[
|
| WebViewConstants.ATTRIBUTE_MINWIDTH].getValue(),
|
| - 'height': this.webViewImpl.attributes[
|
| + 'height': this.view.attributes[
|
| WebViewConstants.ATTRIBUTE_MINHEIGHT].getValue()
|
| },
|
| 'max': {
|
| - 'width': this.webViewImpl.attributes[
|
| + 'width': this.view.attributes[
|
| WebViewConstants.ATTRIBUTE_MAXWIDTH].getValue(),
|
| - 'height': this.webViewImpl.attributes[
|
| + 'height': this.view.attributes[
|
| WebViewConstants.ATTRIBUTE_MAXHEIGHT].getValue()
|
| }
|
| });
|
| return;
|
| };
|
|
|
| +// -----------------------------------------------------------------------------
|
| +// AutosizeAttribute object.
|
| +
|
| // Attribute that specifies whether the webview should be autosized.
|
| -function AutosizeAttribute(webViewImpl) {
|
| - BooleanAttribute.call(this, WebViewConstants.ATTRIBUTE_AUTOSIZE, webViewImpl);
|
| +function AutosizeAttribute(view) {
|
| + GuestViewAttributes.BooleanAttribute.call(
|
| + this, WebViewConstants.ATTRIBUTE_AUTOSIZE, view);
|
| }
|
|
|
| -AutosizeAttribute.prototype.__proto__ = BooleanAttribute.prototype;
|
| +AutosizeAttribute.prototype.__proto__ =
|
| + GuestViewAttributes.BooleanAttribute.prototype;
|
|
|
| AutosizeAttribute.prototype.handleMutation =
|
| AutosizeDimensionAttribute.prototype.handleMutation;
|
|
|
| +// -----------------------------------------------------------------------------
|
| +// NameAttribute object.
|
| +
|
| // Attribute that sets the guest content's window.name object.
|
| -function NameAttribute(webViewImpl) {
|
| - WebViewAttribute.call(this, WebViewConstants.ATTRIBUTE_NAME, webViewImpl);
|
| +function NameAttribute(view) {
|
| + GuestViewAttributes.Attribute.call(
|
| + this, WebViewConstants.ATTRIBUTE_NAME, view);
|
| }
|
|
|
| -NameAttribute.prototype.__proto__ = WebViewAttribute.prototype
|
| +NameAttribute.prototype.__proto__ = GuestViewAttributes.Attribute.prototype
|
|
|
| NameAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
| oldValue = oldValue || '';
|
| newValue = newValue || '';
|
| - if (oldValue === newValue || !this.webViewImpl.guest.getId()) {
|
| + if (oldValue === newValue || !this.view.guest.getId())
|
| return;
|
| - }
|
|
|
| - WebViewInternal.setName(this.webViewImpl.guest.getId(), newValue);
|
| + WebViewInternal.setName(this.view.guest.getId(), newValue);
|
| };
|
|
|
| NameAttribute.prototype.setValue = function(value) {
|
| value = value || '';
|
| - if (value === '') {
|
| - this.webViewImpl.element.removeAttribute(this.name);
|
| - } else {
|
| - this.webViewImpl.element.setAttribute(this.name, value);
|
| - }
|
| + if (value === '')
|
| + this.view.element.removeAttribute(this.name);
|
| + else
|
| + this.view.element.setAttribute(this.name, value);
|
| };
|
|
|
| +// -----------------------------------------------------------------------------
|
| +// PartitionAttribute object.
|
| +
|
| // Attribute representing the state of the storage partition.
|
| -function PartitionAttribute(webViewImpl) {
|
| - WebViewAttribute.call(
|
| - this, WebViewConstants.ATTRIBUTE_PARTITION, webViewImpl);
|
| +function PartitionAttribute(view) {
|
| + GuestViewAttributes.Attribute.call(
|
| + this, WebViewConstants.ATTRIBUTE_PARTITION, view);
|
| this.validPartitionId = true;
|
| }
|
|
|
| -PartitionAttribute.prototype.__proto__ = WebViewAttribute.prototype;
|
| +PartitionAttribute.prototype.__proto__ =
|
| + GuestViewAttributes.Attribute.prototype;
|
|
|
| PartitionAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
| newValue = newValue || '';
|
|
|
| // The partition cannot change if the webview has already navigated.
|
| - if (!this.webViewImpl.attributes[
|
| + if (!this.view.attributes[
|
| WebViewConstants.ATTRIBUTE_SRC].beforeFirstNavigation) {
|
| window.console.error(WebViewConstants.ERROR_MSG_ALREADY_NAVIGATED);
|
| this.setValueIgnoreMutation(oldValue);
|
| @@ -226,18 +161,22 @@ PartitionAttribute.prototype.detach = function() {
|
| this.validPartitionId = true;
|
| };
|
|
|
| +// -----------------------------------------------------------------------------
|
| +// SrcAttribute object.
|
| +
|
| // Attribute that handles the location and navigation of the webview.
|
| -function SrcAttribute(webViewImpl) {
|
| - WebViewAttribute.call(this, WebViewConstants.ATTRIBUTE_SRC, webViewImpl);
|
| +function SrcAttribute(view) {
|
| + GuestViewAttributes.Attribute.call(
|
| + this, WebViewConstants.ATTRIBUTE_SRC, view);
|
| this.setupMutationObserver();
|
| this.beforeFirstNavigation = true;
|
| - this.elementAttached = false;
|
| }
|
|
|
| -SrcAttribute.prototype.__proto__ = WebViewAttribute.prototype;
|
| +SrcAttribute.prototype.__proto__ = GuestViewAttributes.Attribute.prototype;
|
|
|
| SrcAttribute.prototype.setValueIgnoreMutation = function(value) {
|
| - WebViewAttribute.prototype.setValueIgnoreMutation.call(this, value);
|
| + GuestViewAttributes.Attribute.prototype.setValueIgnoreMutation.call(
|
| + this, value);
|
| // takeRecords() is needed to clear queued up src mutations. Without it, it is
|
| // possible for this change to get picked up asyncronously by src's mutation
|
| // observer |observer|, and then get handled even though we do not want to
|
| @@ -260,13 +199,11 @@ SrcAttribute.prototype.handleMutation = function(oldValue, newValue) {
|
| };
|
|
|
| SrcAttribute.prototype.attach = function() {
|
| - this.elementAttached = true;
|
| this.parse();
|
| };
|
|
|
| SrcAttribute.prototype.detach = function() {
|
| this.beforeFirstNavigation = true;
|
| - this.elementAttached = false;
|
| };
|
|
|
| // The purpose of this mutation observer is to catch assignment to the src
|
| @@ -290,27 +227,26 @@ SrcAttribute.prototype.setupMutationObserver =
|
| attributeOldValue: true,
|
| attributeFilter: [this.name]
|
| };
|
| - this.observer.observe(this.webViewImpl.element, params);
|
| + this.observer.observe(this.view.element, params);
|
| };
|
|
|
| SrcAttribute.prototype.parse = function() {
|
| - if (!this.elementAttached ||
|
| - !this.webViewImpl.attributes[
|
| + if (!this.view.elementAttached ||
|
| + !this.view.attributes[
|
| WebViewConstants.ATTRIBUTE_PARTITION].validPartitionId ||
|
| !this.getValue()) {
|
| return;
|
| }
|
|
|
| - if (!this.webViewImpl.guest.getId()) {
|
| + if (!this.view.guest.getId()) {
|
| if (this.beforeFirstNavigation) {
|
| this.beforeFirstNavigation = false;
|
| - this.webViewImpl.createGuest();
|
| + this.view.createGuest();
|
| }
|
| return;
|
| }
|
|
|
| - // Navigate to |src|.
|
| - WebViewInternal.navigate(this.webViewImpl.guest.getId(), this.getValue());
|
| + WebViewInternal.navigate(this.view.guest.getId(), this.getValue());
|
| };
|
|
|
| // -----------------------------------------------------------------------------
|
| @@ -319,10 +255,10 @@ SrcAttribute.prototype.parse = function() {
|
| WebViewImpl.prototype.setupWebViewAttributes = function() {
|
| this.attributes = {};
|
|
|
| - this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] =
|
| - new AllowTransparencyAttribute(this);
|
| this.attributes[WebViewConstants.ATTRIBUTE_ALLOWSCALING] =
|
| new AllowScalingAttribute(this);
|
| + this.attributes[WebViewConstants.ATTRIBUTE_ALLOWTRANSPARENCY] =
|
| + new AllowTransparencyAttribute(this);
|
| this.attributes[WebViewConstants.ATTRIBUTE_AUTOSIZE] =
|
| new AutosizeAttribute(this);
|
| this.attributes[WebViewConstants.ATTRIBUTE_NAME] =
|
|
|