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 =
// 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
// spawns off a new process.
var self = this;
this.srcAndPartitionObserver = new MutationObserver(function(mutations) {
$Array.forEach(mutations, function(mutation) {
var oldValue = mutation.oldValue;
var newValue = self.webviewNode.getAttribute(mutation.attributeName);
var newValue = this.webviewNode.getAttribute(mutation.attributeName);
if (oldValue != newValue) {
return;
}
self.handleWebviewAttributeMutation(
this.handleWebviewAttributeMutation(
mutation.attributeName, oldValue, newValue);
});
});
}.bind(this));
}.bind(this));
var params = {
attributes: true,
attributeOldValue: true,
......@@ -756,19 +755,17 @@ WebViewInternal.prototype.dispatchEvent = function(webViewEvent) {
*/
WebViewInternal.prototype.setupEventProperty = function(eventName) {
var propertyName = 'on' + eventName.toLowerCase();
var self = this;
var webviewNode = this.webviewNode;
Object.defineProperty(webviewNode, propertyName, {
Object.defineProperty(this.webviewNode, propertyName, {
get: function() {
return self.on[propertyName];
},
return this.on[propertyName];
}.bind(this),
set: function(value) {
if (self.on[propertyName])
webviewNode.removeEventListener(eventName, self.on[propertyName]);
self.on[propertyName] = value;
if (this.on[propertyName])
this.webviewNode.removeEventListener(eventName, self.on[propertyName]);
this.on[propertyName] = value;
if (value)
webviewNode.addEventListener(eventName, value);
},
this.webviewNode.addEventListener(eventName, value);
}.bind(this),
enumerable: true
});
};
......
......@@ -171,12 +171,11 @@ function DeclarativeWebRequestEvent(opt_eventName,
EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions,
opt_webViewInstanceId);
var self = this;
// TODO(lazyboy): When do we dispose this listener?
WebRequestMessageEvent.addListener(function() {
// Re-dispatch to subEvent's listeners.
$Function.apply(self.dispatch, self, $Array.slice(arguments));
}, {instanceId: opt_webViewInstanceId || 0});
$Function.apply(this.dispatch, this, $Array.slice(arguments));
}.bind(this), {instanceId: opt_webViewInstanceId || 0});
}
DeclarativeWebRequestEvent.prototype = {
......@@ -216,40 +215,39 @@ WebViewEvents.prototype.setupPluginDestroyedEvent = function() {
};
WebViewEvents.prototype.setupWebRequestEvents = function() {
var self = this;
var request = {};
var createWebRequestEvent = function(webRequestEvent) {
return function() {
if (!self[webRequestEvent.name]) {
self[webRequestEvent.name] =
if (!this[webRequestEvent.name]) {
this[webRequestEvent.name] =
new WebRequestEvent(
'webViewInternal.' + webRequestEvent.name,
webRequestEvent.parameters,
webRequestEvent.extraParameters, webRequestEvent.options,
self.viewInstanceId);
this.viewInstanceId);
}
return self[webRequestEvent.name];
};
};
return this[webRequestEvent.name];
}.bind(this);
}.bind(this);
var createDeclarativeWebRequestEvent = function(webRequestEvent) {
return function() {
if (!self[webRequestEvent.name]) {
if (!this[webRequestEvent.name]) {
// The onMessage event gets a special event type because we want
// the listener to fire only for messages targeted for this particular
// <webview>.
var EventClass = webRequestEvent.name === 'onMessage' ?
DeclarativeWebRequestEvent : EventBindings.Event;
self[webRequestEvent.name] =
this[webRequestEvent.name] =
new EventClass(
'webViewInternal.' + webRequestEvent.name,
webRequestEvent.parameters,
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) {
var eventSchema = DeclarativeWebRequestSchema.events[i];
......@@ -289,23 +287,23 @@ WebViewEvents.prototype.getEvents = function() {
};
WebViewEvents.prototype.setupEvent = function(name, info) {
var self = this;
info.evt.addListener(function(e) {
var details = {bubbles:true};
if (info.cancelable)
if (info.cancelable) {
details.cancelable = true;
}
var webViewEvent = new Event(name, details);
$Array.forEach(info.fields, function(field) {
if (e[field] !== undefined) {
webViewEvent[field] = e[field];
}
});
}.bind(this));
if (info.customHandler) {
info.customHandler(self, e, webViewEvent);
info.customHandler(this, e, webViewEvent);
return;
}
self.webViewInternal.dispatchEvent(webViewEvent);
}, {instanceId: self.viewInstanceId});
this.webViewInternal.dispatchEvent(webViewEvent);
}.bind(this), {instanceId: this.viewInstanceId});
this.webViewInternal.setupEventProperty(name);
};
......@@ -326,7 +324,6 @@ WebViewEvents.prototype.handleDialogEvent = function(event, webViewEvent) {
window.console.warn(output);
};
var self = this;
var requestId = event.requestId;
var actionTaken = false;
......@@ -341,8 +338,8 @@ WebViewEvents.prototype.handleDialogEvent = function(event, webViewEvent) {
};
var getGuestInstanceId = function() {
return self.webViewInternal.getGuestInstanceId();
};
return this.webViewInternal.getGuestInstanceId();
}.bind(this);
var dialog = {
ok: function(user_input) {
......@@ -358,7 +355,7 @@ WebViewEvents.prototype.handleDialogEvent = function(event, webViewEvent) {
};
webViewEvent.dialog = dialog;
var defaultPrevented = !self.webViewInternal.dispatchEvent(webViewEvent);
var defaultPrevented = !this.webViewInternal.dispatchEvent(webViewEvent);
if (actionTaken) {
return;
}
......@@ -426,10 +423,9 @@ WebViewEvents.prototype.handleNewWindowEvent = function(event, webViewEvent) {
var requestId = event.requestId;
var actionTaken = false;
var self = this;
var getGuestInstanceId = function() {
return self.webViewInternal.getGuestInstanceId();
};
return this.webViewInternal.getGuestInstanceId();
}.bind(this);
var validateCall = function () {
if (actionTaken) {
......@@ -475,7 +471,7 @@ WebViewEvents.prototype.handleNewWindowEvent = function(event, webViewEvent) {
};
webViewEvent.window = windowObj;
var defaultPrevented = !self.webViewInternal.dispatchEvent(webViewEvent);
var defaultPrevented = !this.webViewInternal.dispatchEvent(webViewEvent);
if (actionTaken) {
return;
}
......@@ -533,10 +529,9 @@ WebViewEvents.prototype.handlePermissionEvent =
};
var requestId = event.requestId;
var self = this;
var getGuestInstanceId = function() {
return self.webViewInternal.getGuestInstanceId();
};
return this.webViewInternal.getGuestInstanceId();
}.bind(this);
if (this.getPermissionTypes().indexOf(event.permission) < 0) {
// The permission type is not allowed. Trigger the default response.
......@@ -571,7 +566,7 @@ WebViewEvents.prototype.handlePermissionEvent =
};
webViewEvent.request = request;
var defaultPrevented = !self.webViewInternal.dispatchEvent(webViewEvent);
var defaultPrevented = !this.webViewInternal.dispatchEvent(webViewEvent);
if (decisionMade) {
return;
}
......
......@@ -47,12 +47,11 @@ function ContextMenusOnClickedEvent(opt_eventName,
EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions,
opt_webViewInstanceId);
var self = this;
// TODO(lazyboy): When do we dispose this listener?
ContextMenusEvent.addListener(function() {
// Re-dispatch to subEvent's listeners.
$Function.apply(self.dispatch, self, $Array.slice(arguments));
}, {instanceId: opt_webViewInstanceId || 0});
$Function.apply(this.dispatch, this, $Array.slice(arguments));
}.bind(this), {instanceId: opt_webViewInstanceId || 0});
}
ContextMenusOnClickedEvent.prototype = {
......@@ -94,7 +93,6 @@ var WebViewContextMenus = utils.expose(
/** @private */
WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
var requestId = e.requestId;
var self = this;
// Construct the event.menu object.
var actionTaken = false;
var validateCall = function() {
......@@ -111,8 +109,8 @@ WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
validateCall();
// TODO(lazyboy): WebViewShowContextFunction doesn't do anything useful
// with |items|, implement.
WebView.showContextMenu(self.guestInstanceId, requestId, items);
}
WebView.showContextMenu(this.guestInstanceId, requestId, items);
}.bind(this)
};
webViewEvent.menu = menu;
var webviewNode = this.webviewNode;
......@@ -123,7 +121,7 @@ WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
if (!defaultPrevented) {
actionTaken = true;
// 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
// listeners are registered for this event.
......@@ -152,39 +150,38 @@ WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {
/** @private */
WebViewInternal.prototype.setupExperimentalContextMenus = function() {
var self = this;
var createContextMenus = function() {
return function() {
if (self.contextMenus_) {
return self.contextMenus_;
if (this.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() {
return function() {
if (!self.contextMenusOnClickedEvent_) {
if (!this.contextMenusOnClickedEvent_) {
var eventName = 'webViewInternal.onClicked';
// TODO(lazyboy): Find event by name instead of events[0].
var eventSchema = WebViewSchema.events[0];
var eventOptions = {supportsListeners: true};
var onClickedEvent = new ContextMenusOnClickedEvent(
eventName, eventSchema, eventOptions, self.viewInstanceId);
self.contextMenusOnClickedEvent_ = onClickedEvent;
eventName, eventSchema, eventOptions, this.viewInstanceId);
this.contextMenusOnClickedEvent_ = onClickedEvent;
return onClickedEvent;
}
return self.contextMenusOnClickedEvent_;
}
};
return this.contextMenusOnClickedEvent_;
}.bind(this);
}.bind(this);
Object.defineProperty(
self.contextMenus_,
this.contextMenus_,
'onClicked',
{get: getOnClickedEvent(), enumerable: true});
return self.contextMenus_;
};
};
return this.contextMenus_;
}.bind(this);
}.bind(this);
// Expose <webview>.contextMenus object.
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