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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // Implemented when the experimental API is available. | 81 // Implemented when the experimental API is available. |
82 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {} | 82 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {} |
83 | 83 |
84 /** | 84 /** |
85 * @constructor | 85 * @constructor |
86 */ | 86 */ |
87 function WebViewInternal(webviewNode) { | 87 function WebViewInternal(webviewNode) { |
88 privates(webviewNode).internal = this; | 88 privates(webviewNode).internal = this; |
89 this.webviewNode = webviewNode; | 89 this.webviewNode = webviewNode; |
90 this.attached = false; | 90 this.attached = false; |
| 91 this.elementAttached = false; |
91 | 92 |
92 this.beforeFirstNavigation = true; | 93 this.beforeFirstNavigation = true; |
93 this.validPartitionId = true; | 94 this.validPartitionId = true; |
94 // Used to save some state upon deferred attachment. | 95 // Used to save some state upon deferred attachment. |
95 // If <object> bindings is not available, we defer attachment. | 96 // If <object> bindings is not available, we defer attachment. |
96 // This state contains whether or not the attachment request was for | 97 // This state contains whether or not the attachment request was for |
97 // newwindow. | 98 // newwindow. |
98 this.deferredAttachState = null; | 99 this.deferredAttachState = null; |
99 | 100 |
100 // on* Event handlers. | 101 // on* Event handlers. |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 if (!this.partition.validPartitionId) { | 620 if (!this.partition.validPartitionId) { |
620 result.error = ERROR_MSG_INVALID_PARTITION_ATTRIBUTE; | 621 result.error = ERROR_MSG_INVALID_PARTITION_ATTRIBUTE; |
621 return false; | 622 return false; |
622 } | 623 } |
623 this.src = this.webviewNode.getAttribute('src'); | 624 this.src = this.webviewNode.getAttribute('src'); |
624 | 625 |
625 if (!this.src) { | 626 if (!this.src) { |
626 return true; | 627 return true; |
627 } | 628 } |
628 | 629 |
| 630 if (!this.elementAttached) { |
| 631 return true; |
| 632 } |
| 633 |
629 if (!this.hasGuestInstanceID()) { | 634 if (!this.hasGuestInstanceID()) { |
630 if (this.beforeFirstNavigation) { | 635 if (this.beforeFirstNavigation) { |
631 this.beforeFirstNavigation = false; | 636 this.beforeFirstNavigation = false; |
632 this.allocateInstanceId(); | 637 this.allocateInstanceId(); |
633 } | 638 } |
634 return true; | 639 return true; |
635 } | 640 } |
636 | 641 |
637 // Navigate to this.src. | 642 // Navigate to this.src. |
638 WebView.navigate(this.instanceId, this.src); | 643 WebView.navigate(this.instanceId, this.src); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 } | 851 } |
847 | 852 |
848 // Registers <webview> custom element. | 853 // Registers <webview> custom element. |
849 function registerWebViewElement() { | 854 function registerWebViewElement() { |
850 var proto = Object.create(HTMLElement.prototype); | 855 var proto = Object.create(HTMLElement.prototype); |
851 | 856 |
852 proto.createdCallback = function() { | 857 proto.createdCallback = function() { |
853 new WebViewInternal(this); | 858 new WebViewInternal(this); |
854 }; | 859 }; |
855 | 860 |
856 proto.customElementDetached = false; | |
857 | |
858 proto.attributeChangedCallback = function(name, oldValue, newValue) { | 861 proto.attributeChangedCallback = function(name, oldValue, newValue) { |
859 var internal = privates(this).internal; | 862 var internal = privates(this).internal; |
860 if (!internal) { | 863 if (!internal) { |
861 return; | 864 return; |
862 } | 865 } |
863 internal.handleWebviewAttributeMutation(name, oldValue, newValue); | 866 internal.handleWebviewAttributeMutation(name, oldValue, newValue); |
864 }; | 867 }; |
865 | 868 |
866 proto.detachedCallback = function() { | 869 proto.detachedCallback = function() { |
867 this.customElementDetached = true; | 870 var internal = privates(this).internal; |
| 871 if (!internal) { |
| 872 return; |
| 873 } |
| 874 internal.elementAttached = false; |
868 }; | 875 }; |
869 | 876 |
870 proto.attachedCallback = function() { | 877 proto.attachedCallback = function() { |
871 if (this.customElementDetached) { | 878 var internal = privates(this).internal; |
872 var webViewInternal = privates(this).internal; | 879 if (!internal) { |
873 webViewInternal.resetUponReattachment(); | 880 return; |
874 webViewInternal.allocateInstanceId(); | |
875 } | 881 } |
876 this.customElementDetached = false; | 882 if (!internal.elementAttached) { |
| 883 internal.elementAttached = true; |
| 884 internal.resetUponReattachment(); |
| 885 internal.parseAttributes(); |
| 886 } |
877 }; | 887 }; |
878 | 888 |
879 var methods = [ | 889 var methods = [ |
880 'back', | 890 'back', |
881 'find', | 891 'find', |
882 'forward', | 892 'forward', |
883 'canGoBack', | 893 'canGoBack', |
884 'canGoForward', | 894 'canGoForward', |
885 'clearData', | 895 'clearData', |
886 'getProcessId', | 896 'getProcessId', |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 }; | 972 }; |
963 | 973 |
964 /** | 974 /** |
965 * Implemented when the experimental API is available. | 975 * Implemented when the experimental API is available. |
966 * @private | 976 * @private |
967 */ | 977 */ |
968 WebViewInternal.prototype.setupExperimentalContextMenus = function() {}; | 978 WebViewInternal.prototype.setupExperimentalContextMenus = function() {}; |
969 | 979 |
970 exports.WebView = WebView; | 980 exports.WebView = WebView; |
971 exports.WebViewInternal = WebViewInternal; | 981 exports.WebViewInternal = WebViewInternal; |
OLD | NEW |