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

Side by Side 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: Works 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This module implements Webview (<webview>) as a custom element that wraps a 5 // This module implements Webview (<webview>) as a custom element that wraps a
6 // BrowserPlugin object element. The object element is hidden within 6 // BrowserPlugin object element. The object element is hidden within
7 // the shadow DOM of the Webview element. 7 // the shadow DOM of the Webview element.
8 8
9 var DocumentNatives = requireNative('document_natives'); 9 var DocumentNatives = requireNative('document_natives');
10 var GuestViewInternal = 10 var GuestViewInternal =
11 require('binding').Binding.create('guestViewInternal').generate(); 11 require('binding').Binding.create('guestViewInternal').generate();
12 var IdGenerator = requireNative('id_generator'); 12 var IdGenerator = requireNative('id_generator');
13 // TODO(lazyboy): Rename this to WebViewInternal and call WebViewInternal 13 // TODO(lazyboy): Rename this to WebViewInternal and call WebViewInternal
14 // something else. 14 // something else.
15 var WebView = require('webViewInternal').WebView; 15 var WebView = require('webViewInternal').WebView;
16 var WebViewEvents = require('webViewEvents').WebViewEvents; 16 var WebViewEvents = require('webViewEvents').WebViewEvents;
17 17
18 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; 18 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight';
19 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; 19 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth';
20 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; 20 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight';
21 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; 21 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth';
22 var AUTO_SIZE_ATTRIBUTES = [
23 'autosize',
24 WEB_VIEW_ATTRIBUTE_MAXHEIGHT,
25 WEB_VIEW_ATTRIBUTE_MAXWIDTH,
26 WEB_VIEW_ATTRIBUTE_MINHEIGHT,
27 WEB_VIEW_ATTRIBUTE_MINWIDTH
28 ];
29
22 var WEB_VIEW_ATTRIBUTE_PARTITION = 'partition'; 30 var WEB_VIEW_ATTRIBUTE_PARTITION = 'partition';
23 31
24 var PLUGIN_METHOD_ATTACH = '-internal-attach'; 32 var PLUGIN_METHOD_ATTACH = '-internal-attach';
25 33
26 var ERROR_MSG_ALREADY_NAVIGATED = 34 var ERROR_MSG_ALREADY_NAVIGATED =
27 'The object has already navigated, so its partition cannot be changed.'; 35 'The object has already navigated, so its partition cannot be changed.';
28 var ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.'; 36 var ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.';
29 37
30 /** @type {Array.<string>} */ 38 /** @type {Array.<string>} */
31 var WEB_VIEW_ATTRIBUTES = [ 39 var WEB_VIEW_ATTRIBUTES = [
32 'allowtransparency', 40 'allowtransparency',
33 'autosize',
34 WEB_VIEW_ATTRIBUTE_MINHEIGHT,
35 WEB_VIEW_ATTRIBUTE_MINWIDTH,
36 WEB_VIEW_ATTRIBUTE_MAXHEIGHT,
37 WEB_VIEW_ATTRIBUTE_MAXWIDTH
38 ]; 41 ];
39 42
40 /** @class representing state of storage partition. */ 43 /** @class representing state of storage partition. */
41 function Partition() { 44 function Partition() {
42 this.validPartitionId = true; 45 this.validPartitionId = true;
43 this.persistStorage = false; 46 this.persistStorage = false;
44 this.storagePartitionId = ''; 47 this.storagePartitionId = '';
45 }; 48 };
46 49
47 Partition.prototype.toAttribute = function() { 50 Partition.prototype.toAttribute = function() {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 /** 310 /**
308 * @private 311 * @private
309 */ 312 */
310 WebViewInternal.prototype.insertCSS = function(var_args) { 313 WebViewInternal.prototype.insertCSS = function(var_args) {
311 this.validateExecuteCodeCall(); 314 this.validateExecuteCodeCall();
312 var args = $Array.concat([this.instanceId, this.src], 315 var args = $Array.concat([this.instanceId, this.src],
313 $Array.slice(arguments)); 316 $Array.slice(arguments));
314 $Function.apply(WebView.insertCSS, null, args); 317 $Function.apply(WebView.insertCSS, null, args);
315 }; 318 };
316 319
320 WebViewInternal.prototype.setupAutoSizeProperties = function() {
321 var self = this;
322 $Array.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) {
323 this[attributeName] = this.webviewNode.getAttribute(attributeName);
324 Object.defineProperty(this.webviewNode, attributeName, {
325 get: function() {
326 return self[attributeName];
327 },
328 set: function(value) {
329 self.webviewNode.setAttribute(attributeName, value);
330 },
331 enumerable: true
332 });
333 }, this);
334 };
335
317 /** 336 /**
318 * @private 337 * @private
319 */ 338 */
320 WebViewInternal.prototype.setupWebviewNodeProperties = function() { 339 WebViewInternal.prototype.setupWebviewNodeProperties = function() {
321 var ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE = '<webview>: ' + 340 var ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE = '<webview>: ' +
322 'contentWindow is not available at this time. It will become available ' + 341 'contentWindow is not available at this time. It will become available ' +
323 'when the page has finished loading.'; 342 'when the page has finished loading.';
324 343
344 this.setupAutoSizeProperties();
325 var self = this; 345 var self = this;
326 var browserPluginNode = this.browserPluginNode; 346 var browserPluginNode = this.browserPluginNode;
327 // Expose getters and setters for the attributes. 347 // Expose getters and setters for the attributes.
328 $Array.forEach(WEB_VIEW_ATTRIBUTES, function(attributeName) { 348 $Array.forEach(WEB_VIEW_ATTRIBUTES, function(attributeName) {
329 Object.defineProperty(this.webviewNode, attributeName, { 349 Object.defineProperty(this.webviewNode, attributeName, {
330 get: function() { 350 get: function() {
331 if (browserPluginNode.hasOwnProperty(attributeName)) { 351 if (browserPluginNode.hasOwnProperty(attributeName)) {
332 return browserPluginNode[attributeName]; 352 return browserPluginNode[attributeName];
333 } else { 353 } else {
334 return browserPluginNode.getAttribute(attributeName); 354 return browserPluginNode.getAttribute(attributeName);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 /** 458 /**
439 * @private 459 * @private
440 */ 460 */
441 WebViewInternal.prototype.handleWebviewAttributeMutation = 461 WebViewInternal.prototype.handleWebviewAttributeMutation =
442 function(name, oldValue, newValue) { 462 function(name, oldValue, newValue) {
443 // This observer monitors mutations to attributes of the <webview> and 463 // This observer monitors mutations to attributes of the <webview> and
444 // updates the BrowserPlugin properties accordingly. In turn, updating 464 // updates the BrowserPlugin properties accordingly. In turn, updating
445 // a BrowserPlugin property will update the corresponding BrowserPlugin 465 // a BrowserPlugin property will update the corresponding BrowserPlugin
446 // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more 466 // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
447 // details. 467 // details.
448 if (name == 'name') { 468 if (AUTO_SIZE_ATTRIBUTES.indexOf(name) > -1) {
469 this[name] = newValue;
470 if (!this.instanceId) {
471 return;
472 }
473 // Convert autosize attribute to boolean.
474 var autosize = (this.autosize + '').toLowerCase() == 'true' ? true : false;
lazyboy 2014/07/31 04:24:22 This is bad way of specifying attributes IIRC, don
Fady Samuel 2014/08/01 18:12:52 Fixed.
475 WebView.setAutoSize(this.instanceId, {
476 'enableAutoSize': autosize,
477 'min': {
478 'width': parseInt(this.minwidth || 0),
479 'height': parseInt(this.minheight || 0)
480 },
481 'max': {
482 'width': parseInt(this.maxwidth || 0),
483 'height': parseInt(this.maxheight || 0)
484 }
485 });
486 } else if (name == 'name') {
449 // We treat null attribute (attribute removed) and the empty string as 487 // We treat null attribute (attribute removed) and the empty string as
450 // one case. 488 // one case.
451 oldValue = oldValue || ''; 489 oldValue = oldValue || '';
452 newValue = newValue || ''; 490 newValue = newValue || '';
453 491
454 if (oldValue === newValue) { 492 if (oldValue === newValue) {
455 return; 493 return;
456 } 494 }
457 this.name = newValue; 495 this.name = newValue;
458 if (!this.instanceId) { 496 if (!this.instanceId) {
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 814
777 WebViewInternal.prototype.getZoom = function(callback) { 815 WebViewInternal.prototype.getZoom = function(callback) {
778 if (!this.instanceId) { 816 if (!this.instanceId) {
779 return; 817 return;
780 } 818 }
781 WebView.getZoom(this.instanceId, callback); 819 WebView.getZoom(this.instanceId, callback);
782 }; 820 };
783 821
784 WebViewInternal.prototype.buildAttachParams = function(isNewWindow) { 822 WebViewInternal.prototype.buildAttachParams = function(isNewWindow) {
785 var params = { 823 var params = {
786 'api': 'webview', 824 'autosize': (this.autosize + '').toLowerCase() == 'true' ? true : false,
787 'instanceId': this.viewInstanceId, 825 'instanceId': this.viewInstanceId,
826 'maxheight': parseInt(this.maxheight || 0),
827 'maxwidth': parseInt(this.maxwidth || 0),
828 'minheight': parseInt(this.minheight || 0),
829 'minwidth': parseInt(this.minwidth || 0),
788 'name': this.name, 830 'name': this.name,
789 // We don't need to navigate new window from here. 831 // We don't need to navigate new window from here.
790 'src': isNewWindow ? undefined : this.src, 832 'src': isNewWindow ? undefined : this.src,
791 // If we have a partition from the opener, that will also be already 833 // If we have a partition from the opener, that will also be already
792 // set via this.onAttach(). 834 // set via this.onAttach().
793 'storagePartitionId': this.partition.toAttribute(), 835 'storagePartitionId': this.partition.toAttribute(),
794 'userAgentOverride': this.userAgentOverride 836 'userAgentOverride': this.userAgentOverride
795 }; 837 };
796 return params; 838 return params;
797 }; 839 };
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 }; 1004 };
963 1005
964 /** 1006 /**
965 * Implemented when the experimental API is available. 1007 * Implemented when the experimental API is available.
966 * @private 1008 * @private
967 */ 1009 */
968 WebViewInternal.prototype.setupExperimentalContextMenus = function() {}; 1010 WebViewInternal.prototype.setupExperimentalContextMenus = function() {};
969 1011
970 exports.WebView = WebView; 1012 exports.WebView = WebView;
971 exports.WebViewInternal = WebViewInternal; 1013 exports.WebViewInternal = WebViewInternal;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698