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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // If |opt_guestInstanceId| was provided, then a different existing guest is | 191 // If |opt_guestInstanceId| was provided, then a different existing guest is |
186 // being attached to this webview, and the current one will get destroyed. | 192 // being attached to this webview, and the current one will get destroyed. |
187 if (opt_guestInstanceId) { | 193 if (opt_guestInstanceId) { |
188 if (this.guest.getId() == opt_guestInstanceId) { | 194 if (this.guest.getId() == opt_guestInstanceId) { |
189 return true; | 195 return true; |
190 } | 196 } |
191 this.guest.destroy(); | 197 this.guest.destroy(); |
192 this.guest = new GuestView('webview', opt_guestInstanceId); | 198 this.guest = new GuestView('webview', opt_guestInstanceId); |
193 } | 199 } |
194 | 200 |
| 201 /* |
| 202 if (!this.internalInstanceId) { |
| 203 return true; |
| 204 } |
| 205 */ |
| 206 |
| 207 LOG('Guest will start attach'); |
| 208 var generatedId = IdGenerator.GetNextId(); |
| 209 this.internalInstanceId = generatedId; |
| 210 |
| 211 LOG('this.guest.getId() = ' + this.guest.getId()); |
| 212 window.console.log(this.getBrowserPluginElement()); |
| 213 var ret = GuestViewInternalNatives.AttachIframeGuest( |
| 214 this.internalInstanceId, this.guest.getId(), |
| 215 this.getBrowserPluginElement(), function(contentWindow) { |
| 216 LOG(contentWindow); |
| 217 this.guest.setContentWindow(contentWindow); |
| 218 }.bind(this)); |
| 219 |
| 220 LOG('guestViewInternalNatives.AttachIframeGuest status: ' + ret); |
| 221 |
| 222 window.setTimeout(function() { |
| 223 LOG('<webview>: navigate'); |
| 224 var src = |
| 225 this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
| 226 WebViewInternal.navigate( |
| 227 this.guest.getId(), src); |
| 228 }.bind(this), 0); |
| 229 |
| 230 return true; |
| 231 // Note: Following stuff IGNORED. |
195 return GuestViewContainer.prototype.attachWindow.call(this); | 232 return GuestViewContainer.prototype.attachWindow.call(this); |
196 }; | 233 }; |
197 | 234 |
198 // Shared implementation of executeScript() and insertCSS(). | 235 // Shared implementation of executeScript() and insertCSS(). |
199 WebViewImpl.prototype.executeCode = function(func, args) { | 236 WebViewImpl.prototype.executeCode = function(func, args) { |
200 if (!this.guest.getId()) { | 237 if (!this.guest.getId()) { |
201 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); | 238 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); |
202 return false; | 239 return false; |
203 } | 240 } |
204 | 241 |
(...skipping 15 matching lines...) Expand all Loading... |
220 }.bind(this)); | 257 }.bind(this)); |
221 }; | 258 }; |
222 | 259 |
223 // Implemented when the ChromeWebView API is available. | 260 // Implemented when the ChromeWebView API is available. |
224 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; | 261 WebViewImpl.prototype.maybeSetupContextMenus = function() {}; |
225 | 262 |
226 GuestViewContainer.registerElement(WebViewImpl); | 263 GuestViewContainer.registerElement(WebViewImpl); |
227 | 264 |
228 // Exports. | 265 // Exports. |
229 exports.WebViewImpl = WebViewImpl; | 266 exports.WebViewImpl = WebViewImpl; |
OLD | NEW |