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

Side by Side Diff: trunk/src/chrome/renderer/resources/extensions/web_view.js

Issue 23833005: Revert 221023 "Reland after fix: Improve <webview> autosize:" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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 // Shim that simulates a <webview> tag via Mutation Observers. 5 // Shim that simulates a <webview> tag via Mutation Observers.
6 // 6 //
7 // The actual tag is implemented via the browser plugin. The internals of this 7 // The actual tag is implemented via the browser plugin. The internals of this
8 // are hidden via Shadow DOM. 8 // are hidden via Shadow DOM.
9 9
10 'use strict'; 10 'use strict';
11 11
12 var DocumentNatives = requireNative('document_natives'); 12 var DocumentNatives = requireNative('document_natives');
13 var EventBindings = require('event_bindings'); 13 var EventBindings = require('event_bindings');
14 var MessagingNatives = requireNative('messaging_natives'); 14 var MessagingNatives = requireNative('messaging_natives');
15 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; 15 var WebRequestEvent = require('webRequestInternal').WebRequestEvent;
16 var WebRequestSchema = 16 var WebRequestSchema =
17 requireNative('schema_registry').GetSchema('webRequest'); 17 requireNative('schema_registry').GetSchema('webRequest');
18 var WebView = require('binding').Binding.create('webview').generate(); 18 var WebView = require('binding').Binding.create('webview').generate();
19 19
20 // This secret enables hiding <webview> private members from the outside scope. 20 // This secret enables hiding <webview> private members from the outside scope.
21 // Outside of this file, |secret| is inaccessible. The only way to access the 21 // Outside of this file, |secret| is inaccessible. The only way to access the
22 // <webview> element's internal members is via the |secret|. Since it's only 22 // <webview> element's internal members is via the |secret|. Since it's only
23 // accessible by code here (and in web_view_experimental), only <webview>'s 23 // accessible by code here (and in web_view_experimental), only <webview>'s
24 // API can access it and not external developers. 24 // API can access it and not external developers.
25 var secret = {}; 25 var secret = {};
26 26
27 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight';
28 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth';
29 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight';
30 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth';
31
32 /** @type {Array.<string>} */ 27 /** @type {Array.<string>} */
33 var WEB_VIEW_ATTRIBUTES = [ 28 var WEB_VIEW_ATTRIBUTES = ['name', 'partition', 'autosize', 'minheight',
34 'name', 29 'minwidth', 'maxheight', 'maxwidth'];
35 'partition',
36 'autosize',
37 WEB_VIEW_ATTRIBUTE_MINHEIGHT,
38 WEB_VIEW_ATTRIBUTE_MINWIDTH,
39 WEB_VIEW_ATTRIBUTE_MAXHEIGHT,
40 WEB_VIEW_ATTRIBUTE_MAXWIDTH
41 ];
42 30
43 var webViewInstanceIdCounter = 0; 31 var webViewInstanceIdCounter = 0;
44 32
45 var CreateEvent = function(name) { 33 var CreateEvent = function(name) {
46 var eventOpts = {supportsListeners: true, supportsFilters: true}; 34 var eventOpts = {supportsListeners: true, supportsFilters: true};
47 return new EventBindings.Event(name, undefined, eventOpts); 35 return new EventBindings.Event(name, undefined, eventOpts);
48 }; 36 };
49 37
50 var WEB_VIEW_EVENTS = { 38 var WEB_VIEW_EVENTS = {
51 'close': { 39 'close': {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 'url', 106 'url',
119 'userGesture' 107 'userGesture'
120 ] 108 ]
121 }, 109 },
122 'responsive': { 110 'responsive': {
123 evt: CreateEvent('webview.onResponsive'), 111 evt: CreateEvent('webview.onResponsive'),
124 fields: ['processId'] 112 fields: ['processId']
125 }, 113 },
126 'sizechanged': { 114 'sizechanged': {
127 evt: CreateEvent('webview.onSizeChanged'), 115 evt: CreateEvent('webview.onSizeChanged'),
128 customHandler: function(webViewInternal, event, webViewEvent) {
129 webViewInternal.handleSizeChangedEvent_(event, webViewEvent);
130 },
131 fields: ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'] 116 fields: ['oldHeight', 'oldWidth', 'newHeight', 'newWidth']
132 }, 117 },
133 'unresponsive': { 118 'unresponsive': {
134 evt: CreateEvent('webview.onUnresponsive'), 119 evt: CreateEvent('webview.onUnresponsive'),
135 fields: ['processId'] 120 fields: ['processId']
136 } 121 }
137 }; 122 };
138 123
139 // Implemented when the experimental API is available. 124 // Implemented when the experimental API is available.
140 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {} 125 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {}
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 * @private 468 * @private
484 */ 469 */
485 WebViewInternal.prototype.getEvents_ = function() { 470 WebViewInternal.prototype.getEvents_ = function() {
486 var experimentalEvents = this.maybeGetExperimentalEvents_(); 471 var experimentalEvents = this.maybeGetExperimentalEvents_();
487 for (var eventName in experimentalEvents) { 472 for (var eventName in experimentalEvents) {
488 WEB_VIEW_EVENTS[eventName] = experimentalEvents[eventName]; 473 WEB_VIEW_EVENTS[eventName] = experimentalEvents[eventName];
489 } 474 }
490 return WEB_VIEW_EVENTS; 475 return WEB_VIEW_EVENTS;
491 }; 476 };
492 477
493 WebViewInternal.prototype.handleSizeChangedEvent_ =
494 function(event, webViewEvent) {
495 var node = this.webviewNode_;
496
497 var width = node.offsetWidth;
498 var height = node.offsetHeight;
499
500 // Check the current bounds to make sure we do not resize <webview>
501 // outside of current constraints.
502 var maxWidth;
503 if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXWIDTH) &&
504 node[WEB_VIEW_ATTRIBUTE_MAXWIDTH]) {
505 maxWidth = node[WEB_VIEW_ATTRIBUTE_MAXWIDTH];
506 } else {
507 maxWidth = width;
508 }
509
510 var minWidth;
511 if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINWIDTH) &&
512 node[WEB_VIEW_ATTRIBUTE_MINWIDTH]) {
513 minWidth = node[WEB_VIEW_ATTRIBUTE_MINWIDTH];
514 } else {
515 minWidth = width;
516 }
517 if (minWidth > maxWidth) {
518 minWidth = maxWidth;
519 }
520
521 var maxHeight;
522 if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXHEIGHT) &&
523 node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT]) {
524 maxHeight = node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT];
525 } else {
526 maxHeight = height;
527 }
528 var minHeight;
529 if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINHEIGHT) &&
530 node[WEB_VIEW_ATTRIBUTE_MINHEIGHT]) {
531 minHeight = node[WEB_VIEW_ATTRIBUTE_MINHEIGHT];
532 } else {
533 minHeight = height;
534 }
535 if (minHeight > maxHeight) {
536 minHeight = maxHeight;
537 }
538
539 if (webViewEvent.newWidth >= minWidth &&
540 webViewEvent.newWidth <= maxWidth &&
541 webViewEvent.newHeight >= minHeight &&
542 webViewEvent.newHeight <= maxHeight) {
543 node.style.width = webViewEvent.newWidth + 'px';
544 node.style.height = webViewEvent.newHeight + 'px';
545 }
546 node.dispatchEvent(webViewEvent);
547 };
548
549 /** 478 /**
550 * @private 479 * @private
551 */ 480 */
552 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { 481 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() {
553 var self = this; 482 var self = this;
554 this.viewInstanceId_ = ++webViewInstanceIdCounter; 483 this.viewInstanceId_ = ++webViewInstanceIdCounter;
555 var onInstanceIdAllocated = function(e) { 484 var onInstanceIdAllocated = function(e) {
556 var detail = e.detail ? JSON.parse(e.detail) : {}; 485 var detail = e.detail ? JSON.parse(e.detail) : {};
557 self.instanceId_ = detail.windowId; 486 self.instanceId_ = detail.windowId;
558 var params = { 487 var params = {
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 861
933 /** 862 /**
934 * Implemented when the experimental API is available. 863 * Implemented when the experimental API is available.
935 * @private 864 * @private
936 */ 865 */
937 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; 866 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {};
938 867
939 exports.WebView = WebView; 868 exports.WebView = WebView;
940 exports.WebViewInternal = WebViewInternal; 869 exports.WebViewInternal = WebViewInternal;
941 exports.CreateEvent = CreateEvent; 870 exports.CreateEvent = CreateEvent;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698