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

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

Issue 972313002: Make <webview> use out-of-process iframe architecture. (Closed) Base URL: ssh://saopaulo.wat/mnt/dev/shared/src@testoopif2z-better-chrome
Patch Set: add basic postMessage test Created 5 years, 7 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 GuestView = require('guestView').GuestView; 10 var GuestView = require('guestView').GuestView;
11 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; 11 var GuestViewContainer = require('guestViewContainer').GuestViewContainer;
12 var GuestViewInternalNatives = requireNative('guest_view_internal'); 12 var GuestViewInternalNatives = requireNative('guest_view_internal');
13 var WebViewConstants = require('webViewConstants').WebViewConstants; 13 var WebViewConstants = require('webViewConstants').WebViewConstants;
14 var WebViewEvents = require('webViewEvents').WebViewEvents; 14 var WebViewEvents = require('webViewEvents').WebViewEvents;
15 var WebViewInternal = require('webViewInternal').WebViewInternal; 15 var WebViewInternal = require('webViewInternal').WebViewInternal;
16 16
17 var IdGenerator = requireNative('id_generator');
18 var GuestViewInternalNatives = requireNative('guest_view_internal');
19
20 var LOG = function(msg) { window.console.log(msg); };
21
17 // Represents the internal state of <webview>. 22 // Represents the internal state of <webview>.
18 function WebViewImpl(webviewElement) { 23 function WebViewImpl(webviewElement) {
19 GuestViewContainer.call(this, webviewElement, 'webview'); 24 GuestViewContainer.call(this, webviewElement, 'webview');
20 this.cachedZoom = 1; 25 this.cachedZoom = 1;
21 this.setupElementProperties(); 26 this.setupElementProperties();
27 this.isSitePerProcess = GuestViewInternalNatives.IsSitePerProcess();
22 new WebViewEvents(this, this.viewInstanceId); 28 new WebViewEvents(this, this.viewInstanceId);
23 } 29 }
24 30
25 WebViewImpl.prototype.__proto__ = GuestViewContainer.prototype; 31 WebViewImpl.prototype.__proto__ = GuestViewContainer.prototype;
26 32
27 WebViewImpl.VIEW_TYPE = 'WebView'; 33 WebViewImpl.VIEW_TYPE = 'WebView';
28 34
29 // Add extra functionality to |this.element|. 35 // Add extra functionality to |this.element|.
30 WebViewImpl.setupElement = function(proto) { 36 WebViewImpl.setupElement = function(proto) {
31 // Public-facing API methods. 37 // Public-facing API methods.
(...skipping 20 matching lines...) Expand all
52 // Forward proto.foo* method calls to WebViewImpl.foo*. 58 // Forward proto.foo* method calls to WebViewImpl.foo*.
53 GuestViewContainer.forwardApiMethods(proto, apiMethods); 59 GuestViewContainer.forwardApiMethods(proto, apiMethods);
54 }; 60 };
55 61
56 // Initiates navigation once the <webview> element is attached to the DOM. 62 // Initiates navigation once the <webview> element is attached to the DOM.
57 WebViewImpl.prototype.onElementAttached = function() { 63 WebViewImpl.prototype.onElementAttached = function() {
58 // Mark all attributes as dirty on attachment. 64 // Mark all attributes as dirty on attachment.
59 for (var i in this.attributes) { 65 for (var i in this.attributes) {
60 this.attributes[i].dirty = true; 66 this.attributes[i].dirty = true;
61 } 67 }
68 // FIXME: Not sure about this one.
62 for (var i in this.attributes) { 69 for (var i in this.attributes) {
63 this.attributes[i].attach(); 70 this.attributes[i].attach();
64 } 71 }
65 }; 72 };
66 73
67 // Resets some state upon detaching <webview> element from the DOM. 74 // Resets some state upon detaching <webview> element from the DOM.
68 WebViewImpl.prototype.onElementDetached = function() { 75 WebViewImpl.prototype.onElementDetached = function() {
69 this.guest.destroy(); 76 this.guest.destroy();
70 for (var i in this.attributes) { 77 for (var i in this.attributes) {
71 this.attributes[i].dirty = false; 78 this.attributes[i].dirty = false;
(...skipping 13 matching lines...) Expand all
85 enumerable: true 92 enumerable: true
86 } 93 }
87 ); 94 );
88 }; 95 };
89 96
90 WebViewImpl.prototype.setupElementProperties = function() { 97 WebViewImpl.prototype.setupElementProperties = function() {
91 // We cannot use {writable: true} property descriptor because we want a 98 // We cannot use {writable: true} property descriptor because we want a
92 // dynamic getter value. 99 // dynamic getter value.
93 Object.defineProperty(this.element, 'contentWindow', { 100 Object.defineProperty(this.element, 'contentWindow', {
94 get: function() { 101 get: function() {
95 return this.guest.getContentWindow(); 102 if (this.isSitePerProcess) {
103 return this.getBrowserPluginElement().contentWindow;
104 } else {
105 return this.guest.getContentWindow();
106 }
96 }.bind(this), 107 }.bind(this),
97 // No setter. 108 // No setter.
98 enumerable: true 109 enumerable: true
99 }); 110 });
100 }; 111 };
101 112
102 WebViewImpl.prototype.onSizeChanged = function(webViewEvent) { 113 WebViewImpl.prototype.onSizeChanged = function(webViewEvent) {
103 var newWidth = webViewEvent.newWidth; 114 var newWidth = webViewEvent.newWidth;
104 var newHeight = webViewEvent.newHeight; 115 var newHeight = webViewEvent.newHeight;
105 116
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // If |opt_guestInstanceId| was provided, then a different existing guest is 193 // If |opt_guestInstanceId| was provided, then a different existing guest is
183 // being attached to this webview, and the current one will get destroyed. 194 // being attached to this webview, and the current one will get destroyed.
184 if (opt_guestInstanceId) { 195 if (opt_guestInstanceId) {
185 if (this.guest.getId() == opt_guestInstanceId) { 196 if (this.guest.getId() == opt_guestInstanceId) {
186 return true; 197 return true;
187 } 198 }
188 this.guest.destroy(); 199 this.guest.destroy();
189 this.guest = new GuestView('webview', opt_guestInstanceId); 200 this.guest = new GuestView('webview', opt_guestInstanceId);
190 } 201 }
191 202
203 if (this.isSitePerProcess) {
204 return this.attachForSitePerProcess();
205 }
206
207 if (!this.internalInstanceId) {
208 return true;
209 }
210
192 return GuestViewContainer.prototype.attachWindow.call(this); 211 return GuestViewContainer.prototype.attachWindow.call(this);
193 }; 212 };
194 213
214 WebViewImpl.prototype.attachForSitePerProcess = function() {
215 LOG('Guest will start attach');
216 var generatedId = IdGenerator.GetNextId();
217 this.internalInstanceId = generatedId;
218
219 LOG('this.guest.getId() = ' + this.guest.getId());
220 window.console.log(this.getBrowserPluginElement());
221 var ret = GuestViewInternalNatives.AttachIframeGuest(
222 this.internalInstanceId, this.guest.getId(),
223 this.getBrowserPluginElement().contentWindow, function() {
224 // No need to set contentWindow, we will use <iframe>.contentWindow.
225 }.bind(this));
226
227 LOG('guestViewInternalNatives.AttachIframeGuest status: ' + ret);
228
229 window.setTimeout(function() {
230 LOG('<webview>: navigate');
231 var src =
232 this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue();
233 WebViewInternal.navigate(
234 this.guest.getId(), src);
235 }.bind(this), 0);
236
237 return true;
238 };
239
195 // Shared implementation of executeScript() and insertCSS(). 240 // Shared implementation of executeScript() and insertCSS().
196 WebViewImpl.prototype.executeCode = function(func, args) { 241 WebViewImpl.prototype.executeCode = function(func, args) {
197 if (!this.guest.getId()) { 242 if (!this.guest.getId()) {
198 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); 243 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT);
199 return false; 244 return false;
200 } 245 }
201 246
202 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); 247 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue();
203 if (this.baseUrlForDataUrl) { 248 if (this.baseUrlForDataUrl) {
204 webviewSrc = this.baseUrlForDataUrl; 249 webviewSrc = this.baseUrlForDataUrl;
(...skipping 12 matching lines...) Expand all
217 }.bind(this)); 262 }.bind(this));
218 }; 263 };
219 264
220 // Implemented when the ChromeWebView API is available. 265 // Implemented when the ChromeWebView API is available.
221 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; 266 WebViewImpl.prototype.maybeSetupContextMenus = function() {};
222 267
223 GuestViewContainer.registerElement(WebViewImpl); 268 GuestViewContainer.registerElement(WebViewImpl);
224 269
225 // Exports. 270 // Exports.
226 exports.WebViewImpl = WebViewImpl; 271 exports.WebViewImpl = WebViewImpl;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698