Commit 4094084a authored by Leon Han's avatar Leon Han Committed by Commit Bot

[webnfc] Remove compatibility check

The spec change:
https://github.com/w3c/web-nfc/issues/328

BUG=520391

Change-Id: Ida8e5d87ef25dc5b194d0cb4aa65104cfafc8614
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1806357Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarRijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Commit-Queue: Leon Han <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#697444}
parent 31ebfa39
......@@ -23,7 +23,6 @@ import android.util.SparseArray;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.device.mojom.NdefCompatibility;
import org.chromium.device.mojom.NdefMessage;
import org.chromium.device.mojom.Nfc;
import org.chromium.device.mojom.NfcClient;
......@@ -340,22 +339,6 @@ public class NfcImpl implements Nfc {
mPushResponseCallback = callback;
}
/**
* Check if the NFC device matches the |compatibility| field in |options|.
*
* @param compatibility denotes the compatibility kind of the found NFC device.
* @return boolean true if NFC the compatibility matches.
*/
boolean checkCompatibility(int compatibility) {
// 'nfc-forum' option can only push messages to NFC standard devices and 'vendor'
// option can only push to vendor specific ones.
if (nfcPushOptions.compatibility == NdefCompatibility.ANY
|| nfcPushOptions.compatibility == compatibility) {
return true;
}
return false;
}
/**
* Completes pending push operation.
*
......@@ -519,10 +502,6 @@ public class NfcImpl implements Nfc {
return;
}
if (!mPendingPushOperation.checkCompatibility(mTagHandler.compatibility())) {
return;
}
try {
mTagHandler.connect();
mTagHandler.write(NdefMessageUtils.toNdefMessage(mPendingPushOperation.ndefMessage));
......@@ -568,7 +547,7 @@ public class NfcImpl implements Nfc {
Log.w(TAG, "Cannot read data from NFC tag. NdefMessage exceeds allowed size.");
return;
}
notifyMatchingWatchers(message, mTagHandler.compatibility());
notifyMatchingWatchers(message);
} catch (TagLostException e) {
Log.w(TAG, "Cannot read data from NFC tag. Tag is lost.");
} catch (FormatException | IllegalStateException | IOException e) {
......@@ -580,13 +559,13 @@ public class NfcImpl implements Nfc {
* Iterates through active watchers and if any of those match NfcScanOptions criteria,
* delivers NdefMessage to the client.
*/
private void notifyMatchingWatchers(android.nfc.NdefMessage message, int compatibility) {
private void notifyMatchingWatchers(android.nfc.NdefMessage message) {
try {
NdefMessage ndefMessage = NdefMessageUtils.toNdefMessage(message);
List<Integer> watchIds = new ArrayList<Integer>();
for (int i = 0; i < mWatchers.size(); i++) {
NfcScanOptions options = mWatchers.valueAt(i);
if (matchesWatchOptions(ndefMessage, compatibility, options)) {
if (matchesWatchOptions(ndefMessage, options)) {
watchIds.add(mWatchers.keyAt(i));
}
}
......@@ -606,15 +585,7 @@ public class NfcImpl implements Nfc {
/**
* Implements matching algorithm.
*/
private boolean matchesWatchOptions(
NdefMessage message, int compatibility, NfcScanOptions options) {
// 'nfc-forum' option can only read messages from NFC standard devices and 'vendor' option
// can only read from vendor specific ones.
if (options.compatibility != NdefCompatibility.ANY
&& options.compatibility != compatibility) {
return false;
}
private boolean matchesWatchOptions(NdefMessage message, NfcScanOptions options) {
// Filter by WebNfc watch Id.
if (!matchesWebNfcId(message.url, options.url)) return false;
......
......@@ -12,15 +12,12 @@ import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.nfc.tech.TagTechnology;
import org.chromium.device.mojom.NdefCompatibility;
import java.io.IOException;
/**
* Utility class that provides I/O operations for NFC tags.
*/
public class NfcTagHandler {
private final int mCompatibility;
private final TagTechnology mTech;
private final TagTechnologyHandler mTechHandler;
private boolean mWasConnected;
......@@ -37,19 +34,14 @@ public class NfcTagHandler {
Ndef ndef = Ndef.get(tag);
if (ndef != null) {
int compatibility = NdefCompatibility.VENDOR;
String type = ndef.getType();
if (type.equals(Ndef.NFC_FORUM_TYPE_1) || type.equals(Ndef.NFC_FORUM_TYPE_2)
|| type.equals(Ndef.NFC_FORUM_TYPE_3) || type.equals(Ndef.NFC_FORUM_TYPE_4)) {
compatibility = NdefCompatibility.NFC_FORUM;
}
return new NfcTagHandler(compatibility, ndef, new NdefHandler(ndef), tag.getId());
return new NfcTagHandler(ndef, new NdefHandler(ndef), tag.getId());
}
NdefFormatable formattable = NdefFormatable.get(tag);
if (formattable != null) {
return new NfcTagHandler(NdefCompatibility.VENDOR, formattable,
new NdefFormattableHandler(formattable), tag.getId());
return new NfcTagHandler(
formattable, new NdefFormattableHandler(formattable), tag.getId());
}
return null;
......@@ -113,9 +105,7 @@ public class NfcTagHandler {
}
}
protected NfcTagHandler(
int compatibility, TagTechnology tech, TagTechnologyHandler handler, byte[] id) {
mCompatibility = compatibility;
protected NfcTagHandler(TagTechnology tech, TagTechnologyHandler handler, byte[] id) {
mTech = tech;
mTechHandler = handler;
mSerialNumber = bytesToSerialNumber(id);
......@@ -193,12 +183,4 @@ public class NfcTagHandler {
}
return false;
}
/**
* Returns NdefCompatibility.NFC_FORUM if the tag has a NFC standard type, otherwise returns
* NdefCompatibility.VENDOR.
*/
public int compatibility() {
return mCompatibility;
}
}
......@@ -30,16 +30,6 @@ enum NFCPushTarget {
ANY
};
enum NDEFCompatibility {
// Allows all active and passive NFC devices, supported by the NFC standard.
NFC_FORUM,
// Allows vendor specific NFC tags (passive device) that require specific
// reader chips.
VENDOR,
// Allows all NDEF compatible devices that the reader chip can read.
ANY
};
struct NFCError {
NFCErrorType error_type;
};
......@@ -78,9 +68,6 @@ struct NFCPushOptions {
// If the property is true, the push operation will suspend active watchers
// until its completion.
bool ignore_read;
// Defines the accepted kinds of NFC devices.
NDEFCompatibility compatibility;
};
struct NDEFRecordTypeFilter {
......@@ -96,9 +83,6 @@ struct NFCScanOptions {
// Defines media type filtering constraint.
string? media_type;
// Defines the accepted kinds of NFC devices.
NDEFCompatibility compatibility;
};
interface NFC {
......
......@@ -11,5 +11,4 @@ dictionary NFCPushOptions {
unrestricted double timeout; // in ms
boolean ignoreRead = true;
AbortSignal? signal;
NDEFCompatibility compatibility = "nfc-forum";
};
......@@ -2,15 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// http://w3c.github.io/web-nfc/#dom-ndefcompatibility
enum NDEFCompatibility { "nfc-forum", "vendor", "any" };
// https://w3c.github.io/web-nfc/#the-nfcscanoptions-dictionary
dictionary NFCScanOptions {
AbortSignal? signal;
USVString url = "";
NDEFRecordType? recordType;
USVString mediaType = "";
NDEFCompatibility compatibility = "nfc-forum";
};
......@@ -52,13 +52,10 @@ TypeConverter<NFCPushOptionsPtr, const blink::NFCPushOptions*>::Convert(
const blink::NFCPushOptions* pushOptions) {
// https://w3c.github.io/web-nfc/#the-nfcpushoptions-dictionary
// Default values for NFCPushOptions dictionary are:
// target = 'any', timeout = Infinity, ignoreRead = true,
// compatibility = "nfc-forum"
// target = 'any', timeout = Infinity, ignoreRead = true
NFCPushOptionsPtr pushOptionsPtr = NFCPushOptions::New();
pushOptionsPtr->target = blink::StringToNFCPushTarget(pushOptions->target());
pushOptionsPtr->ignore_read = pushOptions->ignoreRead();
pushOptionsPtr->compatibility =
blink::StringToNDEFCompatibility(pushOptions->compatibility());
if (pushOptions->hasTimeout())
pushOptionsPtr->timeout = pushOptions->timeout();
......@@ -73,12 +70,10 @@ TypeConverter<NFCScanOptionsPtr, const blink::NFCScanOptions*>::Convert(
const blink::NFCScanOptions* scanOptions) {
// https://w3c.github.io/web-nfc/#dom-nfcscanoptions
// Default values for NFCScanOptions dictionary are:
// url = "", recordType = null, mediaType = "", compatibility = "nfc-forum"
// url = "", recordType = null, mediaType = ""
NFCScanOptionsPtr scanOptionsPtr = NFCScanOptions::New();
scanOptionsPtr->url = scanOptions->url();
scanOptionsPtr->media_type = scanOptions->mediaType();
scanOptionsPtr->compatibility =
blink::StringToNDEFCompatibility(scanOptions->compatibility());
if (scanOptions->hasRecordType()) {
scanOptionsPtr->record_filter = NDEFRecordTypeFilter::New();
......
......@@ -13,7 +13,6 @@
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
using device::mojom::blink::NDEFCompatibility;
using device::mojom::blink::NFCPushTarget;
namespace blink {
......@@ -39,20 +38,6 @@ bool SetNDEFMessageURL(const String& origin,
return origin_url.IsValid();
}
NDEFCompatibility StringToNDEFCompatibility(const String& compatibility) {
if (compatibility == "nfc-forum")
return NDEFCompatibility::NFC_FORUM;
if (compatibility == "vendor")
return NDEFCompatibility::VENDOR;
if (compatibility == "any")
return NDEFCompatibility::ANY;
NOTREACHED();
return NDEFCompatibility::NFC_FORUM;
}
NFCPushTarget StringToNFCPushTarget(const String& target) {
if (target == "tag")
return NFCPushTarget::TAG;
......
......@@ -20,9 +20,6 @@ size_t GetNDEFMessageSize(const device::mojom::blink::NDEFMessage& message);
bool SetNDEFMessageURL(const String& origin,
device::mojom::blink::NDEFMessage* message);
device::mojom::blink::NDEFCompatibility StringToNDEFCompatibility(
const WTF::String& compatibility);
device::mojom::blink::NFCPushTarget StringToNFCPushTarget(
const WTF::String& target);
......
......@@ -11,14 +11,6 @@ function toMojoNFCPushTarget(target) {
return device.mojom.NFCPushTarget.ANY;
}
function toMojoNDEFCompatibility(compatibility) {
if (compatibility === 'nfc-forum')
return device.mojom.NDEFCompatibility.NFC_FORUM;
if (compatibility === 'vendor')
return device.mojom.NDEFCompatibility.VENDOR;
return device.mojom.NDEFCompatibility.ANY;
}
// Converts between NDEFMessageInit https://w3c.github.io/web-nfc/#dom-ndefmessage
// and mojom.NDEFMessage structure, so that watch function can be tested.
function toMojoNDEFMessage(message) {
......@@ -90,14 +82,6 @@ function assertNFCPushOptionsEqual(provided, received) {
assert_equals(toMojoNFCPushTarget(provided.target), received.target);
else
assert_equals(received.target, device.mojom.NFCPushTarget.ANY);
if (provided.compatibility !== undefined) {
assert_equals(toMojoNDEFCompatibility(provided.compatibility),
received.compatibility);
} else {
assert_equals(received.compatibility,
device.mojom.NDEFCompatibility.NFC_FORUM);
}
}
// Compares NFCReaderOptions structures that were provided to API and
......@@ -113,29 +97,14 @@ function assertNFCReaderOptionsEqual(provided, received) {
else
assert_equals(received.mediaType, '');
if (provided.compatibility !== undefined) {
assert_equals(toMojoNDEFCompatibility(provided.compatibility),
received.compatibility);
} else {
assert_equals(received.compatibility,
device.mojom.NDEFCompatibility.NFC_FORUM);
}
if (provided.recordType !== undefined) {
assert_equals(!+received.record_filter, true);
assert_equals(provided.recordType, received.recordFilter.recordType);
}
}
// Checks whether NFCReaderOptions are matched with given message
// and mock nfc's compatibility
function matchesWatchOptions(message, compatibility, options) {
// Filter by NDEFCompatibility
if (options.compatibility !== toMojoNDEFCompatibility("any")
&& options.compatibility !== compatibility) {
return false;
}
// Checks whether NFCReaderOptions are matched with given message.
function matchesWatchOptions(message, options) {
// Filter by Web NFC id
if (!matchesWebNfcId(message.url, options.url)) return false;
......@@ -255,10 +224,9 @@ var WebNFCTest = (() => {
this.watchers_.push({id: id, options: options});
// Triggers onWatch if the new watcher matches existing messages
for (let message of this.reading_messages_) {
if (matchesWatchOptions(
message.message, message.compatibility, options)) {
if (matchesWatchOptions(message, options)) {
this.client_.onWatch(
[id], fake_tag_serial_number, toMojoNDEFMessage(message.message));
[id], fake_tag_serial_number, toMojoNDEFMessage(message));
}
}
......@@ -335,19 +303,16 @@ var WebNFCTest = (() => {
this.push_should_timeout_ = false;
}
// Sets message that is used to deliver NFC reading updates
// with a specific NDEFCompatibility.
setReadingMessage(message, compatibility = 'nfc-forum') {
this.reading_messages_.push({message: message,
compatibility: toMojoNDEFCompatibility(compatibility)});
// Sets message that is used to deliver NFC reading updates.
setReadingMessage(message) {
this.reading_messages_.push(message);
// Ignore reading if NFCPushOptions.ignoreRead is true
let ignoreRead = false;
if(this.push_options_ && this.push_options_.ignoreRead)
ignoreRead = this.push_options_.ignoreRead;
// Triggers onWatch if the new message matches existing watchers
for (let watcher of this.watchers_) {
if (!ignoreRead && matchesWatchOptions(
message, toMojoNDEFCompatibility(compatibility), watcher.options)) {
if (!ignoreRead && matchesWatchOptions(message, watcher.options)) {
this.client_.onWatch(
[watcher.id], fake_tag_serial_number,
toMojoNDEFMessage(message));
......
......@@ -61,13 +61,6 @@ const NFCReaderOptionTests =
scanOptions: {mediaType: "application/octet-stream"},
unmatchedScanOptions: {mediaType: "application/json"},
message: createMessage([createOpaqueRecord(test_buffer_data)])
},
{
desc: "Test that the compatibility of NFCScanOptions filters relevant data" +
" sources correctly.",
scanOptions: {compatibility: "vendor"},
unmatchedScanOptions: {compatibility: "nfc-forum"},
message: createMessage([createTextRecord(test_text_data)]),
}
];
......@@ -123,14 +116,6 @@ const ReadMultiMessagesTests =
scanOptions: {mediaType: "application/octet-stream"},
message: createMessage([createOpaqueRecord(test_buffer_data)]),
unmatchedMessage: createMessage([createJsonRecord(test_json_data)])
},
{
desc: "Test that filtering 'text' record from different messages" +
" correctly with NFCScanOptions' compatibility set.",
scanOptions: {compatibility: "nfc-forum"},
message: createMessage([createTextRecord(test_text_data)]),
unmatchedMessage: createMessage([createJsonRecord(test_json_data)]),
unmatchedCompatibility: "vendor"
}
];
......@@ -144,16 +129,10 @@ for (let NFCReaderOptionTest of NFCReaderOptionTests) {
}
for (let readMultiMessagesTest of ReadMultiMessagesTests) {
// Sets default message's associated compatibility
let unmatchedCompatibility = "nfc-forum";
if(readMultiMessagesTest.unmatchedCompatibility)
unmatchedCompatibility = readMultiMessagesTest.unmatchedCompatibility;
testReadingMultiMessages(
readMultiMessagesTest.message,
readMultiMessagesTest.scanOptions,
readMultiMessagesTest.unmatchedMessage,
unmatchedCompatibility,
readMultiMessagesTest.desc
);
}
......
......@@ -12,8 +12,7 @@ The `WebNFCTest` interface is defined as:
class MockNFC {
setHWStatus(number status); // Sets the hardware status.
setCompatibility(NDEFCompatibility compatibility); // Sets NDEF accepted compatible devices
setReadingMessage(NDEFMessageInit message, NDEFCompatibility compatibility); // Sets message that is used to deliver NFC reading updates with a specific NDEFCompatibility.
setReadingMessage(NDEFMessageInit message); // Sets message that is used to deliver NFC reading updates.
setPendingPushCompleted(boolean result); // Sets if the pending push is completed.
setPushShouldTimeout(boolean result); // Sets flag to trigger the pending push to timeout.
pushedMessage(); // Gets the pushed `NDEFMessageSource`.
......
......@@ -111,8 +111,8 @@ function createUrlRecord(url) {
return createRecord('url', 'text/plain', url);
}
function createNFCPushOptions(target, timeout, ignoreRead, compatibility) {
return { target, timeout, ignoreRead, compatibility};
function createNFCPushOptions(target, timeout, ignoreRead) {
return {target, timeout, ignoreRead};
}
// Compares NDEFMessageSource that was provided to the API
......@@ -178,7 +178,7 @@ function testNFCScanOptions(message, scanOptions, unmatchedScanOptions, desc) {
const reader2 = new NFCReader();
const controller = new AbortController();
mockNFC.setReadingMessage(message, scanOptions.compatibility);
mockNFC.setReadingMessage(message);
// Reading from unmatched reader will not be triggered
reader1.onreading = t.unreached_func("reading event should not be fired.");
......@@ -198,8 +198,8 @@ function testNFCScanOptions(message, scanOptions, unmatchedScanOptions, desc) {
}, desc);
}
function testReadingMultiMessages(message, scanOptions, unmatchedMessage,
unmatchedCompatibility, desc) {
function testReadingMultiMessages(
message, scanOptions, unmatchedMessage, desc) {
nfc_test(async (t, mockNFC) => {
const reader = new NFCReader();
const controller = new AbortController();
......@@ -214,7 +214,7 @@ function testReadingMultiMessages(message, scanOptions, unmatchedMessage,
reader.scan(scanOptions);
// Unmatched message will not be read
mockNFC.setReadingMessage(unmatchedMessage, unmatchedCompatibility);
mockNFC.setReadingMessage(unmatchedMessage);
mockNFC.setReadingMessage(message);
await promise;
......
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