OLD | NEW |
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 enumerable: true | 91 enumerable: true |
86 } | 92 } |
87 ); | 93 ); |
88 }; | 94 }; |
89 | 95 |
90 WebViewImpl.prototype.setupElementProperties = function() { | 96 WebViewImpl.prototype.setupElementProperties = function() { |
91 // We cannot use {writable: true} property descriptor because we want a | 97 // We cannot use {writable: true} property descriptor because we want a |
92 // dynamic getter value. | 98 // dynamic getter value. |
93 Object.defineProperty(this.element, 'contentWindow', { | 99 Object.defineProperty(this.element, 'contentWindow', { |
94 get: function() { | 100 get: function() { |
95 return this.guest.getContentWindow(); | 101 if (this.isSitePerProcess) { |
| 102 return this.getBrowserPluginElement().contentWindow; |
| 103 } else { |
| 104 return this.guest.getContentWindow(); |
| 105 } |
96 }.bind(this), | 106 }.bind(this), |
97 // No setter. | 107 // No setter. |
98 enumerable: true | 108 enumerable: true |
99 }); | 109 }); |
100 }; | 110 }; |
101 | 111 |
102 WebViewImpl.prototype.onSizeChanged = function(webViewEvent) { | 112 WebViewImpl.prototype.onSizeChanged = function(webViewEvent) { |
103 var newWidth = webViewEvent.newWidth; | 113 var newWidth = webViewEvent.newWidth; |
104 var newHeight = webViewEvent.newHeight; | 114 var newHeight = webViewEvent.newHeight; |
105 | 115 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // If |opt_guestInstanceId| was provided, then a different existing guest is | 192 // If |opt_guestInstanceId| was provided, then a different existing guest is |
183 // being attached to this webview, and the current one will get destroyed. | 193 // being attached to this webview, and the current one will get destroyed. |
184 if (opt_guestInstanceId) { | 194 if (opt_guestInstanceId) { |
185 if (this.guest.getId() == opt_guestInstanceId) { | 195 if (this.guest.getId() == opt_guestInstanceId) { |
186 return true; | 196 return true; |
187 } | 197 } |
188 this.guest.destroy(); | 198 this.guest.destroy(); |
189 this.guest = new GuestView('webview', opt_guestInstanceId); | 199 this.guest = new GuestView('webview', opt_guestInstanceId); |
190 } | 200 } |
191 | 201 |
| 202 if (this.isSitePerProcess) { |
| 203 var generatedID = IdGenerator.GetNextId(); |
| 204 this.onInternalInstanceID(generatedID); |
| 205 return true; |
| 206 } |
| 207 |
192 return GuestViewContainer.prototype.attachWindow.call(this); | 208 return GuestViewContainer.prototype.attachWindow.call(this); |
193 }; | 209 }; |
194 | 210 |
195 // Shared implementation of executeScript() and insertCSS(). | 211 // Shared implementation of executeScript() and insertCSS(). |
196 WebViewImpl.prototype.executeCode = function(func, args) { | 212 WebViewImpl.prototype.executeCode = function(func, args) { |
197 if (!this.guest.getId()) { | 213 if (!this.guest.getId()) { |
198 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); | 214 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); |
199 return false; | 215 return false; |
200 } | 216 } |
201 | 217 |
(...skipping 15 matching lines...) Expand all Loading... |
217 }.bind(this)); | 233 }.bind(this)); |
218 }; | 234 }; |
219 | 235 |
220 // Implemented when the ChromeWebView API is available. | 236 // Implemented when the ChromeWebView API is available. |
221 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; | 237 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; |
222 | 238 |
223 GuestViewContainer.registerElement(WebViewImpl); | 239 GuestViewContainer.registerElement(WebViewImpl); |
224 | 240 |
225 // Exports. | 241 // Exports. |
226 exports.WebViewImpl = WebViewImpl; | 242 exports.WebViewImpl = WebViewImpl; |
OLD | NEW |