mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1086179 - Add a format API to MozNFCTag. r=smaug, allstars.chh
This commit is contained in:
parent
e15ddbe351
commit
801c5023ea
@ -54,6 +54,7 @@ const NFC_IPC_MSG_NAMES = [
|
||||
"NFC:ReadNDEFResponse",
|
||||
"NFC:WriteNDEFResponse",
|
||||
"NFC:MakeReadOnlyResponse",
|
||||
"NFC:FormatResponse",
|
||||
"NFC:ConnectResponse",
|
||||
"NFC:CloseResponse",
|
||||
"NFC:CheckP2PRegistrationResponse",
|
||||
@ -176,6 +177,18 @@ NfcContentHelper.prototype = {
|
||||
return request;
|
||||
},
|
||||
|
||||
format: function format(sessionToken) {
|
||||
let request = Services.DOMRequest.createRequest(this._window);
|
||||
let requestId = btoa(this.getRequestId(request));
|
||||
this._requestMap[requestId] = this._window;
|
||||
|
||||
cpmm.sendAsyncMessage("NFC:Format", {
|
||||
requestId: requestId,
|
||||
sessionToken: sessionToken
|
||||
});
|
||||
return request;
|
||||
},
|
||||
|
||||
connect: function connect(techType, sessionToken) {
|
||||
let request = Services.DOMRequest.createRequest(this._window);
|
||||
let requestId = btoa(this.getRequestId(request));
|
||||
@ -322,6 +335,7 @@ NfcContentHelper.prototype = {
|
||||
case "NFC:CloseResponse":
|
||||
case "NFC:WriteNDEFResponse":
|
||||
case "NFC:MakeReadOnlyResponse":
|
||||
case "NFC:FormatResponse":
|
||||
case "NFC:NotifySendFileStatusResponse":
|
||||
case "NFC:ChangeRFStateResponse":
|
||||
if (result.errorMsg) {
|
||||
|
@ -71,6 +71,7 @@ const NFC_IPC_READ_PERM_MSG_NAMES = [
|
||||
const NFC_IPC_WRITE_PERM_MSG_NAMES = [
|
||||
"NFC:WriteNDEF",
|
||||
"NFC:MakeReadOnly",
|
||||
"NFC:Format",
|
||||
"NFC:SendFile",
|
||||
"NFC:RegisterPeerReadyTarget",
|
||||
"NFC:UnregisterPeerReadyTarget"
|
||||
@ -564,6 +565,7 @@ Nfc.prototype = {
|
||||
case "CloseResponse":
|
||||
case "ReadNDEFResponse":
|
||||
case "MakeReadOnlyResponse":
|
||||
case "FormatResponse":
|
||||
case "WriteNDEFResponse":
|
||||
this.sendNfcResponse(message);
|
||||
break;
|
||||
@ -622,6 +624,9 @@ Nfc.prototype = {
|
||||
case "NFC:MakeReadOnly":
|
||||
this.sendToNfcService("makeReadOnly", message.data);
|
||||
break;
|
||||
case "NFC:Format":
|
||||
this.sendToNfcService("format", message.data);
|
||||
break;
|
||||
case "NFC:Connect":
|
||||
this.sendToNfcService("connect", message.data);
|
||||
break;
|
||||
|
@ -8,7 +8,7 @@
|
||||
namespace mozilla {
|
||||
|
||||
#define NFCD_MAJOR_VERSION 1
|
||||
#define NFCD_MINOR_VERSION 16
|
||||
#define NFCD_MINOR_VERSION 17
|
||||
|
||||
enum NfcRequest {
|
||||
ChangeRFStateReq = 0,
|
||||
@ -17,6 +17,7 @@ enum NfcRequest {
|
||||
ReadNDEFReq,
|
||||
WriteNDEFReq,
|
||||
MakeReadOnlyReq,
|
||||
FormatReq,
|
||||
};
|
||||
|
||||
enum NfcResponse {
|
||||
|
@ -20,6 +20,7 @@ static const char* kChangeRFStateRequest = "changeRFState";
|
||||
static const char* kReadNDEFRequest = "readNDEF";
|
||||
static const char* kWriteNDEFRequest = "writeNDEF";
|
||||
static const char* kMakeReadOnlyRequest = "makeReadOnly";
|
||||
static const char* kFormatRequest = "format";
|
||||
static const char* kConnectRequest = "connect";
|
||||
static const char* kCloseRequest = "close";
|
||||
|
||||
@ -27,6 +28,7 @@ static const char* kChangeRFStateResponse = "ChangeRFStateResponse";
|
||||
static const char* kReadNDEFResponse = "ReadNDEFResponse";
|
||||
static const char* kWriteNDEFResponse = "WriteNDEFResponse";
|
||||
static const char* kMakeReadOnlyResponse = "MakeReadOnlyResponse";
|
||||
static const char* kFormatResponse = "FormatResponse";
|
||||
static const char* kConnectResponse = "ConnectResponse";
|
||||
static const char* kCloseResponse = "CloseResponse";
|
||||
|
||||
@ -52,6 +54,9 @@ NfcMessageHandler::Marshall(Parcel& aParcel, const CommandOptions& aOptions)
|
||||
} else if (!strcmp(type, kMakeReadOnlyRequest)) {
|
||||
result = MakeReadOnlyRequest(aParcel, aOptions);
|
||||
mPendingReqQueue.AppendElement(NfcRequest::MakeReadOnlyReq);
|
||||
} else if (!strcmp(type, kFormatRequest)) {
|
||||
result = FormatRequest(aParcel, aOptions);
|
||||
mPendingReqQueue.AppendElement(NfcRequest::FormatReq);
|
||||
} else if (!strcmp(type, kConnectRequest)) {
|
||||
result = ConnectRequest(aParcel, aOptions);
|
||||
mPendingReqQueue.AppendElement(NfcRequest::ConnectReq);
|
||||
@ -117,6 +122,9 @@ NfcMessageHandler::GeneralResponse(const Parcel& aParcel, EventOptions& aOptions
|
||||
case NfcRequest::MakeReadOnlyReq:
|
||||
type = kMakeReadOnlyResponse;
|
||||
break;
|
||||
case NfcRequest::FormatReq:
|
||||
type = kFormatResponse;
|
||||
break;
|
||||
case NfcRequest::ConnectReq:
|
||||
type = kConnectResponse;
|
||||
break;
|
||||
@ -207,6 +215,15 @@ NfcMessageHandler::MakeReadOnlyRequest(Parcel& aParcel, const CommandOptions& aO
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
NfcMessageHandler::FormatRequest(Parcel& aParcel, const CommandOptions& aOptions)
|
||||
{
|
||||
aParcel.writeInt32(NfcRequest::FormatReq);
|
||||
aParcel.writeInt32(aOptions.mSessionId);
|
||||
mRequestIdQueue.AppendElement(aOptions.mRequestId);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
NfcMessageHandler::ConnectRequest(Parcel& aParcel, const CommandOptions& aOptions)
|
||||
{
|
||||
|
@ -31,6 +31,7 @@ private:
|
||||
bool ReadNDEFResponse(const android::Parcel& aParcel, EventOptions& aOptions);
|
||||
bool WriteNDEFRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||
bool MakeReadOnlyRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||
bool FormatRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||
bool ConnectRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||
bool CloseRequest(android::Parcel& aParcel, const CommandOptions& options);
|
||||
|
||||
|
@ -65,7 +65,7 @@ interface nsINfcEventListener : nsISupports
|
||||
void notifyPeerLost(in DOMString sessionToken);
|
||||
};
|
||||
|
||||
[scriptable, uuid(486dff99-6755-428b-834d-3647ce276b54)]
|
||||
[scriptable, uuid(9343ae1a-6e2f-11e4-b5c4-fbb166b38b62)]
|
||||
interface nsINfcContentHelper : nsISupports
|
||||
{
|
||||
void init(in nsIDOMWindow window);
|
||||
@ -75,6 +75,7 @@ interface nsINfcContentHelper : nsISupports
|
||||
nsIDOMDOMRequest readNDEF(in DOMString sessionToken);
|
||||
nsIDOMDOMRequest writeNDEF(in nsIVariant records, in DOMString sessionToken);
|
||||
nsIDOMDOMRequest makeReadOnly(in DOMString sessionToken);
|
||||
nsIDOMDOMRequest format(in DOMString sessionToken);
|
||||
|
||||
nsIDOMDOMRequest connect(in unsigned long techType, in DOMString sessionToken);
|
||||
nsIDOMDOMRequest close(in DOMString sessionToken);
|
||||
|
@ -101,6 +101,19 @@ MozNFCTagImpl.prototype = {
|
||||
return this._nfcContentHelper.makeReadOnly(this.session);
|
||||
},
|
||||
|
||||
format: function format() {
|
||||
if (this.isLost) {
|
||||
throw new this._window.DOMError("InvalidStateError", "NFCTag object is invalid");
|
||||
}
|
||||
|
||||
if (!this.isFormatable) {
|
||||
throw new this._window.DOMError("InvalidAccessError",
|
||||
"NFCTag object is not formatable");
|
||||
}
|
||||
|
||||
return this._nfcContentHelper.format(this.session);
|
||||
},
|
||||
|
||||
classID: Components.ID("{4e1e2e90-3137-11e3-aa6e-0800200c9a66}"),
|
||||
contractID: "@mozilla.org/nfc/NFCTag;1",
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
||||
|
@ -74,6 +74,9 @@ interface MozNFCTag {
|
||||
|
||||
[Throws]
|
||||
DOMRequest makeReadOnly();
|
||||
|
||||
[Throws]
|
||||
DOMRequest format();
|
||||
};
|
||||
|
||||
// Mozilla Only
|
||||
|
Loading…
Reference in New Issue
Block a user