Commit 7ac82fd5 authored by fsamuel's avatar fsamuel Committed by Commit bot

<webview> cleanup: Change self = this to bind(this) in web_view.js

BUG=none

Review URL: https://codereview.chromium.org/530043002

Cr-Commit-Position: refs/heads/master@{#293053}
parent 8414e964
...@@ -444,18 +444,17 @@ WebViewInternal.prototype.setupWebViewSrcAttributeMutationObserver = ...@@ -444,18 +444,17 @@ WebViewInternal.prototype.setupWebViewSrcAttributeMutationObserver =
// attribute without any changes to its value. This is useful in the case // attribute without any changes to its value. This is useful in the case
// where the webview guest has crashed and navigating to the same address // where the webview guest has crashed and navigating to the same address
// spawns off a new process. // spawns off a new process.
var self = this;
this.srcAndPartitionObserver = new MutationObserver(function(mutations) { this.srcAndPartitionObserver = new MutationObserver(function(mutations) {
$Array.forEach(mutations, function(mutation) { $Array.forEach(mutations, function(mutation) {
var oldValue = mutation.oldValue; var oldValue = mutation.oldValue;
var newValue = self.webviewNode.getAttribute(mutation.attributeName); var newValue = this.webviewNode.getAttribute(mutation.attributeName);
if (oldValue != newValue) { if (oldValue != newValue) {
return; return;
} }
self.handleWebviewAttributeMutation( this.handleWebviewAttributeMutation(
mutation.attributeName, oldValue, newValue); mutation.attributeName, oldValue, newValue);
}); }.bind(this));
}); }.bind(this));
var params = { var params = {
attributes: true, attributes: true,
attributeOldValue: true, attributeOldValue: true,
...@@ -756,19 +755,17 @@ WebViewInternal.prototype.dispatchEvent = function(webViewEvent) { ...@@ -756,19 +755,17 @@ WebViewInternal.prototype.dispatchEvent = function(webViewEvent) {
*/ */
WebViewInternal.prototype.setupEventProperty = function(eventName) { WebViewInternal.prototype.setupEventProperty = function(eventName) {
var propertyName = 'on' + eventName.toLowerCase(); var propertyName = 'on' + eventName.toLowerCase();
var self = this; Object.defineProperty(this.webviewNode, propertyName, {
var webviewNode = this.webviewNode;
Object.defineProperty(webviewNode, propertyName, {
get: function() { get: function() {
return self.on[propertyName]; return this.on[propertyName];
}, }.bind(this),
set: function(value) { set: function(value) {
if (self.on[propertyName]) if (this.on[propertyName])
webviewNode.removeEventListener(eventName, self.on[propertyName]); this.webviewNode.removeEventListener(eventName, self.on[propertyName]);
self.on[propertyName] = value; this.on[propertyName] = value;
if (value) if (value)
webviewNode.addEventListener(eventName, value); this.webviewNode.addEventListener(eventName, value);
}, }.bind(this),
enumerable: true enumerable: true
}); });
}; };
......
...@@ -171,12 +171,11 @@ function DeclarativeWebRequestEvent(opt_eventName, ...@@ -171,12 +171,11 @@ function DeclarativeWebRequestEvent(opt_eventName,
EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions, EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions,
opt_webViewInstanceId); opt_webViewInstanceId);
var self = this;
// TODO(lazyboy): When do we dispose this listener? // TODO(lazyboy): When do we dispose this listener?
WebRequestMessageEvent.addListener(function() { WebRequestMessageEvent.addListener(function() {
// Re-dispatch to subEvent's listeners. // Re-dispatch to subEvent's listeners.
$Function.apply(self.dispatch, self, $Array.slice(arguments)); $Function.apply(this.dispatch, this, $Array.slice(arguments));
}, {instanceId: opt_webViewInstanceId || 0}); }.bind(this), {instanceId: opt_webViewInstanceId || 0});
} }
DeclarativeWebRequestEvent.prototype = { DeclarativeWebRequestEvent.prototype = {
...@@ -216,40 +215,39 @@ WebViewEvents.prototype.setupPluginDestroyedEvent = function() { ...@@ -216,40 +215,39 @@ WebViewEvents.prototype.setupPluginDestroyedEvent = function() {
}; };
WebViewEvents.prototype.setupWebRequestEvents = function() { WebViewEvents.prototype.setupWebRequestEvents = function() {
var self = this;
var request = {}; var request = {};
var createWebRequestEvent = function(webRequestEvent) { var createWebRequestEvent = function(webRequestEvent) {
return function() { return function() {
if (!self[webRequestEvent.name]) { if (!this[webRequestEvent.name]) {
self[webRequestEvent.name] = this[webRequestEvent.name] =
new WebRequestEvent( new WebRequestEvent(
'webViewInternal.' + webRequestEvent.name, 'webViewInternal.' + webRequestEvent.name,
webRequestEvent.parameters, webRequestEvent.parameters,
webRequestEvent.extraParameters, webRequestEvent.options, webRequestEvent.extraParameters, webRequestEvent.options,
self.viewInstanceId); this.viewInstanceId);
} }
return self[webRequestEvent.name]; return this[webRequestEvent.name];
}; }.bind(this);
}; }.bind(this);
var createDeclarativeWebRequestEvent = function(webRequestEvent) { var createDeclarativeWebRequestEvent = function(webRequestEvent) {
return function() { return function() {
if (!self[webRequestEvent.name]) { if (!this[webRequestEvent.name]) {
// The onMessage event gets a special event type because we want // The onMessage event gets a special event type because we want
// the listener to fire only for messages targeted for this particular // the listener to fire only for messages targeted for this particular
// <webview>. // <webview>.
var EventClass = webRequestEvent.name === 'onMessage' ? var EventClass = webRequestEvent.name === 'onMessage' ?
DeclarativeWebRequestEvent : EventBindings.Event; DeclarativeWebRequestEvent : EventBindings.Event;
self[webRequestEvent.name] = this[webRequestEvent.name] =
new EventClass( new EventClass(
'webViewInternal.' + webRequestEvent.name, 'webViewInternal.' + webRequestEvent.name,
webRequestEvent.parameters, webRequestEvent.parameters,
webRequestEvent.options, webRequestEvent.options,
self.viewInstanceId); this.viewInstanceId);
} }
return self[webRequestEvent.name]; return this[webRequestEvent.name];
}; }.bind(this);
}; }.bind(this);
for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) { for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) {
var eventSchema = DeclarativeWebRequestSchema.events[i]; var eventSchema = DeclarativeWebRequestSchema.events[i];
...@@ -289,23 +287,23 @@ WebViewEvents.prototype.getEvents = function() { ...@@ -289,23 +287,23 @@ WebViewEvents.prototype.getEvents = function() {
}; };
WebViewEvents.prototype.setupEvent = function(name, info) { WebViewEvents.prototype.setupEvent = function(name, info) {
var self = this;
info.evt.addListener(function(e) { info.evt.addListener(function(e) {
var details = {bubbles:true}; var details = {bubbles:true};
if (info.cancelable) if (info.cancelable) {
details.cancelable = true; details.cancelable = true;
}
var webViewEvent = new Event(name, details); var webViewEvent = new Event(name, details);
$Array.forEach(info.fields, function(field) { $Array.forEach(info.fields, function(field) {
if (e[field] !== undefined) { if (e[field] !== undefined) {
webViewEvent[field] = e[field]; webViewEvent[field] = e[field];
} }
}); }.bind(this));
if (info.customHandler) { if (info.customHandler) {
info.customHandler(self, e, webViewEvent); info.customHandler(this, e, webViewEvent);
return; return;
} }
self.webViewInternal.dispatchEvent(webViewEvent); this.webViewInternal.dispatchEvent(webViewEvent);
}, {instanceId: self.viewInstanceId}); }.bind(this), {instanceId: this.viewInstanceId});
this.webViewInternal.setupEventProperty(name); this.webViewInternal.setupEventProperty(name);
}; };
...@@ -326,7 +324,6 @@ WebViewEvents.prototype.handleDialogEvent = function(event, webViewEvent) { ...@@ -326,7 +324,6 @@ WebViewEvents.prototype.handleDialogEvent = function(event, webViewEvent) {
window.console.warn(output); window.console.warn(output);
}; };
var self = this;
var requestId = event.requestId; var requestId = event.requestId;
var actionTaken = false; var actionTaken = false;
...@@ -341,8 +338,8 @@ WebViewEvents.prototype.handleDialogEvent = function(event, webViewEvent) { ...@@ -341,8 +338,8 @@ WebViewEvents.prototype.handleDialogEvent = function(event, webViewEvent) {
}; };
var getGuestInstanceId = function() { var getGuestInstanceId = function() {
return self.webViewInternal.getGuestInstanceId(); return this.webViewInternal.getGuestInstanceId();
}; }.bind(this);
var dialog = { var dialog = {
ok: function(user_input) { ok: function(user_input) {
...@@ -358,7 +355,7 @@ WebViewEvents.prototype.handleDialogEvent = function(event, webViewEvent) { ...@@ -358,7 +355,7 @@ WebViewEvents.prototype.handleDialogEvent = function(event, webViewEvent) {
}; };
webViewEvent.dialog = dialog; webViewEvent.dialog = dialog;
var defaultPrevented = !self.webViewInternal.dispatchEvent(webViewEvent); var defaultPrevented = !this.webViewInternal.dispatchEvent(webViewEvent);
if (actionTaken) { if (actionTaken) {
return; return;
} }
...@@ -426,10 +423,9 @@ WebViewEvents.prototype.handleNewWindowEvent = function(event, webViewEvent) { ...@@ -426,10 +423,9 @@ WebViewEvents.prototype.handleNewWindowEvent = function(event, webViewEvent) {
var requestId = event.requestId; var requestId = event.requestId;
var actionTaken = false; var actionTaken = false;
var self = this;
var getGuestInstanceId = function() { var getGuestInstanceId = function() {
return self.webViewInternal.getGuestInstanceId(); return this.webViewInternal.getGuestInstanceId();
}; }.bind(this);
var validateCall = function () { var validateCall = function () {
if (actionTaken) { if (actionTaken) {
...@@ -475,7 +471,7 @@ WebViewEvents.prototype.handleNewWindowEvent = function(event, webViewEvent) { ...@@ -475,7 +471,7 @@ WebViewEvents.prototype.handleNewWindowEvent = function(event, webViewEvent) {
}; };
webViewEvent.window = windowObj; webViewEvent.window = windowObj;
var defaultPrevented = !self.webViewInternal.dispatchEvent(webViewEvent); var defaultPrevented = !this.webViewInternal.dispatchEvent(webViewEvent);
if (actionTaken) { if (actionTaken) {
return; return;
} }
...@@ -533,10 +529,9 @@ WebViewEvents.prototype.handlePermissionEvent = ...@@ -533,10 +529,9 @@ WebViewEvents.prototype.handlePermissionEvent =
}; };
var requestId = event.requestId; var requestId = event.requestId;
var self = this;
var getGuestInstanceId = function() { var getGuestInstanceId = function() {
return self.webViewInternal.getGuestInstanceId(); return this.webViewInternal.getGuestInstanceId();
}; }.bind(this);
if (this.getPermissionTypes().indexOf(event.permission) < 0) { if (this.getPermissionTypes().indexOf(event.permission) < 0) {
// The permission type is not allowed. Trigger the default response. // The permission type is not allowed. Trigger the default response.
...@@ -571,7 +566,7 @@ WebViewEvents.prototype.handlePermissionEvent = ...@@ -571,7 +566,7 @@ WebViewEvents.prototype.handlePermissionEvent =
}; };
webViewEvent.request = request; webViewEvent.request = request;
var defaultPrevented = !self.webViewInternal.dispatchEvent(webViewEvent); var defaultPrevented = !this.webViewInternal.dispatchEvent(webViewEvent);
if (decisionMade) { if (decisionMade) {
return; return;
} }
......
...@@ -47,12 +47,11 @@ function ContextMenusOnClickedEvent(opt_eventName, ...@@ -47,12 +47,11 @@ function ContextMenusOnClickedEvent(opt_eventName,
EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions, EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions,
opt_webViewInstanceId); opt_webViewInstanceId);
var self = this;
// TODO(lazyboy): When do we dispose this listener? // TODO(lazyboy): When do we dispose this listener?
ContextMenusEvent.addListener(function() { ContextMenusEvent.addListener(function() {
// Re-dispatch to subEvent's listeners. // Re-dispatch to subEvent's listeners.
$Function.apply(self.dispatch, self, $Array.slice(arguments)); $Function.apply(this.dispatch, this, $Array.slice(arguments));
}, {instanceId: opt_webViewInstanceId || 0}); }.bind(this), {instanceId: opt_webViewInstanceId || 0});
} }
ContextMenusOnClickedEvent.prototype = { ContextMenusOnClickedEvent.prototype = {
...@@ -94,7 +93,6 @@ var WebViewContextMenus = utils.expose( ...@@ -94,7 +93,6 @@ var WebViewContextMenus = utils.expose(
/** @private */ /** @private */
WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
var requestId = e.requestId; var requestId = e.requestId;
var self = this;
// Construct the event.menu object. // Construct the event.menu object.
var actionTaken = false; var actionTaken = false;
var validateCall = function() { var validateCall = function() {
...@@ -111,8 +109,8 @@ WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { ...@@ -111,8 +109,8 @@ WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
validateCall(); validateCall();
// TODO(lazyboy): WebViewShowContextFunction doesn't do anything useful // TODO(lazyboy): WebViewShowContextFunction doesn't do anything useful
// with |items|, implement. // with |items|, implement.
WebView.showContextMenu(self.guestInstanceId, requestId, items); WebView.showContextMenu(this.guestInstanceId, requestId, items);
} }.bind(this)
}; };
webViewEvent.menu = menu; webViewEvent.menu = menu;
var webviewNode = this.webviewNode; var webviewNode = this.webviewNode;
...@@ -123,7 +121,7 @@ WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { ...@@ -123,7 +121,7 @@ WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
if (!defaultPrevented) { if (!defaultPrevented) {
actionTaken = true; actionTaken = true;
// The default action is equivalent to just showing the context menu as is. // The default action is equivalent to just showing the context menu as is.
WebView.showContextMenu(self.guestInstanceId, requestId, undefined); WebView.showContextMenu(this.guestInstanceId, requestId, undefined);
// TODO(lazyboy): Figure out a way to show warning message only when // TODO(lazyboy): Figure out a way to show warning message only when
// listeners are registered for this event. // listeners are registered for this event.
...@@ -152,39 +150,38 @@ WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) { ...@@ -152,39 +150,38 @@ WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {
/** @private */ /** @private */
WebViewInternal.prototype.setupExperimentalContextMenus = function() { WebViewInternal.prototype.setupExperimentalContextMenus = function() {
var self = this;
var createContextMenus = function() { var createContextMenus = function() {
return function() { return function() {
if (self.contextMenus_) { if (this.contextMenus_) {
return self.contextMenus_; return this.contextMenus_;
} }
self.contextMenus_ = new WebViewContextMenus(self.viewInstanceId); this.contextMenus_ = new WebViewContextMenus(this.viewInstanceId);
// Define 'onClicked' event property on |self.contextMenus_|. // Define 'onClicked' event property on |this.contextMenus_|.
var getOnClickedEvent = function() { var getOnClickedEvent = function() {
return function() { return function() {
if (!self.contextMenusOnClickedEvent_) { if (!this.contextMenusOnClickedEvent_) {
var eventName = 'webViewInternal.onClicked'; var eventName = 'webViewInternal.onClicked';
// TODO(lazyboy): Find event by name instead of events[0]. // TODO(lazyboy): Find event by name instead of events[0].
var eventSchema = WebViewSchema.events[0]; var eventSchema = WebViewSchema.events[0];
var eventOptions = {supportsListeners: true}; var eventOptions = {supportsListeners: true};
var onClickedEvent = new ContextMenusOnClickedEvent( var onClickedEvent = new ContextMenusOnClickedEvent(
eventName, eventSchema, eventOptions, self.viewInstanceId); eventName, eventSchema, eventOptions, this.viewInstanceId);
self.contextMenusOnClickedEvent_ = onClickedEvent; this.contextMenusOnClickedEvent_ = onClickedEvent;
return onClickedEvent; return onClickedEvent;
} }
return self.contextMenusOnClickedEvent_; return this.contextMenusOnClickedEvent_;
} }.bind(this);
}; }.bind(this);
Object.defineProperty( Object.defineProperty(
self.contextMenus_, this.contextMenus_,
'onClicked', 'onClicked',
{get: getOnClickedEvent(), enumerable: true}); {get: getOnClickedEvent(), enumerable: true});
return self.contextMenus_; return this.contextMenus_;
}; }.bind(this);
}; }.bind(this);
// Expose <webview>.contextMenus object. // Expose <webview>.contextMenus object.
Object.defineProperty( Object.defineProperty(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment