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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 // If <object> bindings is not available, we defer attachment. | 99 // If <object> bindings is not available, we defer attachment. |
100 // This state contains whether or not the attachment request was for | 100 // This state contains whether or not the attachment request was for |
101 // newwindow. | 101 // newwindow. |
102 this.deferredAttachState = null; | 102 this.deferredAttachState = null; |
103 | 103 |
104 // on* Event handlers. | 104 // on* Event handlers. |
105 this.on = {}; | 105 this.on = {}; |
106 | 106 |
107 this.browserPluginNode = this.createBrowserPluginNode(); | 107 this.browserPluginNode = this.createBrowserPluginNode(); |
108 var shadowRoot = this.webviewNode.createShadowRoot(); | 108 var shadowRoot = this.webviewNode.createShadowRoot(); |
109 shadowRoot.appendChild(this.browserPluginNode); | 109 this.partition = new Partition(); |
110 | 110 |
111 this.setupWebviewNodeAttributes(); | 111 this.setupWebviewNodeAttributes(); |
112 this.setupFocusPropagation(); | 112 this.setupFocusPropagation(); |
113 this.setupWebviewNodeProperties(); | 113 this.setupWebviewNodeProperties(); |
114 | 114 |
115 this.viewInstanceId = IdGenerator.GetNextId(); | 115 this.viewInstanceId = IdGenerator.GetNextId(); |
116 | 116 |
117 this.partition = new Partition(); | 117 new WebViewEvents(this, this.viewInstanceId); |
118 this.parseAttributes(); | |
119 | 118 |
120 new WebViewEvents(this, this.viewInstanceId); | 119 shadowRoot.appendChild(this.browserPluginNode); |
121 } | 120 } |
122 | 121 |
123 /** | 122 /** |
124 * @private | 123 * @private |
125 */ | 124 */ |
126 WebViewInternal.prototype.createBrowserPluginNode = function() { | 125 WebViewInternal.prototype.createBrowserPluginNode = function() { |
127 // We create BrowserPlugin as a custom element in order to observe changes | 126 // We create BrowserPlugin as a custom element in order to observe changes |
128 // to attributes synchronously. | 127 // to attributes synchronously. |
129 var browserPluginNode = new WebViewInternal.BrowserPlugin(); | 128 var browserPluginNode = new WebViewInternal.BrowserPlugin(); |
130 privates(browserPluginNode).internal = this; | 129 privates(browserPluginNode).internal = this; |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 }; | 555 }; |
557 | 556 |
558 /** | 557 /** |
559 * @private | 558 * @private |
560 */ | 559 */ |
561 WebViewInternal.prototype.handleBrowserPluginAttributeMutation = | 560 WebViewInternal.prototype.handleBrowserPluginAttributeMutation = |
562 function(name, oldValue, newValue) { | 561 function(name, oldValue, newValue) { |
563 if (name == 'internalinstanceid' && !oldValue && !!newValue) { | 562 if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
564 this.browserPluginNode.removeAttribute('internalinstanceid'); | 563 this.browserPluginNode.removeAttribute('internalinstanceid'); |
565 this.internalInstanceId = parseInt(newValue); | 564 this.internalInstanceId = parseInt(newValue); |
566 if (this.deferredAttachState && !!this.guestInstanceId && | 565 if (this.deferredAttachState) { |
567 this.guestInstanceId != 0) { | 566 if (!!this.guestInstanceId && this.guestInstanceId != 0) { |
568 window.setTimeout(function() { | 567 window.setTimeout(function() { |
569 var isNewWindow = this.deferredAttachState ? | 568 var isNewWindow = this.deferredAttachState ? |
570 this.deferredAttachState.isNewWindow : false; | 569 this.deferredAttachState.isNewWindow : false; |
571 var params = this.buildAttachParams(isNewWindow); | 570 var params = this.buildAttachParams(isNewWindow); |
572 guestViewInternalNatives.AttachGuest( | 571 guestViewInternalNatives.AttachGuest( |
573 this.internalInstanceId, | 572 this.internalInstanceId, |
574 this.guestInstanceId, | 573 this.guestInstanceId, |
575 params); | 574 params); |
576 }.bind(this), 0); | 575 }.bind(this), 0); |
576 } | |
577 } else { | |
578 this.parseAttributes(); | |
577 } | 579 } |
578 return; | 580 return; |
579 } | 581 } |
580 | 582 |
581 // This observer monitors mutations to attributes of the BrowserPlugin and | 583 // This observer monitors mutations to attributes of the BrowserPlugin and |
582 // updates the <webview> attributes accordingly. | 584 // updates the <webview> attributes accordingly. |
583 // |newValue| is null if the attribute |name| has been removed. | 585 // |newValue| is null if the attribute |name| has been removed. |
584 if (newValue != null) { | 586 if (newValue != null) { |
585 // Update the <webview> attribute to match the BrowserPlugin attribute. | 587 // Update the <webview> attribute to match the BrowserPlugin attribute. |
586 // Note: Calling setAttribute on <webview> will trigger its mutation | 588 // Note: Calling setAttribute on <webview> will trigger its mutation |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 | 732 |
731 WebViewInternal.prototype.onFrameNameChanged = function(name) { | 733 WebViewInternal.prototype.onFrameNameChanged = function(name) { |
732 this.name = name || ''; | 734 this.name = name || ''; |
733 if (this.name === '') { | 735 if (this.name === '') { |
734 this.webviewNode.removeAttribute('name'); | 736 this.webviewNode.removeAttribute('name'); |
735 } else { | 737 } else { |
736 this.webviewNode.setAttribute('name', this.name); | 738 this.webviewNode.setAttribute('name', this.name); |
737 } | 739 } |
738 }; | 740 }; |
739 | 741 |
742 WebViewInternal.prototype.onPluginDestroyed = function() { | |
743 this.reset(); | |
Fady Samuel
2014/08/23 11:06:16
What happens if you try to set the src attribute w
lazyboy
2014/08/23 16:10:18
The next setting of display = '' will navigate the
| |
744 }; | |
745 | |
740 WebViewInternal.prototype.dispatchEvent = function(webViewEvent) { | 746 WebViewInternal.prototype.dispatchEvent = function(webViewEvent) { |
741 return this.webviewNode.dispatchEvent(webViewEvent); | 747 return this.webviewNode.dispatchEvent(webViewEvent); |
742 }; | 748 }; |
743 | 749 |
744 /** | 750 /** |
745 * Adds an 'on<event>' property on the webview, which can be used to set/unset | 751 * Adds an 'on<event>' property on the webview, which can be used to set/unset |
746 * an event handler. | 752 * an event handler. |
747 */ | 753 */ |
748 WebViewInternal.prototype.setupEventProperty = function(eventName) { | 754 WebViewInternal.prototype.setupEventProperty = function(eventName) { |
749 var propertyName = 'on' + eventName.toLowerCase(); | 755 var propertyName = 'on' + eventName.toLowerCase(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 return params; | 865 return params; |
860 }; | 866 }; |
861 | 867 |
862 WebViewInternal.prototype.attachWindow = function(guestInstanceId, | 868 WebViewInternal.prototype.attachWindow = function(guestInstanceId, |
863 isNewWindow) { | 869 isNewWindow) { |
864 this.guestInstanceId = guestInstanceId; | 870 this.guestInstanceId = guestInstanceId; |
865 var params = this.buildAttachParams(isNewWindow); | 871 var params = this.buildAttachParams(isNewWindow); |
866 | 872 |
867 if (!this.isPluginInRenderTree()) { | 873 if (!this.isPluginInRenderTree()) { |
868 this.deferredAttachState = {isNewWindow: isNewWindow}; | 874 this.deferredAttachState = {isNewWindow: isNewWindow}; |
869 return false; | 875 return true; |
870 } | 876 } |
871 | 877 |
872 this.deferredAttachState = null; | 878 this.deferredAttachState = null; |
873 return guestViewInternalNatives.AttachGuest( | 879 return guestViewInternalNatives.AttachGuest( |
874 this.internalInstanceId, | 880 this.internalInstanceId, |
875 this.guestInstanceId, | 881 this.guestInstanceId, |
876 params); | 882 params); |
877 }; | 883 }; |
878 | 884 |
879 // Registers browser plugin <object> custom element. | 885 // Registers browser plugin <object> custom element. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1033 }; | 1039 }; |
1034 | 1040 |
1035 /** | 1041 /** |
1036 * Implemented when the experimental API is available. | 1042 * Implemented when the experimental API is available. |
1037 * @private | 1043 * @private |
1038 */ | 1044 */ |
1039 WebViewInternal.prototype.setupExperimentalContextMenus = function() {}; | 1045 WebViewInternal.prototype.setupExperimentalContextMenus = function() {}; |
1040 | 1046 |
1041 exports.WebView = WebView; | 1047 exports.WebView = WebView; |
1042 exports.WebViewInternal = WebViewInternal; | 1048 exports.WebViewInternal = WebViewInternal; |
OLD | NEW |