Chromium Code Reviews| 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 WebViewConstants = require('webViewConstants').WebViewConstants; | 12 var WebViewConstants = require('webViewConstants').WebViewConstants; |
| 13 var WebViewEvents = require('webViewEvents').WebViewEvents; | 13 var WebViewEvents = require('webViewEvents').WebViewEvents; |
| 14 var WebViewInternal = require('webViewInternal').WebViewInternal; | 14 var WebViewInternal = require('webViewInternal').WebViewInternal; |
| 15 | 15 |
| 16 var IdGenerator = requireNative('id_generator'); | |
| 17 var GuestViewInternalNatives = requireNative('guest_view_internal'); | |
| 18 | |
| 19 var LOG = function(msg) { window.console.log(msg); }; | |
| 20 | |
| 16 // Represents the internal state of <webview>. | 21 // Represents the internal state of <webview>. |
| 17 function WebViewImpl(webviewElement) { | 22 function WebViewImpl(webviewElement) { |
| 18 GuestViewContainer.call(this, webviewElement, 'webview'); | 23 GuestViewContainer.call(this, webviewElement, 'webview'); |
| 19 | 24 |
| 20 this.setupWebViewAttributes(); | 25 this.setupWebViewAttributes(); |
| 21 this.setupElementProperties(); | 26 this.setupElementProperties(); |
| 22 | 27 |
| 23 // on* Event handlers. | 28 // on* Event handlers. |
| 24 this.on = {}; | 29 this.on = {}; |
| 25 new WebViewEvents(this, this.viewInstanceId); | 30 new WebViewEvents(this, this.viewInstanceId); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 56 createDefaultApiMethod(apiMethods[i]); | 61 createDefaultApiMethod(apiMethods[i]); |
| 57 } | 62 } |
| 58 } | 63 } |
| 59 | 64 |
| 60 // Forward proto.foo* method calls to WebViewImpl.foo*. | 65 // Forward proto.foo* method calls to WebViewImpl.foo*. |
| 61 GuestViewContainer.forwardApiMethods(proto, apiMethods); | 66 GuestViewContainer.forwardApiMethods(proto, apiMethods); |
| 62 }; | 67 }; |
| 63 | 68 |
| 64 // Initiates navigation once the <webview> element is attached to the DOM. | 69 // Initiates navigation once the <webview> element is attached to the DOM. |
| 65 WebViewImpl.prototype.onElementAttached = function() { | 70 WebViewImpl.prototype.onElementAttached = function() { |
| 71 // FIXME: Not sure about this one. | |
| 66 this.attributes[WebViewConstants.ATTRIBUTE_SRC].parse(); | 72 this.attributes[WebViewConstants.ATTRIBUTE_SRC].parse(); |
|
Fady Samuel
2015/03/04 20:44:48
This code is old. What's the problem here?
| |
| 67 }; | 73 }; |
| 68 | 74 |
| 69 // Resets some state upon detaching <webview> element from the DOM. | 75 // Resets some state upon detaching <webview> element from the DOM. |
| 70 WebViewImpl.prototype.onElementDetached = function() { | 76 WebViewImpl.prototype.onElementDetached = function() { |
| 71 this.guest.destroy(); | 77 this.guest.destroy(); |
| 72 for (var i in this.attributes) { | 78 for (var i in this.attributes) { |
| 73 this.attributes[i].reset(); | 79 this.attributes[i].reset(); |
| 74 } | 80 } |
| 75 }; | 81 }; |
| 76 | 82 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 | 195 |
| 190 // Updates state upon loadcommit. | 196 // Updates state upon loadcommit. |
| 191 WebViewImpl.prototype.onLoadCommit = function( | 197 WebViewImpl.prototype.onLoadCommit = function( |
| 192 baseUrlForDataUrl, currentEntryIndex, entryCount, | 198 baseUrlForDataUrl, currentEntryIndex, entryCount, |
| 193 processId, url, isTopLevel) { | 199 processId, url, isTopLevel) { |
| 194 this.baseUrlForDataUrl = baseUrlForDataUrl; | 200 this.baseUrlForDataUrl = baseUrlForDataUrl; |
| 195 this.currentEntryIndex = currentEntryIndex; | 201 this.currentEntryIndex = currentEntryIndex; |
| 196 this.entryCount = entryCount; | 202 this.entryCount = entryCount; |
| 197 this.processId = processId; | 203 this.processId = processId; |
| 198 var oldValue = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); | 204 var oldValue = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
| 205 LOG('WebViewImpl.onLoadCommit, oldValue = ' + oldValue + | |
| 206 ', newValue = ' + newValue); | |
| 199 var newValue = url; | 207 var newValue = url; |
| 200 if (isTopLevel && (oldValue != newValue)) { | 208 if (isTopLevel && (oldValue != newValue)) { |
| 201 // Touching the src attribute triggers a navigation. To avoid | 209 // Touching the src attribute triggers a navigation. To avoid |
| 202 // triggering a page reload on every guest-initiated navigation, | 210 // triggering a page reload on every guest-initiated navigation, |
| 203 // we do not handle this mutation. | 211 // we do not handle this mutation. |
| 204 this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation( | 212 this.attributes[WebViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation( |
| 205 newValue); | 213 newValue); |
| 206 } | 214 } |
| 207 }; | 215 }; |
| 208 | 216 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 223 // If |opt_guestInstanceId| was provided, then a different existing guest is | 231 // If |opt_guestInstanceId| was provided, then a different existing guest is |
| 224 // being attached to this webview, and the current one will get destroyed. | 232 // being attached to this webview, and the current one will get destroyed. |
| 225 if (opt_guestInstanceId) { | 233 if (opt_guestInstanceId) { |
| 226 if (this.guest.getId() == opt_guestInstanceId) { | 234 if (this.guest.getId() == opt_guestInstanceId) { |
| 227 return true; | 235 return true; |
| 228 } | 236 } |
| 229 this.guest.destroy(); | 237 this.guest.destroy(); |
| 230 this.guest = new GuestView('webview', opt_guestInstanceId); | 238 this.guest = new GuestView('webview', opt_guestInstanceId); |
| 231 } | 239 } |
| 232 | 240 |
| 241 /* | |
| 242 if (!this.internalInstanceId) { | |
| 243 return true; | |
| 244 } | |
| 245 */ | |
| 246 | |
| 247 LOG('Guest will start attach'); | |
| 248 var generatedId = IdGenerator.GetNextId(); | |
| 249 this.internalInstanceId = generatedId; | |
| 250 | |
| 251 LOG('this.guest.getId() = ' + this.guest.getId()); | |
| 252 var ret = GuestViewInternalNatives.AttachIframeGuest( | |
| 253 this.internalInstanceId, this.guest.getId(), | |
| 254 this.getBrowserPluginElement(), function(contentWindow) { | |
| 255 LOG(contentWindow); | |
| 256 this.guest.setContentWindow(contentWindow); | |
| 257 }.bind(this)); | |
| 258 | |
| 259 LOG('guestViewInternalNatives.AttachIframeGuest status: ' + ret); | |
| 260 | |
| 261 window.setTimeout(function() { | |
| 262 LOG('<webview>: navigate'); | |
| 263 var src = | |
| 264 this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); | |
| 265 WebViewInternal.navigate( | |
| 266 this.guest.getId(), src); | |
|
Fady Samuel
2015/03/04 20:44:48
This totally breaks the new window API.
| |
| 267 }.bind(this), 0); | |
| 268 | |
| 269 return true; | |
| 270 // Note: Following stuff IGNORED. | |
| 233 return GuestViewContainer.prototype.attachWindow.call(this); | 271 return GuestViewContainer.prototype.attachWindow.call(this); |
| 234 }; | 272 }; |
| 235 | 273 |
| 236 // Shared implementation of executeScript() and insertCSS(). | 274 // Shared implementation of executeScript() and insertCSS(). |
| 237 WebViewImpl.prototype.executeCode = function(func, args) { | 275 WebViewImpl.prototype.executeCode = function(func, args) { |
| 238 if (!this.guest.getId()) { | 276 if (!this.guest.getId()) { |
| 239 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); | 277 window.console.error(WebViewConstants.ERROR_MSG_CANNOT_INJECT_SCRIPT); |
| 240 return false; | 278 return false; |
| 241 } | 279 } |
| 242 | 280 |
| 243 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); | 281 var webviewSrc = this.attributes[WebViewConstants.ATTRIBUTE_SRC].getValue(); |
| 244 if (this.baseUrlForDataUrl != '') { | 282 if (this.baseUrlForDataUrl != '') { |
| 245 webviewSrc = this.baseUrlForDataUrl; | 283 webviewSrc = this.baseUrlForDataUrl; |
| 246 } | 284 } |
| 285 LOG('webviewSrc: ' + webviewSrc); | |
| 247 | 286 |
| 248 args = $Array.concat([this.guest.getId(), webviewSrc], | 287 args = $Array.concat([this.guest.getId(), webviewSrc], |
| 249 $Array.slice(args)); | 288 $Array.slice(args)); |
| 250 $Function.apply(func, null, args); | 289 $Function.apply(func, null, args); |
| 251 return true; | 290 return true; |
| 252 } | 291 } |
| 253 | 292 |
| 254 // Implemented when the ChromeWebView API is available. | 293 // Implemented when the ChromeWebView API is available. |
| 255 WebViewImpl.prototype.maybeGetChromeWebViewEvents = function() {}; | 294 WebViewImpl.prototype.maybeGetChromeWebViewEvents = function() {}; |
| 256 | 295 |
| 257 // Implemented when the experimental WebView API is available. | 296 // Implemented when the experimental WebView API is available. |
| 258 WebViewImpl.maybeGetExperimentalApiMethods = function() { return []; }; | 297 WebViewImpl.maybeGetExperimentalApiMethods = function() { return []; }; |
| 259 WebViewImpl.prototype.setupExperimentalContextMenus = function() {}; | 298 WebViewImpl.prototype.setupExperimentalContextMenus = function() {}; |
| 260 WebViewImpl.prototype.maybeSetupExperimentalChromeWebViewEvents = | 299 WebViewImpl.prototype.maybeSetupExperimentalChromeWebViewEvents = |
| 261 function(request) { | 300 function(request) { |
| 262 return request; | 301 return request; |
| 263 }; | 302 }; |
| 264 | 303 |
| 265 GuestViewContainer.registerElement(WebViewImpl); | 304 GuestViewContainer.registerElement(WebViewImpl); |
| 266 | 305 |
| 267 // Exports. | 306 // Exports. |
| 268 exports.WebViewImpl = WebViewImpl; | 307 exports.WebViewImpl = WebViewImpl; |
| OLD | NEW |