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

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: Make <webview> work without --site-per-process as well 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 25
21 this.setupElementProperties(); 26 this.setupElementProperties();
22 new WebViewEvents(this, this.viewInstanceId); 27 new WebViewEvents(this, this.viewInstanceId);
23 } 28 }
24 29
25 WebViewImpl.prototype.__proto__ = GuestViewContainer.prototype; 30 WebViewImpl.prototype.__proto__ = GuestViewContainer.prototype;
26 31
(...skipping 25 matching lines...) Expand all
52 // Forward proto.foo* method calls to WebViewImpl.foo*. 57 // Forward proto.foo* method calls to WebViewImpl.foo*.
53 GuestViewContainer.forwardApiMethods(proto, apiMethods); 58 GuestViewContainer.forwardApiMethods(proto, apiMethods);
54 }; 59 };
55 60
56 // Initiates navigation once the <webview> element is attached to the DOM. 61 // Initiates navigation once the <webview> element is attached to the DOM.
57 WebViewImpl.prototype.onElementAttached = function() { 62 WebViewImpl.prototype.onElementAttached = function() {
58 // Mark all attributes as dirty on attachment. 63 // Mark all attributes as dirty on attachment.
59 for (var i in this.attributes) { 64 for (var i in this.attributes) {
60 this.attributes[i].dirty = true; 65 this.attributes[i].dirty = true;
61 } 66 }
67 // FIXME: Not sure about this one.
62 for (var i in this.attributes) { 68 for (var i in this.attributes) {
63 this.attributes[i].attach(); 69 this.attributes[i].attach();
64 } 70 }
65 }; 71 };
66 72
67 // Resets some state upon detaching <webview> element from the DOM. 73 // Resets some state upon detaching <webview> element from the DOM.
68 WebViewImpl.prototype.onElementDetached = function() { 74 WebViewImpl.prototype.onElementDetached = function() {
69 this.guest.destroy(); 75 this.guest.destroy();
70 for (var i in this.attributes) { 76 for (var i in this.attributes) {
71 this.attributes[i].dirty = false; 77 this.attributes[i].dirty = false;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // If |opt_guestInstanceId| was provided, then a different existing guest is 187 // If |opt_guestInstanceId| was provided, then a different existing guest is
182 // being attached to this webview, and the current one will get destroyed. 188 // being attached to this webview, and the current one will get destroyed.
183 if (opt_guestInstanceId) { 189 if (opt_guestInstanceId) {
184 if (this.guest.getId() == opt_guestInstanceId) { 190 if (this.guest.getId() == opt_guestInstanceId) {
185 return true; 191 return true;
186 } 192 }
187 this.guest.destroy(); 193 this.guest.destroy();
188 this.guest = new GuestView('webview', opt_guestInstanceId); 194 this.guest = new GuestView('webview', opt_guestInstanceId);
189 } 195 }
190 196
197 if (GuestViewInternalNatives.IsSitePerProcess()) {
198 return this.attachForSitePerProcess();
199 }
200
201 if (!this.internalInstanceId) {
202 return true;
203 }
204
191 return GuestViewContainer.prototype.attachWindow.call(this); 205 return GuestViewContainer.prototype.attachWindow.call(this);
192 }; 206 };
193 207
208 WebViewImpl.prototype.attachForSitePerProcess = function() {
209 LOG('Guest will start attach');
210 var generatedId = IdGenerator.GetNextId();
211 this.internalInstanceId = generatedId;
212
213 LOG('this.guest.getId() = ' + this.guest.getId());
214 window.console.log(this.getBrowserPluginElement());
215 var ret = GuestViewInternalNatives.AttachIframeGuest(
216 this.internalInstanceId, this.guest.getId(),
217 this.getBrowserPluginElement(), function(contentWindow) {
218 LOG(contentWindow);
219 this.guest.setContentWindow(contentWindow);
220 }.bind(this));
221
222 LOG('guestViewInternalNatives.AttachIframeGuest status: ' + ret);
223
224 window.setTimeout(function() {
225 LOG('<webview>: navigate');
226 var src =
227 this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue();
228 WebViewInternal.navigate(
Fady Samuel 2015/04/28 17:56:11 This breaks webview expectations now. What happene
229 this.guest.getId(), src);
230 }.bind(this), 0);
231
232 return true;
233 };
234
194 // Shared implementation of executeScript() and insertCSS(). 235 // Shared implementation of executeScript() and insertCSS().
195 WebViewImpl.prototype.executeCode = function(func, args) { 236 WebViewImpl.prototype.executeCode = function(func, args) {
196 if (!this.guest.getId()) { 237 if (!this.guest.getId()) {
197 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); 238 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT);
198 return false; 239 return false;
199 } 240 }
200 241
201 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); 242 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue();
202 if (this.baseUrlForDataUrl) { 243 if (this.baseUrlForDataUrl) {
203 webviewSrc = this.baseUrlForDataUrl; 244 webviewSrc = this.baseUrlForDataUrl;
(...skipping 12 matching lines...) Expand all
216 }.bind(this)); 257 }.bind(this));
217 }; 258 };
218 259
219 // Implemented when the ChromeWebView API is available. 260 // Implemented when the ChromeWebView API is available.
220 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; 261 WebViewImpl.prototype.maybeSetupContextMenus = function() {};
221 262
222 GuestViewContainer.registerElement(WebViewImpl); 263 GuestViewContainer.registerElement(WebViewImpl);
223 264
224 // Exports. 265 // Exports.
225 exports.WebViewImpl = WebViewImpl; 266 exports.WebViewImpl = WebViewImpl;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698