| 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 | 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 Loading... |
| 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 Loading... |
| 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().contentWindow, function() { |
| 218 // TODO(lazyboy): Once http://crbug.com/480676 is fixed, we won't need |
| 219 // to set contentWindow in callback, we can use <webview>.contentWindow |
| 220 // to point to <iframe>.contentWindow right after creation. |
| 221 var frameContentWindow = this.getBrowserPluginElement().contentWindow; |
| 222 this.guest.setContentWindow(frameContentWindow); |
| 223 }.bind(this)); |
| 224 |
| 225 LOG('guestViewInternalNatives.AttachIframeGuest status: ' + ret); |
| 226 |
| 227 window.setTimeout(function() { |
| 228 LOG('<webview>: navigate'); |
| 229 var src = |
| 230 this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
| 231 WebViewInternal.navigate( |
| 232 this.guest.getId(), src); |
| 233 }.bind(this), 0); |
| 234 |
| 235 return true; |
| 236 }; |
| 237 |
| 194 // Shared implementation of executeScript() and insertCSS(). | 238 // Shared implementation of executeScript() and insertCSS(). |
| 195 WebViewImpl.prototype.executeCode = function(func, args) { | 239 WebViewImpl.prototype.executeCode = function(func, args) { |
| 196 if (!this.guest.getId()) { | 240 if (!this.guest.getId()) { |
| 197 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); | 241 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); |
| 198 return false; | 242 return false; |
| 199 } | 243 } |
| 200 | 244 |
| 201 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); | 245 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
| 202 if (this.baseUrlForDataUrl) { | 246 if (this.baseUrlForDataUrl) { |
| 203 webviewSrc = this.baseUrlForDataUrl; | 247 webviewSrc = this.baseUrlForDataUrl; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 216 }.bind(this)); | 260 }.bind(this)); |
| 217 }; | 261 }; |
| 218 | 262 |
| 219 // Implemented when the ChromeWebView API is available. | 263 // Implemented when the ChromeWebView API is available. |
| 220 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; | 264 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; |
| 221 | 265 |
| 222 GuestViewContainer.registerElement(WebViewImpl); | 266 GuestViewContainer.registerElement(WebViewImpl); |
| 223 | 267 |
| 224 // Exports. | 268 // Exports. |
| 225 exports.WebViewImpl = WebViewImpl; | 269 exports.WebViewImpl = WebViewImpl; |
| OLD | NEW |