| 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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 | 437 |
| 438 /** | 438 /** |
| 439 * @private | 439 * @private |
| 440 */ | 440 */ |
| 441 WebViewInternal.prototype.setupWebViewSrcAttributeMutationObserver = | 441 WebViewInternal.prototype.setupWebViewSrcAttributeMutationObserver = |
| 442 function() { | 442 function() { |
| 443 // The purpose of this mutation observer is to catch assignment to the src | 443 // The purpose of this mutation observer is to catch assignment to the src |
| 444 // attribute without any changes to its value. This is useful in the case | 444 // attribute without any changes to its value. This is useful in the case |
| 445 // where the webview guest has crashed and navigating to the same address | 445 // where the webview guest has crashed and navigating to the same address |
| 446 // spawns off a new process. | 446 // spawns off a new process. |
| 447 var self = this; | |
| 448 this.srcAndPartitionObserver = new MutationObserver(function(mutations) { | 447 this.srcAndPartitionObserver = new MutationObserver(function(mutations) { |
| 449 $Array.forEach(mutations, function(mutation) { | 448 $Array.forEach(mutations, function(mutation) { |
| 450 var oldValue = mutation.oldValue; | 449 var oldValue = mutation.oldValue; |
| 451 var newValue = self.webviewNode.getAttribute(mutation.attributeName); | 450 var newValue = this.webviewNode.getAttribute(mutation.attributeName); |
| 452 if (oldValue != newValue) { | 451 if (oldValue != newValue) { |
| 453 return; | 452 return; |
| 454 } | 453 } |
| 455 self.handleWebviewAttributeMutation( | 454 this.handleWebviewAttributeMutation( |
| 456 mutation.attributeName, oldValue, newValue); | 455 mutation.attributeName, oldValue, newValue); |
| 457 }); | 456 }.bind(this)); |
| 458 }); | 457 }.bind(this)); |
| 459 var params = { | 458 var params = { |
| 460 attributes: true, | 459 attributes: true, |
| 461 attributeOldValue: true, | 460 attributeOldValue: true, |
| 462 attributeFilter: ['src', 'partition'] | 461 attributeFilter: ['src', 'partition'] |
| 463 }; | 462 }; |
| 464 this.srcAndPartitionObserver.observe(this.webviewNode, params); | 463 this.srcAndPartitionObserver.observe(this.webviewNode, params); |
| 465 }; | 464 }; |
| 466 | 465 |
| 467 /** | 466 /** |
| 468 * @private | 467 * @private |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 WebViewInternal.prototype.dispatchEvent = function(webViewEvent) { | 748 WebViewInternal.prototype.dispatchEvent = function(webViewEvent) { |
| 750 return this.webviewNode.dispatchEvent(webViewEvent); | 749 return this.webviewNode.dispatchEvent(webViewEvent); |
| 751 }; | 750 }; |
| 752 | 751 |
| 753 /** | 752 /** |
| 754 * Adds an 'on<event>' property on the webview, which can be used to set/unset | 753 * Adds an 'on<event>' property on the webview, which can be used to set/unset |
| 755 * an event handler. | 754 * an event handler. |
| 756 */ | 755 */ |
| 757 WebViewInternal.prototype.setupEventProperty = function(eventName) { | 756 WebViewInternal.prototype.setupEventProperty = function(eventName) { |
| 758 var propertyName = 'on' + eventName.toLowerCase(); | 757 var propertyName = 'on' + eventName.toLowerCase(); |
| 759 var self = this; | 758 Object.defineProperty(this.webviewNode, propertyName, { |
| 760 var webviewNode = this.webviewNode; | |
| 761 Object.defineProperty(webviewNode, propertyName, { | |
| 762 get: function() { | 759 get: function() { |
| 763 return self.on[propertyName]; | 760 return this.on[propertyName]; |
| 764 }, | 761 }.bind(this), |
| 765 set: function(value) { | 762 set: function(value) { |
| 766 if (self.on[propertyName]) | 763 if (this.on[propertyName]) |
| 767 webviewNode.removeEventListener(eventName, self.on[propertyName]); | 764 this.webviewNode.removeEventListener(eventName, self.on[propertyName]); |
| 768 self.on[propertyName] = value; | 765 this.on[propertyName] = value; |
| 769 if (value) | 766 if (value) |
| 770 webviewNode.addEventListener(eventName, value); | 767 this.webviewNode.addEventListener(eventName, value); |
| 771 }, | 768 }.bind(this), |
| 772 enumerable: true | 769 enumerable: true |
| 773 }); | 770 }); |
| 774 }; | 771 }; |
| 775 | 772 |
| 776 // Updates state upon loadcommit. | 773 // Updates state upon loadcommit. |
| 777 WebViewInternal.prototype.onLoadCommit = function( | 774 WebViewInternal.prototype.onLoadCommit = function( |
| 778 currentEntryIndex, entryCount, processId, url, isTopLevel) { | 775 currentEntryIndex, entryCount, processId, url, isTopLevel) { |
| 779 this.currentEntryIndex = currentEntryIndex; | 776 this.currentEntryIndex = currentEntryIndex; |
| 780 this.entryCount = entryCount; | 777 this.entryCount = entryCount; |
| 781 this.processId = processId; | 778 this.processId = processId; |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 }; | 1039 }; |
| 1043 | 1040 |
| 1044 /** | 1041 /** |
| 1045 * Implemented when the experimental API is available. | 1042 * Implemented when the experimental API is available. |
| 1046 * @private | 1043 * @private |
| 1047 */ | 1044 */ |
| 1048 WebViewInternal.prototype.setupExperimentalContextMenus = function() {}; | 1045 WebViewInternal.prototype.setupExperimentalContextMenus = function() {}; |
| 1049 | 1046 |
| 1050 exports.WebView = WebView; | 1047 exports.WebView = WebView; |
| 1051 exports.WebViewInternal = WebViewInternal; | 1048 exports.WebViewInternal = WebViewInternal; |
| OLD | NEW |