mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1054217 - part 2: remove targetsBySessionTokens. r=dimi
From 07ca796ae9e1d8f98d8282c2bc4f68046d311fde Mon Sep 17 00:00:00 2001 --- dom/nfc/gonk/Nfc.js | 124 ++++++++++----------------------------------- dom/nfc/gonk/nfc_consts.js | 2 + 2 files changed, 29 insertions(+), 97 deletions(-)
This commit is contained in:
parent
28d58b9bb7
commit
d7ac11ec33
@ -81,9 +81,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
|
|||||||
XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
|
XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
|
||||||
"@mozilla.org/system-message-internal;1",
|
"@mozilla.org/system-message-internal;1",
|
||||||
"nsISystemMessagesInternal");
|
"nsISystemMessagesInternal");
|
||||||
XPCOMUtils.defineLazyServiceGetter(this, "gSystemWorkerManager",
|
|
||||||
"@mozilla.org/telephony/system-worker-manager;1",
|
|
||||||
"nsISystemWorkerManager");
|
|
||||||
XPCOMUtils.defineLazyServiceGetter(this, "UUIDGenerator",
|
XPCOMUtils.defineLazyServiceGetter(this, "UUIDGenerator",
|
||||||
"@mozilla.org/uuid-generator;1",
|
"@mozilla.org/uuid-generator;1",
|
||||||
"nsIUUIDGenerator");
|
"nsIUUIDGenerator");
|
||||||
@ -94,11 +91,6 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
|||||||
|
|
||||||
nfc: null,
|
nfc: null,
|
||||||
|
|
||||||
// Manage message targets in terms of sessionToken. Only the authorized and
|
|
||||||
// registered contents can receive related messages.
|
|
||||||
targetsBySessionTokens: {},
|
|
||||||
sessionTokens: [],
|
|
||||||
|
|
||||||
// Manage registered Peer Targets
|
// Manage registered Peer Targets
|
||||||
peerTargetsMap: {},
|
peerTargetsMap: {},
|
||||||
currentPeerAppId: null,
|
currentPeerAppId: null,
|
||||||
@ -160,70 +152,6 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
|||||||
ppmm = null;
|
ppmm = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
_registerMessageTarget: function _registerMessageTarget(sessionToken, target) {
|
|
||||||
let targets = this.targetsBySessionTokens[sessionToken];
|
|
||||||
if (!targets) {
|
|
||||||
targets = this.targetsBySessionTokens[sessionToken] = [];
|
|
||||||
let list = this.sessionTokens;
|
|
||||||
if (list.indexOf(sessionToken) == -1) {
|
|
||||||
list.push(sessionToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targets.indexOf(target) != -1) {
|
|
||||||
debug("Already registered this target!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
targets.push(target);
|
|
||||||
debug("Registered :" + sessionToken + " target: " + target);
|
|
||||||
},
|
|
||||||
|
|
||||||
_unregisterMessageTarget: function _unregisterMessageTarget(sessionToken, target) {
|
|
||||||
if (sessionToken == null) {
|
|
||||||
// Unregister the target for every sessionToken when no sessionToken is specified.
|
|
||||||
for (let session of this.sessionTokens) {
|
|
||||||
this._unregisterMessageTarget(session, target);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unregister the target for a specified sessionToken.
|
|
||||||
let targets = this.targetsBySessionTokens[sessionToken];
|
|
||||||
if (!targets) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target == null) {
|
|
||||||
debug("Unregistered all targets for the " + sessionToken + " targets: " + targets);
|
|
||||||
targets = [];
|
|
||||||
let list = this.sessionTokens;
|
|
||||||
if (sessionToken !== null) {
|
|
||||||
let index = list.indexOf(sessionToken);
|
|
||||||
if (index > -1) {
|
|
||||||
list.splice(index, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let index = targets.indexOf(target);
|
|
||||||
if (index != -1) {
|
|
||||||
targets.splice(index, 1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_sendTargetMessage: function _sendTargetMessage(sessionToken, message, options) {
|
|
||||||
let targets = this.targetsBySessionTokens[sessionToken];
|
|
||||||
if (!targets) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let target of targets) {
|
|
||||||
target.sendAsyncMessage(message, options);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
registerPeerReadyTarget: function registerPeerReadyTarget(msg) {
|
registerPeerReadyTarget: function registerPeerReadyTarget(msg) {
|
||||||
let appInfo = msg.json;
|
let appInfo = msg.json;
|
||||||
let targets = this.peerTargetsMap;
|
let targets = this.peerTargetsMap;
|
||||||
@ -311,10 +239,6 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
|||||||
receiveMessage: function receiveMessage(msg) {
|
receiveMessage: function receiveMessage(msg) {
|
||||||
debug("Received '" + msg.name + "' message from content process");
|
debug("Received '" + msg.name + "' message from content process");
|
||||||
if (msg.name == "child-process-shutdown") {
|
if (msg.name == "child-process-shutdown") {
|
||||||
// By the time we receive child-process-shutdown, the child process has
|
|
||||||
// already forgotten its permissions so we need to unregister the target
|
|
||||||
// for every permission.
|
|
||||||
this._unregisterMessageTarget(null, msg.target);
|
|
||||||
this.removePeerTarget(msg.target);
|
this.removePeerTarget(msg.target);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -350,9 +274,7 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
|||||||
debug("Received invalid Session Token: " + msg.json.sessionToken + " - Do not register this target");
|
debug("Received invalid Session Token: " + msg.json.sessionToken + " - Do not register this target");
|
||||||
return NFC.NFC_ERROR_BAD_SESSION_ID;
|
return NFC.NFC_ERROR_BAD_SESSION_ID;
|
||||||
}
|
}
|
||||||
this._registerMessageTarget(this.nfc.sessionTokenMap[this.nfc._currentSessionId], msg.target);
|
debug("Registering target for this SessionToken : " + msg.json.sessionToken);
|
||||||
debug("Registering target for this SessionToken : " +
|
|
||||||
this.nfc.sessionTokenMap[this.nfc._currentSessionId]);
|
|
||||||
return NFC.NFC_SUCCESS;
|
return NFC.NFC_SUCCESS;
|
||||||
case "NFC:RegisterPeerReadyTarget":
|
case "NFC:RegisterPeerReadyTarget":
|
||||||
this.registerPeerReadyTarget(msg);
|
this.registerPeerReadyTarget(msg);
|
||||||
@ -378,7 +300,12 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
|||||||
case "NFC:NotifySendFileStatus":
|
case "NFC:NotifySendFileStatus":
|
||||||
// Upon receiving the status of sendFile operation, send the response
|
// Upon receiving the status of sendFile operation, send the response
|
||||||
// to appropriate content process.
|
// to appropriate content process.
|
||||||
this.sendNfcResponseMessage(msg.name + "Response", msg.json);
|
msg.json.type = "NotifySendFileStatus";
|
||||||
|
if (msg.json.status !== NFC.NFC_SUCCESS) {
|
||||||
|
msg.json.errorMsg =
|
||||||
|
this.nfc.getErrorMessage(NFC.NFC_GECKO_ERROR_SEND_FILE_FAILED);
|
||||||
|
}
|
||||||
|
this.nfc.sendNfcResponse(msg.json);
|
||||||
return null;
|
return null;
|
||||||
default:
|
default:
|
||||||
return this.nfc.receiveMessage(msg);
|
return this.nfc.receiveMessage(msg);
|
||||||
@ -396,10 +323,6 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sendNfcResponseMessage: function sendNfcResponseMessage(message, data) {
|
|
||||||
this._sendTargetMessage(this.nfc.sessionTokenMap[this.nfc._currentSessionId], message, data);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -449,6 +372,17 @@ Nfc.prototype = {
|
|||||||
this.nfcService.sendCommand(message);
|
this.nfcService.sendCommand(message);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sendNfcResponse: function sendNfcResponse(message) {
|
||||||
|
let target = this.targetsByRequestId[message.requestId];
|
||||||
|
if (!target) {
|
||||||
|
debug("No target for requestId: " + message.requestId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete this.targetsByRequestId[message.requestId];
|
||||||
|
|
||||||
|
target.sendAsyncMessage("NFC:" + message.type, message);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send Error response to content. This is used only
|
* Send Error response to content. This is used only
|
||||||
* in case of discovering an error in message received from
|
* in case of discovering an error in message received from
|
||||||
@ -506,7 +440,6 @@ Nfc.prototype = {
|
|||||||
break;
|
break;
|
||||||
case "TechLostNotification":
|
case "TechLostNotification":
|
||||||
message.type = "techLost";
|
message.type = "techLost";
|
||||||
gMessageManager._unregisterMessageTarget(this.sessionTokenMap[this._currentSessionId], null);
|
|
||||||
|
|
||||||
// Update the upper layers with a session token (alias)
|
// Update the upper layers with a session token (alias)
|
||||||
message.sessionToken = this.sessionTokenMap[this._currentSessionId];
|
message.sessionToken = this.sessionTokenMap[this._currentSessionId];
|
||||||
@ -521,18 +454,11 @@ Nfc.prototype = {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case "ConfigResponse":
|
case "ConfigResponse":
|
||||||
let target = this.targetsByRequestId[message.requestId];
|
|
||||||
if (!target) {
|
|
||||||
debug("No target for requestId: " + message.requestId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
delete this.targetsByRequestId[message.requestId];
|
|
||||||
|
|
||||||
if (message.status === NFC.NFC_SUCCESS) {
|
if (message.status === NFC.NFC_SUCCESS) {
|
||||||
this.powerLevel = message.powerLevel;
|
this.powerLevel = message.powerLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
target.sendAsyncMessage("NFC:ConfigResponse", message);
|
this.sendNfcResponse(message);
|
||||||
break;
|
break;
|
||||||
case "ConnectResponse": // Fall through.
|
case "ConnectResponse": // Fall through.
|
||||||
case "CloseResponse":
|
case "CloseResponse":
|
||||||
@ -540,10 +466,7 @@ Nfc.prototype = {
|
|||||||
case "ReadNDEFResponse":
|
case "ReadNDEFResponse":
|
||||||
case "MakeReadOnlyNDEFResponse":
|
case "MakeReadOnlyNDEFResponse":
|
||||||
case "WriteNDEFResponse":
|
case "WriteNDEFResponse":
|
||||||
message.sessionToken = this.sessionTokenMap[this._currentSessionId];
|
this.sendNfcResponse(message);
|
||||||
// Do not expose the actual session to the content
|
|
||||||
delete message.sessionId;
|
|
||||||
gMessageManager.sendNfcResponseMessage("NFC:" + message.type, message);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error("Don't know about this message type: " + message.type);
|
throw new Error("Don't know about this message type: " + message.type);
|
||||||
@ -599,21 +522,27 @@ Nfc.prototype = {
|
|||||||
|
|
||||||
switch (message.name) {
|
switch (message.name) {
|
||||||
case "NFC:GetDetailsNDEF":
|
case "NFC:GetDetailsNDEF":
|
||||||
|
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||||
this.sendToNfcService("getDetailsNDEF", message.json);
|
this.sendToNfcService("getDetailsNDEF", message.json);
|
||||||
break;
|
break;
|
||||||
case "NFC:ReadNDEF":
|
case "NFC:ReadNDEF":
|
||||||
|
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||||
this.sendToNfcService("readNDEF", message.json);
|
this.sendToNfcService("readNDEF", message.json);
|
||||||
break;
|
break;
|
||||||
case "NFC:WriteNDEF":
|
case "NFC:WriteNDEF":
|
||||||
|
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||||
this.sendToNfcService("writeNDEF", message.json);
|
this.sendToNfcService("writeNDEF", message.json);
|
||||||
break;
|
break;
|
||||||
case "NFC:MakeReadOnlyNDEF":
|
case "NFC:MakeReadOnlyNDEF":
|
||||||
|
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||||
this.sendToNfcService("makeReadOnlyNDEF", message.json);
|
this.sendToNfcService("makeReadOnlyNDEF", message.json);
|
||||||
break;
|
break;
|
||||||
case "NFC:Connect":
|
case "NFC:Connect":
|
||||||
|
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||||
this.sendToNfcService("connect", message.json);
|
this.sendToNfcService("connect", message.json);
|
||||||
break;
|
break;
|
||||||
case "NFC:Close":
|
case "NFC:Close":
|
||||||
|
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||||
this.sendToNfcService("close", message.json);
|
this.sendToNfcService("close", message.json);
|
||||||
break;
|
break;
|
||||||
case "NFC:SendFile":
|
case "NFC:SendFile":
|
||||||
@ -622,6 +551,7 @@ Nfc.prototype = {
|
|||||||
// and system app that handles the system message :
|
// and system app that handles the system message :
|
||||||
// 'nfc-manager-send-file'. System app subsequently handover's
|
// 'nfc-manager-send-file'. System app subsequently handover's
|
||||||
// the data to alternate carrier's (BT / WiFi) 'sendFile' interface.
|
// the data to alternate carrier's (BT / WiFi) 'sendFile' interface.
|
||||||
|
this.targetsByRequestId[message.json.requestId] = message.target;
|
||||||
|
|
||||||
// Notify system app to initiate BT send file operation
|
// Notify system app to initiate BT send file operation
|
||||||
gSystemMessenger.broadcastMessage("nfc-manager-send-file",
|
gSystemMessenger.broadcastMessage("nfc-manager-send-file",
|
||||||
|
@ -93,6 +93,7 @@ this.NFC_ERROR_FAIL_DISABLE_LOW_POWER_MODE = -31;
|
|||||||
this.NFC_GECKO_ERROR_GENERIC_FAILURE = 1;
|
this.NFC_GECKO_ERROR_GENERIC_FAILURE = 1;
|
||||||
this.NFC_GECKO_ERROR_P2P_REG_INVALID = 2;
|
this.NFC_GECKO_ERROR_P2P_REG_INVALID = 2;
|
||||||
this.NFC_GECKO_ERROR_NOT_ENABLED = 3;
|
this.NFC_GECKO_ERROR_NOT_ENABLED = 3;
|
||||||
|
this.NFC_GECKO_ERROR_SEND_FILE_FAILED = 4;
|
||||||
|
|
||||||
this.NFC_ERROR_MSG = {};
|
this.NFC_ERROR_MSG = {};
|
||||||
this.NFC_ERROR_MSG[this.NFC_ERROR_IO] = "NfcIoError";
|
this.NFC_ERROR_MSG[this.NFC_ERROR_IO] = "NfcIoError";
|
||||||
@ -129,6 +130,7 @@ this.NFC_ERROR_MSG[this.NFC_ERROR_FAIL_DISABLE_LOW_POWER_MODE] = "DisableLowPowe
|
|||||||
this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_GENERIC_FAILURE] = "NfcGenericFailureError";
|
this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_GENERIC_FAILURE] = "NfcGenericFailureError";
|
||||||
this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_P2P_REG_INVALID] = "NfcP2PRegistrationInvalid";
|
this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_P2P_REG_INVALID] = "NfcP2PRegistrationInvalid";
|
||||||
this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_NOT_ENABLED] = "NfcNotEnabledError";
|
this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_NOT_ENABLED] = "NfcNotEnabledError";
|
||||||
|
this.NFC_ERROR_MSG[this.NFC_GECKO_ERROR_SEND_FILE_FAILED] = "NfcSendFileFailed";
|
||||||
|
|
||||||
// NFC powerlevels must match config PDUs.
|
// NFC powerlevels must match config PDUs.
|
||||||
this.NFC_POWER_LEVEL_UNKNOWN = -1;
|
this.NFC_POWER_LEVEL_UNKNOWN = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user