Bug 1097442 - Part 1: rename eventTarget to eventListener. r=dimi

From 3e4d4deffb10f715e03725700d4078aa98cc1803 Mon Sep 17 00:00:00 2001
---
 dom/nfc/NfcContentHelper.js     | 18 +++++++++---------
 dom/nfc/gonk/Nfc.js             | 28 ++++++++++++++--------------
 dom/nfc/nsINfcContentHelper.idl | 13 +++++++------
 dom/nfc/nsNfc.js                |  4 ++--
 4 files changed, 32 insertions(+), 31 deletions(-)
This commit is contained in:
Yoshi Huang 2014-11-12 10:26:09 +08:00
parent 8db9333880
commit 7b50cbd594
4 changed files with 32 additions and 31 deletions

View File

@ -88,7 +88,7 @@ NfcContentHelper.prototype = {
_window: null,
_requestMap: null,
eventTarget: null,
eventListener: null,
init: function init(aWindow) {
if (aWindow == null) {
@ -221,9 +221,9 @@ NfcContentHelper.prototype = {
});
},
registerEventTarget: function registerEventTarget(target) {
this.eventTarget = target;
cpmm.sendAsyncMessage("NFC:AddEventTarget");
addEventListener: function addEventListener(listener) {
this.eventListener = listener;
cpmm.sendAsyncMessage("NFC:AddEventListener");
},
registerTargetForPeerReady: function registerTargetForPeerReady(appId) {
@ -351,13 +351,13 @@ NfcContentHelper.prototype = {
case "NFC:DOMEvent":
switch (result.event) {
case NFC.PEER_EVENT_READY:
this.eventTarget.notifyPeerFound(result.sessionToken, /* isPeerReady */ true);
this.eventListener.notifyPeerFound(result.sessionToken, /* isPeerReady */ true);
break;
case NFC.PEER_EVENT_FOUND:
this.eventTarget.notifyPeerFound(result.sessionToken);
this.eventListener.notifyPeerFound(result.sessionToken);
break;
case NFC.PEER_EVENT_LOST:
this.eventTarget.notifyPeerLost(result.sessionToken);
this.eventListener.notifyPeerLost(result.sessionToken);
break;
case NFC.TAG_EVENT_FOUND:
let event = new NfcTagEvent(result.techList,
@ -366,10 +366,10 @@ NfcContentHelper.prototype = {
result.isReadOnly,
result.isFormatable);
this.eventTarget.notifyTagFound(result.sessionToken, event, result.records);
this.eventListener.notifyTagFound(result.sessionToken, event, result.records);
break;
case NFC.TAG_EVENT_LOST:
this.eventTarget.notifyTagLost(result.sessionToken);
this.eventListener.notifyTagLost(result.sessionToken);
break;
}
break;

View File

@ -55,7 +55,7 @@ const NFC_CID =
Components.ID("{2ff24790-5e74-11e1-b86c-0800200c9a66}");
const NFC_IPC_ADD_EVENT_TARGET_MSG_NAMES = [
"NFC:AddEventTarget"
"NFC:AddEventListener"
];
const NFC_IPC_MSG_NAMES = [
@ -104,7 +104,7 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
// Manage registered Peer Targets
peerTargets: {},
eventTargets: [],
eventListeners: [],
init: function init(nfc) {
this.nfc = nfc;
@ -205,18 +205,18 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
target.sendAsyncMessage("NFC:DOMEvent", options);
},
addEventTarget: function addEventTarget(target) {
if (this.eventTargets.indexOf(target) != -1) {
addEventListener: function addEventListener(target) {
if (this.eventListeners.indexOf(target) != -1) {
return;
}
this.eventTargets.push(target);
this.eventListeners.push(target);
},
removeEventTarget: function removeEventTarget(target) {
let index = this.eventTargets.indexOf(target);
removeEventListener: function removeEventListener(target) {
let index = this.eventListeners.indexOf(target);
if (index !== -1) {
this.eventTargets.splice(index, 1);
this.eventListeners.splice(index, 1);
}
},
@ -247,21 +247,21 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
onTagFound: function onTagFound(message) {
message.event = NFC.TAG_EVENT_FOUND;
for (let target of this.eventTargets) {
for (let target of this.eventListeners) {
this.notifyDOMEvent(target, message);
}
delete message.event;
},
onTagLost: function onTagLost(sessionToken) {
for (let target of this.eventTargets) {
for (let target of this.eventListeners) {
this.notifyDOMEvent(target, {event: NFC.TAG_EVENT_LOST,
sessionToken: sessionToken});
}
},
onPeerEvent: function onPeerEvent(eventType, sessionToken) {
for (let target of this.eventTargets) {
for (let target of this.eventListeners) {
this.notifyDOMEvent(target, { event: eventType,
sessionToken: sessionToken });
}
@ -277,7 +277,7 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
if (message.name == "child-process-shutdown") {
this.removePeerTarget(message.target);
this.nfc.removeTarget(message.target);
this.removeEventTarget(message.target);
this.removeEventListener(message.target);
return null;
}
@ -308,8 +308,8 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
}
switch (message.name) {
case "NFC:AddEventTarget":
this.addEventTarget(message.target);
case "NFC:AddEventListener":
this.addEventListener(message.target);
return null;
case "NFC:CheckSessionToken":
let sessionToken = message.data.sessionToken;

View File

@ -22,8 +22,8 @@ interface nsINfcTagEvent : nsISupports
readonly attribute boolean isFormatable;
};
[scriptable, uuid(2074503e-f590-4017-a45e-85d3ca766f41)]
interface nsINfcDOMEventTarget : nsISupports
[scriptable, uuid(42c7a85f-59ae-4bde-b961-e1f1436476c3)]
interface nsINfcDOMEventListener : nsISupports
{
/**
* Callback function used to notify tagfound.
@ -65,7 +65,7 @@ interface nsINfcDOMEventTarget : nsISupports
void notifyPeerLost(in DOMString sessionToken);
};
[scriptable, uuid(d2a3fbf3-a0b2-4625-b0db-b6f37c937097)]
[scriptable, uuid(632cd911-06bf-410b-a91e-8afa4e200e3b)]
interface nsINfcContentHelper : nsISupports
{
const long NFC_EVENT_PEER_READY = 0x01;
@ -100,11 +100,12 @@ interface nsINfcContentHelper : nsISupports
in DOMString sessionToken);
/**
* Register the event target.
* Add the event listener.
*
* @param target An instance of the nsINfcDOMEventTarget.
* @param listener
* An instance of the nsINfcDOMEventListener.
*/
void registerEventTarget(in nsINfcDOMEventTarget target);
void addEventListener(in nsINfcDOMEventListener listener);
/**
* Register the given application id with parent process

View File

@ -166,7 +166,7 @@ function MozNFCImpl() {
debug("No NFC support.")
}
this._nfcContentHelper.registerEventTarget(this);
this._nfcContentHelper.addEventListener(this);
}
MozNFCImpl.prototype = {
_nfcContentHelper: null,
@ -389,7 +389,7 @@ MozNFCImpl.prototype = {
contractID: "@mozilla.org/navigatorNfc;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
Ci.nsIDOMGlobalPropertyInitializer,
Ci.nsINfcDOMEventTarget]),
Ci.nsINfcDOMEventListener]),
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MozNFCTagImpl,