| Index: chrome/renderer/resources/extensions/web_view.js
|
| diff --git a/chrome/renderer/resources/extensions/web_view.js b/chrome/renderer/resources/extensions/web_view.js
|
| index 3bed13beaab9d30d95ea6ed93d57b8a732cbccef..fdf9e4a17e5da44886d7bea942501db6326268a6 100644
|
| --- a/chrome/renderer/resources/extensions/web_view.js
|
| +++ b/chrome/renderer/resources/extensions/web_view.js
|
| @@ -15,10 +15,19 @@ var IdGenerator = requireNative('id_generator');
|
| var WebView = require('webViewInternal').WebView;
|
| var WebViewEvents = require('webViewEvents').WebViewEvents;
|
|
|
| +var WEB_VIEW_ATTRIBUTE_AUTOSIZE = 'autosize';
|
| var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight';
|
| var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth';
|
| var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight';
|
| var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth';
|
| +var AUTO_SIZE_ATTRIBUTES = [
|
| + WEB_VIEW_ATTRIBUTE_AUTOSIZE,
|
| + WEB_VIEW_ATTRIBUTE_MAXHEIGHT,
|
| + WEB_VIEW_ATTRIBUTE_MAXWIDTH,
|
| + WEB_VIEW_ATTRIBUTE_MINHEIGHT,
|
| + WEB_VIEW_ATTRIBUTE_MINWIDTH
|
| +];
|
| +
|
| var WEB_VIEW_ATTRIBUTE_PARTITION = 'partition';
|
|
|
| var PLUGIN_METHOD_ATTACH = '-internal-attach';
|
| @@ -30,11 +39,6 @@ var ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.';
|
| /** @type {Array.<string>} */
|
| var WEB_VIEW_ATTRIBUTES = [
|
| 'allowtransparency',
|
| - 'autosize',
|
| - WEB_VIEW_ATTRIBUTE_MINHEIGHT,
|
| - WEB_VIEW_ATTRIBUTE_MINWIDTH,
|
| - WEB_VIEW_ATTRIBUTE_MAXHEIGHT,
|
| - WEB_VIEW_ATTRIBUTE_MAXWIDTH
|
| ];
|
|
|
| /** @class representing state of storage partition. */
|
| @@ -314,6 +318,22 @@ WebViewInternal.prototype.insertCSS = function(var_args) {
|
| $Function.apply(WebView.insertCSS, null, args);
|
| };
|
|
|
| +WebViewInternal.prototype.setupAutoSizeProperties = function() {
|
| + var self = this;
|
| + $Array.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) {
|
| + this[attributeName] = this.webviewNode.getAttribute(attributeName);
|
| + Object.defineProperty(this.webviewNode, attributeName, {
|
| + get: function() {
|
| + return self[attributeName];
|
| + },
|
| + set: function(value) {
|
| + self.webviewNode.setAttribute(attributeName, value);
|
| + },
|
| + enumerable: true
|
| + });
|
| + }, this);
|
| +};
|
| +
|
| /**
|
| * @private
|
| */
|
| @@ -322,6 +342,7 @@ WebViewInternal.prototype.setupWebviewNodeProperties = function() {
|
| 'contentWindow is not available at this time. It will become available ' +
|
| 'when the page has finished loading.';
|
|
|
| + this.setupAutoSizeProperties();
|
| var self = this;
|
| var browserPluginNode = this.browserPluginNode;
|
| // Expose getters and setters for the attributes.
|
| @@ -445,7 +466,26 @@ WebViewInternal.prototype.handleWebviewAttributeMutation =
|
| // a BrowserPlugin property will update the corresponding BrowserPlugin
|
| // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
|
| // details.
|
| - if (name == 'name') {
|
| + if (AUTO_SIZE_ATTRIBUTES.indexOf(name) > -1) {
|
| + this[name] = newValue;
|
| + if (!this.instanceId) {
|
| + return;
|
| + }
|
| + // Convert autosize attribute to boolean.
|
| + var autosize = this.webviewNode.hasAttribute(WEB_VIEW_ATTRIBUTE_AUTOSIZE);
|
| + WebView.setAutoSize(this.instanceId, {
|
| + 'enableAutoSize': autosize,
|
| + 'min': {
|
| + 'width': parseInt(this.minwidth || 0),
|
| + 'height': parseInt(this.minheight || 0)
|
| + },
|
| + 'max': {
|
| + 'width': parseInt(this.maxwidth || 0),
|
| + 'height': parseInt(this.maxheight || 0)
|
| + }
|
| + });
|
| + return;
|
| + } else if (name == 'name') {
|
| // We treat null attribute (attribute removed) and the empty string as
|
| // one case.
|
| oldValue = oldValue || '';
|
| @@ -550,7 +590,10 @@ WebViewInternal.prototype.handleBrowserPluginAttributeMutation =
|
| }
|
| };
|
|
|
| -WebViewInternal.prototype.onSizeChanged = function(newWidth, newHeight) {
|
| +WebViewInternal.prototype.onSizeChanged = function(webViewEvent) {
|
| + var newWidth = webViewEvent.newWidth;
|
| + var newHeight = webViewEvent.newHeight;
|
| +
|
| var node = this.webviewNode;
|
|
|
| var width = node.offsetWidth;
|
| @@ -595,12 +638,16 @@ WebViewInternal.prototype.onSizeChanged = function(newWidth, newHeight) {
|
| minHeight = maxHeight;
|
| }
|
|
|
| - if (newWidth >= minWidth &&
|
| - newWidth <= maxWidth &&
|
| - newHeight >= minHeight &&
|
| - newHeight <= maxHeight) {
|
| + if (!this.webviewNode.hasAttribute(WEB_VIEW_ATTRIBUTE_AUTOSIZE) ||
|
| + (newWidth >= minWidth &&
|
| + newWidth <= maxWidth &&
|
| + newHeight >= minHeight &&
|
| + newHeight <= maxHeight)) {
|
| node.style.width = newWidth + 'px';
|
| node.style.height = newHeight + 'px';
|
| + // Only fire the DOM event if the size of the <webview> has actually
|
| + // changed.
|
| + this.dispatchEvent(webViewEvent);
|
| }
|
| };
|
|
|
| @@ -783,8 +830,12 @@ WebViewInternal.prototype.getZoom = function(callback) {
|
|
|
| WebViewInternal.prototype.buildAttachParams = function(isNewWindow) {
|
| var params = {
|
| - 'api': 'webview',
|
| + 'autosize': this.webviewNode.hasAttribute(WEB_VIEW_ATTRIBUTE_AUTOSIZE),
|
| 'instanceId': this.viewInstanceId,
|
| + 'maxheight': parseInt(this.maxheight || 0),
|
| + 'maxwidth': parseInt(this.maxwidth || 0),
|
| + 'minheight': parseInt(this.minheight || 0),
|
| + 'minwidth': parseInt(this.minwidth || 0),
|
| 'name': this.name,
|
| // We don't need to navigate new window from here.
|
| 'src': isNewWindow ? undefined : this.src,
|
|
|