| 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 GuestViewInternal = | 10 var GuestViewInternal = |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 /** | 87 /** |
| 88 * @constructor | 88 * @constructor |
| 89 */ | 89 */ |
| 90 function WebViewInternal(webviewNode) { | 90 function WebViewInternal(webviewNode) { |
| 91 privates(webviewNode).internal = this; | 91 privates(webviewNode).internal = this; |
| 92 this.webviewNode = webviewNode; | 92 this.webviewNode = webviewNode; |
| 93 this.attached = false; | 93 this.attached = false; |
| 94 this.elementAttached = false; | 94 this.elementAttached = false; |
| 95 | 95 |
| 96 this.beforeFirstNavigation = true; | 96 this.beforeFirstNavigation = true; |
| 97 this.contentWindow = null; |
| 97 this.validPartitionId = true; | 98 this.validPartitionId = true; |
| 98 // Used to save some state upon deferred attachment. | 99 // Used to save some state upon deferred attachment. |
| 99 // If <object> bindings is not available, we defer attachment. | 100 // If <object> bindings is not available, we defer attachment. |
| 100 // This state contains whether or not the attachment request was for | 101 // This state contains whether or not the attachment request was for |
| 101 // newwindow. | 102 // newwindow. |
| 102 this.deferredAttachState = null; | 103 this.deferredAttachState = null; |
| 103 | 104 |
| 104 // on* Event handlers. | 105 // on* Event handlers. |
| 105 this.on = {}; | 106 this.on = {}; |
| 106 | 107 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // already picked up a partition ID. Thus, we need to reset the initialization | 160 // already picked up a partition ID. Thus, we need to reset the initialization |
| 160 // state. However, it may be the case that beforeFirstNavigation is false BUT | 161 // state. However, it may be the case that beforeFirstNavigation is false BUT |
| 161 // guestInstanceId has yet to be initialized. This means that we have not | 162 // guestInstanceId has yet to be initialized. This means that we have not |
| 162 // heard back from createGuest yet. We will not reset the flag in this case so | 163 // heard back from createGuest yet. We will not reset the flag in this case so |
| 163 // that we don't end up allocating a second guest. | 164 // that we don't end up allocating a second guest. |
| 164 if (this.guestInstanceId) { | 165 if (this.guestInstanceId) { |
| 165 this.guestInstanceId = undefined; | 166 this.guestInstanceId = undefined; |
| 166 this.beforeFirstNavigation = true; | 167 this.beforeFirstNavigation = true; |
| 167 this.validPartitionId = true; | 168 this.validPartitionId = true; |
| 168 this.partition.validPartitionId = true; | 169 this.partition.validPartitionId = true; |
| 170 this.contentWindow = null; |
| 169 } | 171 } |
| 170 this.internalInstanceId = 0; | 172 this.internalInstanceId = 0; |
| 171 }; | 173 }; |
| 172 | 174 |
| 173 // Sets <webview>.request property. | 175 // Sets <webview>.request property. |
| 174 WebViewInternal.prototype.setRequestPropertyOnWebViewNode = function(request) { | 176 WebViewInternal.prototype.setRequestPropertyOnWebViewNode = function(request) { |
| 175 Object.defineProperty( | 177 Object.defineProperty( |
| 176 this.webviewNode, | 178 this.webviewNode, |
| 177 'request', | 179 'request', |
| 178 { | 180 { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 } | 414 } |
| 413 self.webviewNode.setAttribute('partition', value); | 415 self.webviewNode.setAttribute('partition', value); |
| 414 }, | 416 }, |
| 415 enumerable: true | 417 enumerable: true |
| 416 }); | 418 }); |
| 417 | 419 |
| 418 // We cannot use {writable: true} property descriptor because we want a | 420 // We cannot use {writable: true} property descriptor because we want a |
| 419 // dynamic getter value. | 421 // dynamic getter value. |
| 420 Object.defineProperty(this.webviewNode, 'contentWindow', { | 422 Object.defineProperty(this.webviewNode, 'contentWindow', { |
| 421 get: function() { | 423 get: function() { |
| 422 if (browserPluginNode.contentWindow) | 424 if (this.contentWindow) { |
| 423 return browserPluginNode.contentWindow; | 425 return this.contentWindow; |
| 426 } |
| 424 window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); | 427 window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); |
| 425 }, | 428 }.bind(this), |
| 426 // No setter. | 429 // No setter. |
| 427 enumerable: true | 430 enumerable: true |
| 428 }); | 431 }); |
| 429 }; | 432 }; |
| 430 | 433 |
| 431 /** | 434 /** |
| 432 * @private | 435 * @private |
| 433 */ | 436 */ |
| 434 WebViewInternal.prototype.setupWebviewNodeAttributes = function() { | 437 WebViewInternal.prototype.setupWebviewNodeAttributes = function() { |
| 435 this.setupWebViewSrcAttributeMutationObserver(); | 438 this.setupWebViewSrcAttributeMutationObserver(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 } | 571 } |
| 569 | 572 |
| 570 if (!!this.guestInstanceId && this.guestInstanceId != 0) { | 573 if (!!this.guestInstanceId && this.guestInstanceId != 0) { |
| 571 window.setTimeout(function() { | 574 window.setTimeout(function() { |
| 572 var isNewWindow = this.deferredAttachState ? | 575 var isNewWindow = this.deferredAttachState ? |
| 573 this.deferredAttachState.isNewWindow : false; | 576 this.deferredAttachState.isNewWindow : false; |
| 574 var params = this.buildAttachParams(isNewWindow); | 577 var params = this.buildAttachParams(isNewWindow); |
| 575 guestViewInternalNatives.AttachGuest( | 578 guestViewInternalNatives.AttachGuest( |
| 576 this.internalInstanceId, | 579 this.internalInstanceId, |
| 577 this.guestInstanceId, | 580 this.guestInstanceId, |
| 578 params); | 581 params, |
| 582 function(w) { |
| 583 this.contentWindow = w; |
| 584 }.bind(this) |
| 585 ); |
| 579 }.bind(this), 0); | 586 }.bind(this), 0); |
| 580 } | 587 } |
| 581 | 588 |
| 582 return; | 589 return; |
| 583 } | 590 } |
| 584 | 591 |
| 585 // This observer monitors mutations to attributes of the BrowserPlugin and | 592 // This observer monitors mutations to attributes of the BrowserPlugin and |
| 586 // updates the <webview> attributes accordingly. | 593 // updates the <webview> attributes accordingly. |
| 587 // |newValue| is null if the attribute |name| has been removed. | 594 // |newValue| is null if the attribute |name| has been removed. |
| 588 if (newValue != null) { | 595 if (newValue != null) { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 | 879 |
| 873 if (!this.isPluginInRenderTree()) { | 880 if (!this.isPluginInRenderTree()) { |
| 874 this.deferredAttachState = {isNewWindow: isNewWindow}; | 881 this.deferredAttachState = {isNewWindow: isNewWindow}; |
| 875 return true; | 882 return true; |
| 876 } | 883 } |
| 877 | 884 |
| 878 this.deferredAttachState = null; | 885 this.deferredAttachState = null; |
| 879 return guestViewInternalNatives.AttachGuest( | 886 return guestViewInternalNatives.AttachGuest( |
| 880 this.internalInstanceId, | 887 this.internalInstanceId, |
| 881 this.guestInstanceId, | 888 this.guestInstanceId, |
| 882 params); | 889 params, function(w) { |
| 890 this.contentWindow = w; |
| 891 }.bind(this) |
| 892 ); |
| 883 }; | 893 }; |
| 884 | 894 |
| 885 // Registers browser plugin <object> custom element. | 895 // Registers browser plugin <object> custom element. |
| 886 function registerBrowserPluginElement() { | 896 function registerBrowserPluginElement() { |
| 887 var proto = Object.create(HTMLObjectElement.prototype); | 897 var proto = Object.create(HTMLObjectElement.prototype); |
| 888 | 898 |
| 889 proto.createdCallback = function() { | 899 proto.createdCallback = function() { |
| 890 this.setAttribute('type', 'application/browser-plugin'); | 900 this.setAttribute('type', 'application/browser-plugin'); |
| 891 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); | 901 this.setAttribute('id', 'browser-plugin-' + IdGenerator.GetNextId()); |
| 892 // The <object> node fills in the <webview> container. | 902 // The <object> node fills in the <webview> container. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 | 1048 |
| 1039 /** | 1049 /** |
| 1040 * Implemented when the experimental API is available. | 1050 * Implemented when the experimental API is available. |
| 1041 * @private | 1051 * @private |
| 1042 */ | 1052 */ |
| 1043 WebViewInternal.prototype.setupExperimentalContextMenus = function() { | 1053 WebViewInternal.prototype.setupExperimentalContextMenus = function() { |
| 1044 }; | 1054 }; |
| 1045 | 1055 |
| 1046 exports.WebView = WebView; | 1056 exports.WebView = WebView; |
| 1047 exports.WebViewInternal = WebViewInternal; | 1057 exports.WebViewInternal = WebViewInternal; |
| OLD | NEW |