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

Side by Side Diff: extensions/renderer/resources/web_view.js

Issue 564973004: Move ContentWindow from BrowserPlugin To GuestView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments + fixed teardown bug Created 6 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
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 =
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 /** 87 /**
88 * @constructor 88 * @constructor
89 */ 89 */
90 function WebViewInternal(webviewNode) { 90 function WebViewInternal(webviewNode) {
91 privates(webviewNode).internal = this; 91 privates(webviewNode).internal = this;
92 this.webviewNode = webviewNode; 92 this.webviewNode = webviewNode;
93 this.attached = false; 93 this.attached = false;
94 this.elementAttached = false; 94 this.elementAttached = false;
95 95
96 this.beforeFirstNavigation = true; 96 this.beforeFirstNavigation = true;
97 this.contentWindow = null;
97 this.validPartitionId = true; 98 this.validPartitionId = true;
98 // Used to save some state upon deferred attachment. 99 // Used to save some state upon deferred attachment.
99 // If <object> bindings is not available, we defer attachment. 100 // If <object> bindings is not available, we defer attachment.
100 // This state contains whether or not the attachment request was for 101 // This state contains whether or not the attachment request was for
101 // newwindow. 102 // newwindow.
102 this.deferredAttachState = null; 103 this.deferredAttachState = null;
103 104
104 // on* Event handlers. 105 // on* Event handlers.
105 this.on = {}; 106 this.on = {};
106 107
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // already picked up a partition ID. Thus, we need to reset the initialization 160 // already picked up a partition ID. Thus, we need to reset the initialization
160 // state. However, it may be the case that beforeFirstNavigation is false BUT 161 // state. However, it may be the case that beforeFirstNavigation is false BUT
161 // guestInstanceId has yet to be initialized. This means that we have not 162 // guestInstanceId has yet to be initialized. This means that we have not
162 // heard back from createGuest yet. We will not reset the flag in this case so 163 // heard back from createGuest yet. We will not reset the flag in this case so
163 // that we don't end up allocating a second guest. 164 // that we don't end up allocating a second guest.
164 if (this.guestInstanceId) { 165 if (this.guestInstanceId) {
165 this.guestInstanceId = undefined; 166 this.guestInstanceId = undefined;
166 this.beforeFirstNavigation = true; 167 this.beforeFirstNavigation = true;
167 this.validPartitionId = true; 168 this.validPartitionId = true;
168 this.partition.validPartitionId = true; 169 this.partition.validPartitionId = true;
170 this.contentWindow = null;
169 } 171 }
170 this.internalInstanceId = 0; 172 this.internalInstanceId = 0;
171 }; 173 };
172 174
173 // Sets <webview>.request property. 175 // Sets <webview>.request property.
174 WebViewInternal.prototype.setRequestPropertyOnWebViewNode = function(request) { 176 WebViewInternal.prototype.setRequestPropertyOnWebViewNode = function(request) {
175 Object.defineProperty( 177 Object.defineProperty(
176 this.webviewNode, 178 this.webviewNode,
177 'request', 179 'request',
178 { 180 {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 414 }
413 self.webviewNode.setAttribute('partition', value); 415 self.webviewNode.setAttribute('partition', value);
414 }, 416 },
415 enumerable: true 417 enumerable: true
416 }); 418 });
417 419
418 // We cannot use {writable: true} property descriptor because we want a 420 // We cannot use {writable: true} property descriptor because we want a
419 // dynamic getter value. 421 // dynamic getter value.
420 Object.defineProperty(this.webviewNode, 'contentWindow', { 422 Object.defineProperty(this.webviewNode, 'contentWindow', {
421 get: function() { 423 get: function() {
422 if (browserPluginNode.contentWindow) 424 if (this.contentWindow) {
423 return browserPluginNode.contentWindow; 425 return this.contentWindow;
426 }
424 window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); 427 window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE);
425 }, 428 }.bind(this),
426 // No setter. 429 // No setter.
427 enumerable: true 430 enumerable: true
428 }); 431 });
429 }; 432 };
430 433
431 /** 434 /**
432 * @private 435 * @private
433 */ 436 */
434 WebViewInternal.prototype.setupWebviewNodeAttributes = function() { 437 WebViewInternal.prototype.setupWebviewNodeAttributes = function() {
435 this.setupWebViewSrcAttributeMutationObserver(); 438 this.setupWebViewSrcAttributeMutationObserver();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } 571 }
569 572
570 if (!!this.guestInstanceId && this.guestInstanceId != 0) { 573 if (!!this.guestInstanceId && this.guestInstanceId != 0) {
571 window.setTimeout(function() { 574 window.setTimeout(function() {
572 var isNewWindow = this.deferredAttachState ? 575 var isNewWindow = this.deferredAttachState ?
573 this.deferredAttachState.isNewWindow : false; 576 this.deferredAttachState.isNewWindow : false;
574 var params = this.buildAttachParams(isNewWindow); 577 var params = this.buildAttachParams(isNewWindow);
575 guestViewInternalNatives.AttachGuest( 578 guestViewInternalNatives.AttachGuest(
576 this.internalInstanceId, 579 this.internalInstanceId,
577 this.guestInstanceId, 580 this.guestInstanceId,
578 params); 581 params,
582 function(w) {
583 this.contentWindow = w;
Ken Rockot(use gerrit already) 2014/09/17 21:30:37 nit: This indentation seems a little funky to me;
Fady Samuel 2014/09/17 22:05:46 Done.
584 }.bind(this));
579 }.bind(this), 0); 585 }.bind(this), 0);
580 } 586 }
581 587
582 return; 588 return;
583 } 589 }
584 590
585 // This observer monitors mutations to attributes of the BrowserPlugin and 591 // This observer monitors mutations to attributes of the BrowserPlugin and
586 // updates the <webview> attributes accordingly. 592 // updates the <webview> attributes accordingly.
587 // |newValue| is null if the attribute |name| has been removed. 593 // |newValue| is null if the attribute |name| has been removed.
588 if (newValue != null) { 594 if (newValue != null) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 878
873 if (!this.isPluginInRenderTree()) { 879 if (!this.isPluginInRenderTree()) {
874 this.deferredAttachState = {isNewWindow: isNewWindow}; 880 this.deferredAttachState = {isNewWindow: isNewWindow};
875 return true; 881 return true;
876 } 882 }
877 883
878 this.deferredAttachState = null; 884 this.deferredAttachState = null;
879 return guestViewInternalNatives.AttachGuest( 885 return guestViewInternalNatives.AttachGuest(
880 this.internalInstanceId, 886 this.internalInstanceId,
881 this.guestInstanceId, 887 this.guestInstanceId,
882 params); 888 params, function(w) {
889 this.contentWindow = w;
890 }.bind(this));
883 }; 891 };
884 892
885 // Registers browser plugin <object> custom element. 893 // Registers browser plugin <object> custom element.
886 function registerBrowserPluginElement() { 894 function registerBrowserPluginElement() {
887 var proto = Object.create(HTMLObjectElement.prototype); 895 var proto = Object.create(HTMLObjectElement.prototype);
888 896
889 proto.createdCallback = function() { 897 proto.createdCallback = function() {
890 this.setAttribute('type', 'application/browser-plugin'); 898 this.setAttribute('type', 'application/browser-plugin');
891 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); 899 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId());
892 // The <object> node fills in the <webview> container. 900 // The <object> node fills in the <webview> container.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 1046
1039 /** 1047 /**
1040 * Implemented when the experimental API is available. 1048 * Implemented when the experimental API is available.
1041 * @private 1049 * @private
1042 */ 1050 */
1043 WebViewInternal.prototype.setupExperimentalContextMenus = function() { 1051 WebViewInternal.prototype.setupExperimentalContextMenus = function() {
1044 }; 1052 };
1045 1053
1046 exports.WebView = WebView; 1054 exports.WebView = WebView;
1047 exports.WebViewInternal = WebViewInternal; 1055 exports.WebViewInternal = WebViewInternal;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698