Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: chrome/renderer/resources/extensions/web_view.js

Issue 530043002: <webview> cleanup: Change self = this to bind(this) in web_view.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/renderer/resources/extensions/web_view_events.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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;
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/resources/extensions/web_view_events.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698