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

Unified Diff: chrome/renderer/resources/extensions/web_view.js

Issue 427883002: <webview>: Move autosize from content to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_frame_url
Patch Set: Initialize variable Created 6 years, 4 months 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 side-by-side diff with in-line comments
Download patch
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 f97867a78a2baf7867273dd1a7c1ffa47850a642..a21a4ab5de093d81d49fac130a7dfa38f2ef5398 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. */
@@ -315,6 +319,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
*/
@@ -323,6 +343,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.
@@ -446,7 +467,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);
+ GuestViewInternal.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 || '';
@@ -551,7 +591,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;
@@ -596,12 +639,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);
}
};
@@ -788,8 +835,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,
« no previous file with comments | « chrome/common/extensions/api/guest_view_internal.json ('k') | chrome/renderer/resources/extensions/web_view_events.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698