| 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 |
| 567 this.guestInstanceId != 0) { | 566 if (!this.deferredAttachState) { |
| 567 this.parseAttributes(); |
| 568 return; |
| 569 } |
| 570 |
| 571 if (!!this.guestInstanceId && this.guestInstanceId != 0) { |
| 568 window.setTimeout(function() { | 572 window.setTimeout(function() { |
| 569 var isNewWindow = this.deferredAttachState ? | 573 var isNewWindow = this.deferredAttachState ? |
| 570 this.deferredAttachState.isNewWindow : false; | 574 this.deferredAttachState.isNewWindow : false; |
| 571 var params = this.buildAttachParams(isNewWindow); | 575 var params = this.buildAttachParams(isNewWindow); |
| 572 guestViewInternalNatives.AttachGuest( | 576 guestViewInternalNatives.AttachGuest( |
| 573 this.internalInstanceId, | 577 this.internalInstanceId, |
| 574 this.guestInstanceId, | 578 this.guestInstanceId, |
| 575 params); | 579 params); |
| 576 }.bind(this), 0); | 580 }.bind(this), 0); |
| 577 } | 581 } |
| 582 |
| 578 return; | 583 return; |
| 579 } | 584 } |
| 580 | 585 |
| 581 // This observer monitors mutations to attributes of the BrowserPlugin and | 586 // This observer monitors mutations to attributes of the BrowserPlugin and |
| 582 // updates the <webview> attributes accordingly. | 587 // updates the <webview> attributes accordingly. |
| 583 // |newValue| is null if the attribute |name| has been removed. | 588 // |newValue| is null if the attribute |name| has been removed. |
| 584 if (newValue != null) { | 589 if (newValue != null) { |
| 585 // Update the <webview> attribute to match the BrowserPlugin attribute. | 590 // Update the <webview> attribute to match the BrowserPlugin attribute. |
| 586 // Note: Calling setAttribute on <webview> will trigger its mutation | 591 // Note: Calling setAttribute on <webview> will trigger its mutation |
| 587 // observer which will then propagate that attribute to BrowserPlugin. In | 592 // observer which will then propagate that attribute to BrowserPlugin. In |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 | 735 |
| 731 WebViewInternal.prototype.onFrameNameChanged = function(name) { | 736 WebViewInternal.prototype.onFrameNameChanged = function(name) { |
| 732 this.name = name || ''; | 737 this.name = name || ''; |
| 733 if (this.name === '') { | 738 if (this.name === '') { |
| 734 this.webviewNode.removeAttribute('name'); | 739 this.webviewNode.removeAttribute('name'); |
| 735 } else { | 740 } else { |
| 736 this.webviewNode.setAttribute('name', this.name); | 741 this.webviewNode.setAttribute('name', this.name); |
| 737 } | 742 } |
| 738 }; | 743 }; |
| 739 | 744 |
| 745 WebViewInternal.prototype.onPluginDestroyed = function() { |
| 746 this.reset(); |
| 747 }; |
| 748 |
| 740 WebViewInternal.prototype.dispatchEvent = function(webViewEvent) { | 749 WebViewInternal.prototype.dispatchEvent = function(webViewEvent) { |
| 741 return this.webviewNode.dispatchEvent(webViewEvent); | 750 return this.webviewNode.dispatchEvent(webViewEvent); |
| 742 }; | 751 }; |
| 743 | 752 |
| 744 /** | 753 /** |
| 745 * Adds an 'on<event>' property on the webview, which can be used to set/unset | 754 * Adds an 'on<event>' property on the webview, which can be used to set/unset |
| 746 * an event handler. | 755 * an event handler. |
| 747 */ | 756 */ |
| 748 WebViewInternal.prototype.setupEventProperty = function(eventName) { | 757 WebViewInternal.prototype.setupEventProperty = function(eventName) { |
| 749 var propertyName = 'on' + eventName.toLowerCase(); | 758 var propertyName = 'on' + eventName.toLowerCase(); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 }; | 1042 }; |
| 1034 | 1043 |
| 1035 /** | 1044 /** |
| 1036 * Implemented when the experimental API is available. | 1045 * Implemented when the experimental API is available. |
| 1037 * @private | 1046 * @private |
| 1038 */ | 1047 */ |
| 1039 WebViewInternal.prototype.setupExperimentalContextMenus = function() {}; | 1048 WebViewInternal.prototype.setupExperimentalContextMenus = function() {}; |
| 1040 | 1049 |
| 1041 exports.WebView = WebView; | 1050 exports.WebView = WebView; |
| 1042 exports.WebViewInternal = WebViewInternal; | 1051 exports.WebViewInternal = WebViewInternal; |
| OLD | NEW |