mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 993891 - B2G NFC: NFC_IPC_MSG_NAMES in Nfc.js is handled twice. r=dimi
This commit is contained in:
parent
f71172786b
commit
48264d7a72
@ -45,22 +45,25 @@ const NFC_CID =
|
||||
Components.ID("{2ff24790-5e74-11e1-b86c-0800200c9a66}");
|
||||
|
||||
const NFC_IPC_MSG_NAMES = [
|
||||
"NFC:SetSessionToken",
|
||||
"NFC:ReadNDEF",
|
||||
"NFC:WriteNDEF",
|
||||
"NFC:GetDetailsNDEF",
|
||||
"NFC:MakeReadOnlyNDEF",
|
||||
"NFC:Connect",
|
||||
"NFC:Close",
|
||||
"NFC:SendFile"
|
||||
"NFC:SetSessionToken"
|
||||
];
|
||||
|
||||
const NFC_IPC_PEER_MSG_NAMES = [
|
||||
const NFC_IPC_READ_PERM_MSG_NAMES = [
|
||||
"NFC:ReadNDEF",
|
||||
"NFC:GetDetailsNDEF",
|
||||
"NFC:Connect",
|
||||
"NFC:Close",
|
||||
];
|
||||
|
||||
const NFC_IPC_WRITE_PERM_MSG_NAMES = [
|
||||
"NFC:WriteNDEF",
|
||||
"NFC:MakeReadOnlyNDEF",
|
||||
"NFC:SendFile",
|
||||
"NFC:RegisterPeerTarget",
|
||||
"NFC:UnregisterPeerTarget"
|
||||
];
|
||||
|
||||
const NFC_IPC_MANAGER_MSG_NAMES = [
|
||||
const NFC_IPC_MANAGER_PERM_MSG_NAMES = [
|
||||
"NFC:CheckP2PRegistration",
|
||||
"NFC:NotifyUserAcceptedP2P",
|
||||
"NFC:NotifySendFileStatus"
|
||||
@ -100,43 +103,53 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
||||
init: function init(nfc) {
|
||||
this.nfc = nfc;
|
||||
|
||||
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
||||
Services.obs.addObserver(this, NFC.TOPIC_XPCOM_SHUTDOWN, false);
|
||||
this._registerMessageListeners();
|
||||
},
|
||||
|
||||
_shutdown: function _shutdown() {
|
||||
this.nfc = null;
|
||||
|
||||
Services.obs.removeObserver(this, "xpcom-shutdown");
|
||||
Services.obs.removeObserver(this, NFC.TOPIC_XPCOM_SHUTDOWN);
|
||||
this._unregisterMessageListeners();
|
||||
},
|
||||
|
||||
_registerMessageListeners: function _registerMessageListeners() {
|
||||
ppmm.addMessageListener("child-process-shutdown", this);
|
||||
|
||||
for (let msgname of NFC_IPC_MSG_NAMES) {
|
||||
ppmm.addMessageListener(msgname, this);
|
||||
}
|
||||
|
||||
for (let msgname of NFC_IPC_PEER_MSG_NAMES) {
|
||||
for (let msgname of NFC_IPC_READ_PERM_MSG_NAMES) {
|
||||
ppmm.addMessageListener(msgname, this);
|
||||
}
|
||||
|
||||
for (let msgname of NFC_IPC_MANAGER_MSG_NAMES) {
|
||||
for (let msgname of NFC_IPC_WRITE_PERM_MSG_NAMES) {
|
||||
ppmm.addMessageListener(msgname, this);
|
||||
}
|
||||
|
||||
for (let msgname of NFC_IPC_MANAGER_PERM_MSG_NAMES) {
|
||||
ppmm.addMessageListener(msgname, this);
|
||||
}
|
||||
},
|
||||
|
||||
_unregisterMessageListeners: function _unregisterMessageListeners() {
|
||||
ppmm.removeMessageListener("child-process-shutdown", this);
|
||||
|
||||
for (let msgname of NFC_IPC_MSG_NAMES) {
|
||||
ppmm.removeMessageListener(msgname, this);
|
||||
}
|
||||
|
||||
for (let msgname of NFC_IPC_PEER_MSG_NAMES) {
|
||||
for (let msgname of NFC_IPC_READ_PERM_MSG_NAMES) {
|
||||
ppmm.removeMessageListener(msgname, this);
|
||||
}
|
||||
|
||||
for (let msgname of NFC_IPC_MANAGER_MSG_NAMES) {
|
||||
for (let msgname of NFC_IPC_WRITE_PERM_MSG_NAMES) {
|
||||
ppmm.removeMessageListener(msgname, this);
|
||||
}
|
||||
|
||||
for (let msgname of NFC_IPC_MANAGER_PERM_MSG_NAMES) {
|
||||
ppmm.removeMessageListener(msgname, this);
|
||||
}
|
||||
|
||||
@ -310,18 +323,20 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
||||
}
|
||||
|
||||
if (NFC_IPC_MSG_NAMES.indexOf(msg.name) != -1) {
|
||||
// Do nothing.
|
||||
} else if (NFC_IPC_READ_PERM_MSG_NAMES.indexOf(msg.name) != -1) {
|
||||
if (!msg.target.assertPermission("nfc-read")) {
|
||||
debug("Nfc message " + msg.name +
|
||||
" from a content process with no 'nfc-read' privileges.");
|
||||
return null;
|
||||
}
|
||||
} else if (NFC_IPC_PEER_MSG_NAMES.indexOf(msg.name) != -1) {
|
||||
} else if (NFC_IPC_WRITE_PERM_MSG_NAMES.indexOf(msg.name) != -1) {
|
||||
if (!msg.target.assertPermission("nfc-write")) {
|
||||
debug("Nfc Peer message " + msg.name +
|
||||
" from a content process with no 'nfc-write' privileges.");
|
||||
return null;
|
||||
}
|
||||
} else if (NFC_IPC_MANAGER_MSG_NAMES.indexOf(msg.name) != -1) {
|
||||
} else if (NFC_IPC_MANAGER_PERM_MSG_NAMES.indexOf(msg.name) != -1) {
|
||||
if (!msg.target.assertPermission("nfc-manager")) {
|
||||
debug("NFC message " + message.name +
|
||||
" from a content process with no 'nfc-manager' privileges.");
|
||||
@ -337,13 +352,13 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
||||
this._registerMessageTarget(this.nfc.sessionTokenMap[this.nfc._currentSessionId], msg.target);
|
||||
debug("Registering target for this SessionToken : " +
|
||||
this.nfc.sessionTokenMap[this.nfc._currentSessionId]);
|
||||
break;
|
||||
return null;
|
||||
case "NFC:RegisterPeerTarget":
|
||||
this.registerPeerTarget(msg);
|
||||
break;
|
||||
return null;
|
||||
case "NFC:UnregisterPeerTarget":
|
||||
this.unregisterPeerTarget(msg);
|
||||
break;
|
||||
return null;
|
||||
case "NFC:CheckP2PRegistration":
|
||||
// Check if the application id is a valid registered target.
|
||||
// (It should have registered for NFC_PEER_EVENT_READY).
|
||||
@ -358,18 +373,19 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
||||
status: status,
|
||||
requestId: msg.json.requestId
|
||||
});
|
||||
break;
|
||||
return null;
|
||||
case "NFC:NotifyUserAcceptedP2P":
|
||||
// Notify the 'NFC_PEER_EVENT_READY' since user has acknowledged
|
||||
this.notifyPeerEvent(msg.json.appId, NFC.NFC_PEER_EVENT_READY);
|
||||
break;
|
||||
return null;
|
||||
case "NFC:NotifySendFileStatus":
|
||||
// Upon receiving the status of sendFile operation, send the response
|
||||
// to appropriate content process.
|
||||
this.sendNfcResponseMessage(msg.name + "Response", msg.json);
|
||||
break;
|
||||
return null;
|
||||
default:
|
||||
return this.nfc.receiveMessage(msg);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -378,7 +394,7 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
||||
|
||||
observe: function observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "xpcom-shutdown":
|
||||
case NFC.TOPIC_XPCOM_SHUTDOWN:
|
||||
this._shutdown();
|
||||
break;
|
||||
}
|
||||
@ -396,12 +412,7 @@ function Nfc() {
|
||||
this.worker.onerror = this.onerror.bind(this);
|
||||
this.worker.onmessage = this.onmessage.bind(this);
|
||||
|
||||
for each (let msgname in NFC_IPC_MSG_NAMES) {
|
||||
ppmm.addMessageListener(msgname, this);
|
||||
}
|
||||
|
||||
Services.obs.addObserver(this, NFC.TOPIC_MOZSETTINGS_CHANGED, false);
|
||||
Services.obs.addObserver(this, NFC.TOPIC_XPCOM_SHUTDOWN, false);
|
||||
Services.obs.addObserver(this, NFC.TOPIC_HARDWARE_STATE, false);
|
||||
|
||||
gMessageManager.init(this);
|
||||
@ -540,34 +551,6 @@ Nfc.prototype = {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Enforce bare minimums for NFC permissions
|
||||
switch (message.name) {
|
||||
case "NFC:Connect": // Fall through
|
||||
case "NFC:Close":
|
||||
case "NFC:GetDetailsNDEF":
|
||||
case "NFC:ReadNDEF":
|
||||
if (!message.target.assertPermission("nfc-read")) {
|
||||
debug("NFC message " + message.name +
|
||||
" from a content process with no 'nfc-read' privileges.");
|
||||
this.sendNfcErrorResponse(message);
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
case "NFC:WriteNDEF": // Fall through
|
||||
case "NFC:MakeReadOnlyNDEF":
|
||||
case "NFC:SendFile":
|
||||
if (!message.target.assertPermission("nfc-write")) {
|
||||
debug("NFC message " + message.name +
|
||||
" from a content process with no 'nfc-write' privileges.");
|
||||
this.sendNfcErrorResponse(message);
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
case "NFC:SetSessionToken":
|
||||
//Do nothing here. No need to process this message further
|
||||
return null;
|
||||
}
|
||||
|
||||
// Sanity check on sessionId
|
||||
if (message.json.sessionToken !== this.sessionTokenMap[this._currentSessionId]) {
|
||||
debug("Invalid Session Token: " + message.json.sessionToken +
|
||||
@ -613,6 +596,8 @@ Nfc.prototype = {
|
||||
debug("UnSupported : Message Name " + message.name);
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -634,13 +619,6 @@ Nfc.prototype = {
|
||||
|
||||
observe: function observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case NFC.TOPIC_XPCOM_SHUTDOWN:
|
||||
for each (let msgname in NFC_IPC_MSG_NAMES) {
|
||||
ppmm.removeMessageListener(msgname, this);
|
||||
}
|
||||
ppmm = null;
|
||||
Services.obs.removeObserver(this, NFC.TOPIC_XPCOM_SHUTDOWN);
|
||||
break;
|
||||
case NFC.TOPIC_MOZSETTINGS_CHANGED:
|
||||
let setting = JSON.parse(data);
|
||||
if (setting) {
|
||||
|
@ -99,10 +99,6 @@ NfcContentHelper.prototype = {
|
||||
_requestMap: null,
|
||||
peerEventsCallbackMap: null,
|
||||
|
||||
/* TODO: Bug 815526: This is a limitation when a DOMString is used in sequences of Moz DOM Objects.
|
||||
* Strings such as 'type', 'id' 'payload' will not be acccessible to NfcWorker.
|
||||
* Therefore this function exists till the bug is addressed.
|
||||
*/
|
||||
encodeNDEFRecords: function encodeNDEFRecords(records) {
|
||||
let encodedRecords = [];
|
||||
for (let i = 0; i < records.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user