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; ...@@ -23,7 +23,6 @@ import android.util.SparseArray;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.device.mojom.NdefCompatibility;
import org.chromium.device.mojom.NdefMessage; import org.chromium.device.mojom.NdefMessage;
import org.chromium.device.mojom.Nfc; import org.chromium.device.mojom.Nfc;
import org.chromium.device.mojom.NfcClient; import org.chromium.device.mojom.NfcClient;
...@@ -340,22 +339,6 @@ public class NfcImpl implements Nfc { ...@@ -340,22 +339,6 @@ public class NfcImpl implements Nfc {
mPushResponseCallback = callback; 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. * Completes pending push operation.
* *
...@@ -519,10 +502,6 @@ public class NfcImpl implements Nfc { ...@@ -519,10 +502,6 @@ public class NfcImpl implements Nfc {
return; return;
} }
if (!mPendingPushOperation.checkCompatibility(mTagHandler.compatibility())) {
return;
}
try { try {
mTagHandler.connect(); mTagHandler.connect();
mTagHandler.write(NdefMessageUtils.toNdefMessage(mPendingPushOperation.ndefMessage)); mTagHandler.write(NdefMessageUtils.toNdefMessage(mPendingPushOperation.ndefMessage));
...@@ -568,7 +547,7 @@ public class NfcImpl implements Nfc { ...@@ -568,7 +547,7 @@ public class NfcImpl implements Nfc {
Log.w(TAG, "Cannot read data from NFC tag. NdefMessage exceeds allowed size."); Log.w(TAG, "Cannot read data from NFC tag. NdefMessage exceeds allowed size.");
return; return;
} }
notifyMatchingWatchers(message, mTagHandler.compatibility()); notifyMatchingWatchers(message);
} catch (TagLostException e) { } catch (TagLostException e) {
Log.w(TAG, "Cannot read data from NFC tag. Tag is lost."); Log.w(TAG, "Cannot read data from NFC tag. Tag is lost.");
} catch (FormatException | IllegalStateException | IOException e) { } catch (FormatException | IllegalStateException | IOException e) {
...@@ -580,13 +559,13 @@ public class NfcImpl implements Nfc { ...@@ -580,13 +559,13 @@ public class NfcImpl implements Nfc {
* Iterates through active watchers and if any of those match NfcScanOptions criteria, * Iterates through active watchers and if any of those match NfcScanOptions criteria,
* delivers NdefMessage to the client. * delivers NdefMessage to the client.
*/ */
private void notifyMatchingWatchers(android.nfc.NdefMessage message, int compatibility) { private void notifyMatchingWatchers(android.nfc.NdefMessage message) {
try { try {
NdefMessage ndefMessage = NdefMessageUtils.toNdefMessage(message); NdefMessage ndefMessage = NdefMessageUtils.toNdefMessage(message);
List<Integer> watchIds = new ArrayList<Integer>(); List<Integer> watchIds = new ArrayList<Integer>();
for (int i = 0; i < mWatchers.size(); i++) { for (int i = 0; i < mWatchers.size(); i++) {
NfcScanOptions options = mWatchers.valueAt(i); NfcScanOptions options = mWatchers.valueAt(i);
if (matchesWatchOptions(ndefMessage, compatibility, options)) { if (matchesWatchOptions(ndefMessage, options)) {
watchIds.add(mWatchers.keyAt(i)); watchIds.add(mWatchers.keyAt(i));
} }
} }
...@@ -606,15 +585,7 @@ public class NfcImpl implements Nfc { ...@@ -606,15 +585,7 @@ public class NfcImpl implements Nfc {
/** /**
* Implements matching algorithm. * Implements matching algorithm.
*/ */
private boolean matchesWatchOptions( private boolean matchesWatchOptions(NdefMessage message, NfcScanOptions options) {
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;
}
// Filter by WebNfc watch Id. // Filter by WebNfc watch Id.
if (!matchesWebNfcId(message.url, options.url)) return false; if (!matchesWebNfcId(message.url, options.url)) return false;
......
...@@ -12,15 +12,12 @@ import android.nfc.tech.Ndef; ...@@ -12,15 +12,12 @@ import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable; import android.nfc.tech.NdefFormatable;
import android.nfc.tech.TagTechnology; import android.nfc.tech.TagTechnology;
import org.chromium.device.mojom.NdefCompatibility;
import java.io.IOException; import java.io.IOException;
/** /**
* Utility class that provides I/O operations for NFC tags. * Utility class that provides I/O operations for NFC tags.
*/ */
public class NfcTagHandler { public class NfcTagHandler {
private final int mCompatibility;
private final TagTechnology mTech; private final TagTechnology mTech;
private final TagTechnologyHandler mTechHandler; private final TagTechnologyHandler mTechHandler;
private boolean mWasConnected; private boolean mWasConnected;
...@@ -37,19 +34,14 @@ public class NfcTagHandler { ...@@ -37,19 +34,14 @@ public class NfcTagHandler {
Ndef ndef = Ndef.get(tag); Ndef ndef = Ndef.get(tag);
if (ndef != null) { if (ndef != null) {
int compatibility = NdefCompatibility.VENDOR;
String type = ndef.getType(); String type = ndef.getType();
if (type.equals(Ndef.NFC_FORUM_TYPE_1) || type.equals(Ndef.NFC_FORUM_TYPE_2) return new NfcTagHandler(ndef, new NdefHandler(ndef), tag.getId());
|| 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());
} }
NdefFormatable formattable = NdefFormatable.get(tag); NdefFormatable formattable = NdefFormatable.get(tag);
if (formattable != null) { if (formattable != null) {
return new NfcTagHandler(NdefCompatibility.VENDOR, formattable, return new NfcTagHandler(
new NdefFormattableHandler(formattable), tag.getId()); formattable, new NdefFormattableHandler(formattable), tag.getId());
} }
return null; return null;
...@@ -113,9 +105,7 @@ public class NfcTagHandler { ...@@ -113,9 +105,7 @@ public class NfcTagHandler {
} }
} }
protected NfcTagHandler( protected NfcTagHandler(TagTechnology tech, TagTechnologyHandler handler, byte[] id) {
int compatibility, TagTechnology tech, TagTechnologyHandler handler, byte[] id) {
mCompatibility = compatibility;
mTech = tech; mTech = tech;
mTechHandler = handler; mTechHandler = handler;
mSerialNumber = bytesToSerialNumber(id); mSerialNumber = bytesToSerialNumber(id);
...@@ -193,12 +183,4 @@ public class NfcTagHandler { ...@@ -193,12 +183,4 @@ public class NfcTagHandler {
} }
return false; return false;
} }
/**
* Returns NdefCompatibility.NFC_FORUM if the tag has a NFC standard type, otherwise returns
* NdefCompatibility.VENDOR.
*/
public int compatibility() {
return mCompatibility;
}
} }
...@@ -18,7 +18,6 @@ import static org.mockito.Mockito.doThrow; ...@@ -18,7 +18,6 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
...@@ -43,7 +42,6 @@ import org.chromium.base.ApiCompatibilityUtils; ...@@ -43,7 +42,6 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.device.mojom.NdefCompatibility;
import org.chromium.device.mojom.NdefMessage; import org.chromium.device.mojom.NdefMessage;
import org.chromium.device.mojom.NdefRecord; import org.chromium.device.mojom.NdefRecord;
import org.chromium.device.mojom.NdefRecordTypeFilter; import org.chromium.device.mojom.NdefRecordTypeFilter;
...@@ -458,78 +456,6 @@ public class NFCTest { ...@@ -458,78 +456,6 @@ public class NFCTest {
assertNull(mErrorCaptor.getValue()); assertNull(mErrorCaptor.getValue());
} }
/**
* Test that compatibility is checked for Nfc.push() with NFC_FORUM device.
*/
@Test
@Feature({"NFCTest"})
public void testPushCompatibilityMatchingNfcForum() {
TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate);
mDelegate.invokeCallback();
doReturn(NdefCompatibility.NFC_FORUM).when(mNfcTagHandler).compatibility();
// Should match, because |compatibility| is set to NdefCompatibility.ANY
// in createNfcPushOptions().
PushResponse mockCallback_1 = mock(PushResponse.class);
nfc.push(createMojoNdefMessage(), createNfcPushOptions(), mockCallback_1);
nfc.processPendingOperationsForTesting(mNfcTagHandler);
verify(mockCallback_1).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
// Should match.
PushResponse mockCallback_2 = mock(PushResponse.class);
NfcPushOptions options_2 = createNfcPushOptions();
options_2.compatibility = NdefCompatibility.NFC_FORUM;
nfc.push(createMojoNdefMessage(), options_2, mockCallback_2);
nfc.processPendingOperationsForTesting(mNfcTagHandler);
verify(mockCallback_2).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
// Should not match.
PushResponse mockCallback_3 = mock(PushResponse.class);
NfcPushOptions options_3 = createNfcPushOptions();
options_3.compatibility = NdefCompatibility.VENDOR;
nfc.push(createMojoNdefMessage(), options_3, mockCallback_3);
nfc.processPendingOperationsForTesting(mNfcTagHandler);
verifyZeroInteractions(mockCallback_3);
}
/**
* Test that compatibility is checked for Nfc.push() with VENDOR device.
*/
@Test
@Feature({"NFCTest"})
public void testPushCompatibilityMatchingVendor() {
TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate);
mDelegate.invokeCallback();
doReturn(NdefCompatibility.VENDOR).when(mNfcTagHandler).compatibility();
// Should match, because |compatibility| is set to NdefCompatibility.ANY
// in createNfcPushOptions().
PushResponse mockCallback_1 = mock(PushResponse.class);
nfc.push(createMojoNdefMessage(), createNfcPushOptions(), mockCallback_1);
nfc.processPendingOperationsForTesting(mNfcTagHandler);
verify(mockCallback_1).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
// Should match for NdefCompatibility.VENDOR.
PushResponse mockCallback_2 = mock(PushResponse.class);
NfcPushOptions options_2 = createNfcPushOptions();
options_2.compatibility = NdefCompatibility.VENDOR;
nfc.push(createMojoNdefMessage(), options_2, mockCallback_2);
nfc.processPendingOperationsForTesting(mNfcTagHandler);
verify(mockCallback_2).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
// Should not match.
PushResponse mockCallback_3 = mock(PushResponse.class);
NfcPushOptions options_3 = createNfcPushOptions();
options_3.compatibility = NdefCompatibility.NFC_FORUM;
nfc.push(createMojoNdefMessage(), options_3, mockCallback_3);
nfc.processPendingOperationsForTesting(mNfcTagHandler);
verifyZeroInteractions(mockCallback_3);
}
/** /**
* Test that Nfc.watch() works correctly and client is notified. * Test that Nfc.watch() works correctly and client is notified.
*/ */
...@@ -576,7 +502,6 @@ public class NFCTest { ...@@ -576,7 +502,6 @@ public class NFCTest {
// Should match by WebNFC Id (exact match). // Should match by WebNFC Id (exact match).
NfcScanOptions options1 = createNfcScanOptions(); NfcScanOptions options1 = createNfcScanOptions();
options1.compatibility = NdefCompatibility.NFC_FORUM;
options1.url = TEST_URL; options1.url = TEST_URL;
int watchId1 = mNextWatchId++; int watchId1 = mNextWatchId++;
WatchResponse mockWatchCallback1 = mock(WatchResponse.class); WatchResponse mockWatchCallback1 = mock(WatchResponse.class);
...@@ -586,7 +511,6 @@ public class NFCTest { ...@@ -586,7 +511,6 @@ public class NFCTest {
// Should match by media type. // Should match by media type.
NfcScanOptions options2 = createNfcScanOptions(); NfcScanOptions options2 = createNfcScanOptions();
options2.compatibility = NdefCompatibility.ANY;
options2.mediaType = TEXT_MIME; options2.mediaType = TEXT_MIME;
int watchId2 = mNextWatchId++; int watchId2 = mNextWatchId++;
WatchResponse mockWatchCallback2 = mock(WatchResponse.class); WatchResponse mockWatchCallback2 = mock(WatchResponse.class);
...@@ -596,7 +520,6 @@ public class NFCTest { ...@@ -596,7 +520,6 @@ public class NFCTest {
// Should match by record type. // Should match by record type.
NfcScanOptions options3 = createNfcScanOptions(); NfcScanOptions options3 = createNfcScanOptions();
options3.compatibility = NdefCompatibility.ANY;
NdefRecordTypeFilter typeFilter = new NdefRecordTypeFilter(); NdefRecordTypeFilter typeFilter = new NdefRecordTypeFilter();
typeFilter.recordType = NdefMessageUtils.RECORD_TYPE_URL; typeFilter.recordType = NdefMessageUtils.RECORD_TYPE_URL;
options3.recordFilter = typeFilter; options3.recordFilter = typeFilter;
...@@ -608,7 +531,6 @@ public class NFCTest { ...@@ -608,7 +531,6 @@ public class NFCTest {
// Should not match // Should not match
NfcScanOptions options4 = createNfcScanOptions(); NfcScanOptions options4 = createNfcScanOptions();
options4.compatibility = NdefCompatibility.NFC_FORUM;
options4.url = AUTHOR_RECORD_DOMAIN; options4.url = AUTHOR_RECORD_DOMAIN;
int watchId4 = mNextWatchId++; int watchId4 = mNextWatchId++;
WatchResponse mockWatchCallback4 = mock(WatchResponse.class); WatchResponse mockWatchCallback4 = mock(WatchResponse.class);
...@@ -996,126 +918,6 @@ public class NFCTest { ...@@ -996,126 +918,6 @@ public class NFCTest {
assertEquals(NfcErrorType.NOT_SUPPORTED, mErrorCaptor.getValue().errorType); assertEquals(NfcErrorType.NOT_SUPPORTED, mErrorCaptor.getValue().errorType);
} }
/**
* Test that 'nfc-forum' tag messages can only be read by Nfc.watch() with 'nfc-forum' or 'any'
* option.
*/
@Test
@Feature({"NFCTest"})
public void testWatchCompatibilityMatchingNfcForumTag() {
TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate);
mDelegate.invokeCallback();
nfc.setClient(mNfcClient);
// Should match.
int watchId1 = mNextWatchId++;
{
NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = TEST_URL;
WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId1, mockWatchCallback);
verify(mockWatchCallback).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
}
// Should not match.
int watchId2 = mNextWatchId++;
{
NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.VENDOR;
options.url = TEST_URL;
WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId2, mockWatchCallback);
verify(mockWatchCallback).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
}
// Should match.
int watchId3 = mNextWatchId++;
{
NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.ANY;
options.url = TEST_URL;
WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId3, mockWatchCallback);
verify(mockWatchCallback).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
}
doReturn(NdefCompatibility.NFC_FORUM).when(mNfcTagHandler).compatibility();
nfc.processPendingOperationsForTesting(mNfcTagHandler);
// Check that client was notified and watch with 'nfc-forum' or 'any' compatibility was
// triggered.
verify(mNfcClient, times(1))
.onWatch(mOnWatchCallbackCaptor.capture(), nullable(String.class),
any(NdefMessage.class));
assertEquals(2, mOnWatchCallbackCaptor.getValue().length);
assertEquals(watchId1, mOnWatchCallbackCaptor.getValue()[0]);
assertEquals(watchId3, mOnWatchCallbackCaptor.getValue()[1]);
}
/**
* Test that 'vendor' tag messages can only be read by Nfc.watch() with 'vendor' or 'any'
* option.
*/
@Test
@Feature({"NFCTest"})
public void testWatchCompatibilityMatchingVendorTag() {
TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate);
mDelegate.invokeCallback();
nfc.setClient(mNfcClient);
// Should not match.
int watchId1 = mNextWatchId++;
{
NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = TEST_URL;
WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId1, mockWatchCallback);
verify(mockWatchCallback).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
}
// Should match.
int watchId2 = mNextWatchId++;
{
NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.VENDOR;
options.url = TEST_URL;
WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId2, mockWatchCallback);
verify(mockWatchCallback).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
}
// Should match.
int watchId3 = mNextWatchId++;
{
NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.ANY;
options.url = TEST_URL;
WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId3, mockWatchCallback);
verify(mockWatchCallback).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
}
doReturn(NdefCompatibility.VENDOR).when(mNfcTagHandler).compatibility();
nfc.processPendingOperationsForTesting(mNfcTagHandler);
// Check that client was notified and watch with 'vendor' or 'any' compatibility was
// triggered.
verify(mNfcClient, times(1))
.onWatch(mOnWatchCallbackCaptor.capture(), nullable(String.class),
any(NdefMessage.class));
assertEquals(2, mOnWatchCallbackCaptor.getValue().length);
assertEquals(watchId2, mOnWatchCallbackCaptor.getValue()[0]);
assertEquals(watchId3, mOnWatchCallbackCaptor.getValue()[1]);
}
/** /**
* Test that Nfc.watch() WebNFC Id pattern matching works correctly. * Test that Nfc.watch() WebNFC Id pattern matching works correctly.
*/ */
...@@ -1130,7 +932,6 @@ public class NFCTest { ...@@ -1130,7 +932,6 @@ public class NFCTest {
int watchId1 = mNextWatchId++; int watchId1 = mNextWatchId++;
{ {
NfcScanOptions options = createNfcScanOptions(); NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = "https://test.com/*"; options.url = "https://test.com/*";
WatchResponse mockWatchCallback = mock(WatchResponse.class); WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId1, mockWatchCallback); nfc.watch(options, watchId1, mockWatchCallback);
...@@ -1142,7 +943,6 @@ public class NFCTest { ...@@ -1142,7 +943,6 @@ public class NFCTest {
int watchId2 = mNextWatchId++; int watchId2 = mNextWatchId++;
{ {
NfcScanOptions options = createNfcScanOptions(); NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = "https://test.com/contact/42"; options.url = "https://test.com/contact/42";
WatchResponse mockWatchCallback = mock(WatchResponse.class); WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId2, mockWatchCallback); nfc.watch(options, watchId2, mockWatchCallback);
...@@ -1154,7 +954,6 @@ public class NFCTest { ...@@ -1154,7 +954,6 @@ public class NFCTest {
int watchId3 = mNextWatchId++; int watchId3 = mNextWatchId++;
{ {
NfcScanOptions options = createNfcScanOptions(); NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = "https://subdomain.test.com/*"; options.url = "https://subdomain.test.com/*";
WatchResponse mockWatchCallback = mock(WatchResponse.class); WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId3, mockWatchCallback); nfc.watch(options, watchId3, mockWatchCallback);
...@@ -1166,7 +965,6 @@ public class NFCTest { ...@@ -1166,7 +965,6 @@ public class NFCTest {
int watchId4 = mNextWatchId++; int watchId4 = mNextWatchId++;
{ {
NfcScanOptions options = createNfcScanOptions(); NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = "https://subdomain.test.com/contact"; options.url = "https://subdomain.test.com/contact";
WatchResponse mockWatchCallback = mock(WatchResponse.class); WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, watchId4, mockWatchCallback); nfc.watch(options, watchId4, mockWatchCallback);
...@@ -1177,7 +975,6 @@ public class NFCTest { ...@@ -1177,7 +975,6 @@ public class NFCTest {
// Should not match. // Should not match.
{ {
NfcScanOptions options = createNfcScanOptions(); NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = "https://www.test.com/*"; options.url = "https://www.test.com/*";
WatchResponse mockWatchCallback = mock(WatchResponse.class); WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, mNextWatchId++, mockWatchCallback); nfc.watch(options, mNextWatchId++, mockWatchCallback);
...@@ -1188,7 +985,6 @@ public class NFCTest { ...@@ -1188,7 +985,6 @@ public class NFCTest {
// Should not match. // Should not match.
{ {
NfcScanOptions options = createNfcScanOptions(); NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = "http://test.com/*"; options.url = "http://test.com/*";
WatchResponse mockWatchCallback = mock(WatchResponse.class); WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, mNextWatchId++, mockWatchCallback); nfc.watch(options, mNextWatchId++, mockWatchCallback);
...@@ -1199,7 +995,6 @@ public class NFCTest { ...@@ -1199,7 +995,6 @@ public class NFCTest {
// Should not match. // Should not match.
{ {
NfcScanOptions options = createNfcScanOptions(); NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = "invalid pattern url"; options.url = "invalid pattern url";
WatchResponse mockWatchCallback = mock(WatchResponse.class); WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, mNextWatchId++, mockWatchCallback); nfc.watch(options, mNextWatchId++, mockWatchCallback);
...@@ -1239,7 +1034,6 @@ public class NFCTest { ...@@ -1239,7 +1034,6 @@ public class NFCTest {
// Should not match when invalid WebNFC Id is received. // Should not match when invalid WebNFC Id is received.
NfcScanOptions options = createNfcScanOptions(); NfcScanOptions options = createNfcScanOptions();
options.compatibility = NdefCompatibility.NFC_FORUM;
options.url = "https://test.com/*"; options.url = "https://test.com/*";
WatchResponse mockWatchCallback = mock(WatchResponse.class); WatchResponse mockWatchCallback = mock(WatchResponse.class);
nfc.watch(options, mNextWatchId, mockWatchCallback); nfc.watch(options, mNextWatchId, mockWatchCallback);
...@@ -1300,7 +1094,6 @@ public class NFCTest { ...@@ -1300,7 +1094,6 @@ public class NFCTest {
pushOptions.target = NfcPushTarget.ANY; pushOptions.target = NfcPushTarget.ANY;
pushOptions.timeout = timeout; pushOptions.timeout = timeout;
pushOptions.ignoreRead = false; pushOptions.ignoreRead = false;
pushOptions.compatibility = NdefCompatibility.ANY;
return pushOptions; return pushOptions;
} }
...@@ -1308,7 +1101,6 @@ public class NFCTest { ...@@ -1308,7 +1101,6 @@ public class NFCTest {
NfcScanOptions options = new NfcScanOptions(); NfcScanOptions options = new NfcScanOptions();
options.url = ""; options.url = "";
options.mediaType = ""; options.mediaType = "";
options.compatibility = NdefCompatibility.ANY;
options.recordFilter = null; options.recordFilter = null;
return options; return options;
} }
......
...@@ -30,16 +30,6 @@ enum NFCPushTarget { ...@@ -30,16 +30,6 @@ enum NFCPushTarget {
ANY 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 { struct NFCError {
NFCErrorType error_type; NFCErrorType error_type;
}; };
...@@ -78,9 +68,6 @@ struct NFCPushOptions { ...@@ -78,9 +68,6 @@ struct NFCPushOptions {
// If the property is true, the push operation will suspend active watchers // If the property is true, the push operation will suspend active watchers
// until its completion. // until its completion.
bool ignore_read; bool ignore_read;
// Defines the accepted kinds of NFC devices.
NDEFCompatibility compatibility;
}; };
struct NDEFRecordTypeFilter { struct NDEFRecordTypeFilter {
...@@ -96,9 +83,6 @@ struct NFCScanOptions { ...@@ -96,9 +83,6 @@ struct NFCScanOptions {
// Defines media type filtering constraint. // Defines media type filtering constraint.
string? media_type; string? media_type;
// Defines the accepted kinds of NFC devices.
NDEFCompatibility compatibility;
}; };
interface NFC { interface NFC {
......
...@@ -11,5 +11,4 @@ dictionary NFCPushOptions { ...@@ -11,5 +11,4 @@ dictionary NFCPushOptions {
unrestricted double timeout; // in ms unrestricted double timeout; // in ms
boolean ignoreRead = true; boolean ignoreRead = true;
AbortSignal? signal; AbortSignal? signal;
NDEFCompatibility compatibility = "nfc-forum";
}; };
...@@ -2,15 +2,10 @@ ...@@ -2,15 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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 // https://w3c.github.io/web-nfc/#the-nfcscanoptions-dictionary
dictionary NFCScanOptions { dictionary NFCScanOptions {
AbortSignal? signal; AbortSignal? signal;
USVString url = ""; USVString url = "";
NDEFRecordType? recordType; NDEFRecordType? recordType;
USVString mediaType = ""; USVString mediaType = "";
NDEFCompatibility compatibility = "nfc-forum";
}; };
...@@ -52,13 +52,10 @@ TypeConverter<NFCPushOptionsPtr, const blink::NFCPushOptions*>::Convert( ...@@ -52,13 +52,10 @@ TypeConverter<NFCPushOptionsPtr, const blink::NFCPushOptions*>::Convert(
const blink::NFCPushOptions* pushOptions) { const blink::NFCPushOptions* pushOptions) {
// https://w3c.github.io/web-nfc/#the-nfcpushoptions-dictionary // https://w3c.github.io/web-nfc/#the-nfcpushoptions-dictionary
// Default values for NFCPushOptions dictionary are: // Default values for NFCPushOptions dictionary are:
// target = 'any', timeout = Infinity, ignoreRead = true, // target = 'any', timeout = Infinity, ignoreRead = true
// compatibility = "nfc-forum"
NFCPushOptionsPtr pushOptionsPtr = NFCPushOptions::New(); NFCPushOptionsPtr pushOptionsPtr = NFCPushOptions::New();
pushOptionsPtr->target = blink::StringToNFCPushTarget(pushOptions->target()); pushOptionsPtr->target = blink::StringToNFCPushTarget(pushOptions->target());
pushOptionsPtr->ignore_read = pushOptions->ignoreRead(); pushOptionsPtr->ignore_read = pushOptions->ignoreRead();
pushOptionsPtr->compatibility =
blink::StringToNDEFCompatibility(pushOptions->compatibility());
if (pushOptions->hasTimeout()) if (pushOptions->hasTimeout())
pushOptionsPtr->timeout = pushOptions->timeout(); pushOptionsPtr->timeout = pushOptions->timeout();
...@@ -73,12 +70,10 @@ TypeConverter<NFCScanOptionsPtr, const blink::NFCScanOptions*>::Convert( ...@@ -73,12 +70,10 @@ TypeConverter<NFCScanOptionsPtr, const blink::NFCScanOptions*>::Convert(
const blink::NFCScanOptions* scanOptions) { const blink::NFCScanOptions* scanOptions) {
// https://w3c.github.io/web-nfc/#dom-nfcscanoptions // https://w3c.github.io/web-nfc/#dom-nfcscanoptions
// Default values for NFCScanOptions dictionary are: // Default values for NFCScanOptions dictionary are:
// url = "", recordType = null, mediaType = "", compatibility = "nfc-forum" // url = "", recordType = null, mediaType = ""
NFCScanOptionsPtr scanOptionsPtr = NFCScanOptions::New(); NFCScanOptionsPtr scanOptionsPtr = NFCScanOptions::New();
scanOptionsPtr->url = scanOptions->url(); scanOptionsPtr->url = scanOptions->url();
scanOptionsPtr->media_type = scanOptions->mediaType(); scanOptionsPtr->media_type = scanOptions->mediaType();
scanOptionsPtr->compatibility =
blink::StringToNDEFCompatibility(scanOptions->compatibility());
if (scanOptions->hasRecordType()) { if (scanOptions->hasRecordType()) {
scanOptionsPtr->record_filter = NDEFRecordTypeFilter::New(); scanOptionsPtr->record_filter = NDEFRecordTypeFilter::New();
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h"
using device::mojom::blink::NDEFCompatibility;
using device::mojom::blink::NFCPushTarget; using device::mojom::blink::NFCPushTarget;
namespace blink { namespace blink {
...@@ -39,20 +38,6 @@ bool SetNDEFMessageURL(const String& origin, ...@@ -39,20 +38,6 @@ bool SetNDEFMessageURL(const String& origin,
return origin_url.IsValid(); 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) { NFCPushTarget StringToNFCPushTarget(const String& target) {
if (target == "tag") if (target == "tag")
return NFCPushTarget::TAG; return NFCPushTarget::TAG;
......
...@@ -20,9 +20,6 @@ size_t GetNDEFMessageSize(const device::mojom::blink::NDEFMessage& message); ...@@ -20,9 +20,6 @@ size_t GetNDEFMessageSize(const device::mojom::blink::NDEFMessage& message);
bool SetNDEFMessageURL(const String& origin, bool SetNDEFMessageURL(const String& origin,
device::mojom::blink::NDEFMessage* message); device::mojom::blink::NDEFMessage* message);
device::mojom::blink::NDEFCompatibility StringToNDEFCompatibility(
const WTF::String& compatibility);
device::mojom::blink::NFCPushTarget StringToNFCPushTarget( device::mojom::blink::NFCPushTarget StringToNFCPushTarget(
const WTF::String& target); const WTF::String& target);
......
...@@ -11,14 +11,6 @@ function toMojoNFCPushTarget(target) { ...@@ -11,14 +11,6 @@ function toMojoNFCPushTarget(target) {
return device.mojom.NFCPushTarget.ANY; 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 // Converts between NDEFMessageInit https://w3c.github.io/web-nfc/#dom-ndefmessage
// and mojom.NDEFMessage structure, so that watch function can be tested. // and mojom.NDEFMessage structure, so that watch function can be tested.
function toMojoNDEFMessage(message) { function toMojoNDEFMessage(message) {
...@@ -90,14 +82,6 @@ function assertNFCPushOptionsEqual(provided, received) { ...@@ -90,14 +82,6 @@ function assertNFCPushOptionsEqual(provided, received) {
assert_equals(toMojoNFCPushTarget(provided.target), received.target); assert_equals(toMojoNFCPushTarget(provided.target), received.target);
else else
assert_equals(received.target, device.mojom.NFCPushTarget.ANY); 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 // Compares NFCReaderOptions structures that were provided to API and
...@@ -113,29 +97,14 @@ function assertNFCReaderOptionsEqual(provided, received) { ...@@ -113,29 +97,14 @@ function assertNFCReaderOptionsEqual(provided, received) {
else else
assert_equals(received.mediaType, ''); 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) { if (provided.recordType !== undefined) {
assert_equals(!+received.record_filter, true); assert_equals(!+received.record_filter, true);
assert_equals(provided.recordType, received.recordFilter.recordType); assert_equals(provided.recordType, received.recordFilter.recordType);
} }
} }
// Checks whether NFCReaderOptions are matched with given message // Checks whether NFCReaderOptions are matched with given message.
// and mock nfc's compatibility function matchesWatchOptions(message, options) {
function matchesWatchOptions(message, compatibility, options) {
// Filter by NDEFCompatibility
if (options.compatibility !== toMojoNDEFCompatibility("any")
&& options.compatibility !== compatibility) {
return false;
}
// Filter by Web NFC id // Filter by Web NFC id
if (!matchesWebNfcId(message.url, options.url)) return false; if (!matchesWebNfcId(message.url, options.url)) return false;
...@@ -255,10 +224,9 @@ var WebNFCTest = (() => { ...@@ -255,10 +224,9 @@ var WebNFCTest = (() => {
this.watchers_.push({id: id, options: options}); this.watchers_.push({id: id, options: options});
// Triggers onWatch if the new watcher matches existing messages // Triggers onWatch if the new watcher matches existing messages
for (let message of this.reading_messages_) { for (let message of this.reading_messages_) {
if (matchesWatchOptions( if (matchesWatchOptions(message, options)) {
message.message, message.compatibility, options)) {
this.client_.onWatch( this.client_.onWatch(
[id], fake_tag_serial_number, toMojoNDEFMessage(message.message)); [id], fake_tag_serial_number, toMojoNDEFMessage(message));
} }
} }
...@@ -335,19 +303,16 @@ var WebNFCTest = (() => { ...@@ -335,19 +303,16 @@ var WebNFCTest = (() => {
this.push_should_timeout_ = false; this.push_should_timeout_ = false;
} }
// Sets message that is used to deliver NFC reading updates // Sets message that is used to deliver NFC reading updates.
// with a specific NDEFCompatibility. setReadingMessage(message) {
setReadingMessage(message, compatibility = 'nfc-forum') { this.reading_messages_.push(message);
this.reading_messages_.push({message: message,
compatibility: toMojoNDEFCompatibility(compatibility)});
// Ignore reading if NFCPushOptions.ignoreRead is true // Ignore reading if NFCPushOptions.ignoreRead is true
let ignoreRead = false; let ignoreRead = false;
if(this.push_options_ && this.push_options_.ignoreRead) if(this.push_options_ && this.push_options_.ignoreRead)
ignoreRead = this.push_options_.ignoreRead; ignoreRead = this.push_options_.ignoreRead;
// Triggers onWatch if the new message matches existing watchers // Triggers onWatch if the new message matches existing watchers
for (let watcher of this.watchers_) { for (let watcher of this.watchers_) {
if (!ignoreRead && matchesWatchOptions( if (!ignoreRead && matchesWatchOptions(message, watcher.options)) {
message, toMojoNDEFCompatibility(compatibility), watcher.options)) {
this.client_.onWatch( this.client_.onWatch(
[watcher.id], fake_tag_serial_number, [watcher.id], fake_tag_serial_number,
toMojoNDEFMessage(message)); toMojoNDEFMessage(message));
......
...@@ -61,13 +61,6 @@ const NFCReaderOptionTests = ...@@ -61,13 +61,6 @@ const NFCReaderOptionTests =
scanOptions: {mediaType: "application/octet-stream"}, scanOptions: {mediaType: "application/octet-stream"},
unmatchedScanOptions: {mediaType: "application/json"}, unmatchedScanOptions: {mediaType: "application/json"},
message: createMessage([createOpaqueRecord(test_buffer_data)]) 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 = ...@@ -123,14 +116,6 @@ const ReadMultiMessagesTests =
scanOptions: {mediaType: "application/octet-stream"}, scanOptions: {mediaType: "application/octet-stream"},
message: createMessage([createOpaqueRecord(test_buffer_data)]), message: createMessage([createOpaqueRecord(test_buffer_data)]),
unmatchedMessage: createMessage([createJsonRecord(test_json_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) { ...@@ -144,16 +129,10 @@ for (let NFCReaderOptionTest of NFCReaderOptionTests) {
} }
for (let readMultiMessagesTest of ReadMultiMessagesTests) { for (let readMultiMessagesTest of ReadMultiMessagesTests) {
// Sets default message's associated compatibility
let unmatchedCompatibility = "nfc-forum";
if(readMultiMessagesTest.unmatchedCompatibility)
unmatchedCompatibility = readMultiMessagesTest.unmatchedCompatibility;
testReadingMultiMessages( testReadingMultiMessages(
readMultiMessagesTest.message, readMultiMessagesTest.message,
readMultiMessagesTest.scanOptions, readMultiMessagesTest.scanOptions,
readMultiMessagesTest.unmatchedMessage, readMultiMessagesTest.unmatchedMessage,
unmatchedCompatibility,
readMultiMessagesTest.desc readMultiMessagesTest.desc
); );
} }
......
...@@ -12,8 +12,7 @@ The `WebNFCTest` interface is defined as: ...@@ -12,8 +12,7 @@ The `WebNFCTest` interface is defined as:
class MockNFC { class MockNFC {
setHWStatus(number status); // Sets the hardware status. setHWStatus(number status); // Sets the hardware status.
setCompatibility(NDEFCompatibility compatibility); // Sets NDEF accepted compatible devices setReadingMessage(NDEFMessageInit message); // Sets message that is used to deliver NFC reading updates.
setReadingMessage(NDEFMessageInit message, NDEFCompatibility compatibility); // Sets message that is used to deliver NFC reading updates with a specific NDEFCompatibility.
setPendingPushCompleted(boolean result); // Sets if the pending push is completed. setPendingPushCompleted(boolean result); // Sets if the pending push is completed.
setPushShouldTimeout(boolean result); // Sets flag to trigger the pending push to timeout. setPushShouldTimeout(boolean result); // Sets flag to trigger the pending push to timeout.
pushedMessage(); // Gets the pushed `NDEFMessageSource`. pushedMessage(); // Gets the pushed `NDEFMessageSource`.
......
...@@ -111,8 +111,8 @@ function createUrlRecord(url) { ...@@ -111,8 +111,8 @@ function createUrlRecord(url) {
return createRecord('url', 'text/plain', url); return createRecord('url', 'text/plain', url);
} }
function createNFCPushOptions(target, timeout, ignoreRead, compatibility) { function createNFCPushOptions(target, timeout, ignoreRead) {
return { target, timeout, ignoreRead, compatibility}; return {target, timeout, ignoreRead};
} }
// Compares NDEFMessageSource that was provided to the API // Compares NDEFMessageSource that was provided to the API
...@@ -178,7 +178,7 @@ function testNFCScanOptions(message, scanOptions, unmatchedScanOptions, desc) { ...@@ -178,7 +178,7 @@ function testNFCScanOptions(message, scanOptions, unmatchedScanOptions, desc) {
const reader2 = new NFCReader(); const reader2 = new NFCReader();
const controller = new AbortController(); const controller = new AbortController();
mockNFC.setReadingMessage(message, scanOptions.compatibility); mockNFC.setReadingMessage(message);
// Reading from unmatched reader will not be triggered // Reading from unmatched reader will not be triggered
reader1.onreading = t.unreached_func("reading event should not be fired."); reader1.onreading = t.unreached_func("reading event should not be fired.");
...@@ -198,8 +198,8 @@ function testNFCScanOptions(message, scanOptions, unmatchedScanOptions, desc) { ...@@ -198,8 +198,8 @@ function testNFCScanOptions(message, scanOptions, unmatchedScanOptions, desc) {
}, desc); }, desc);
} }
function testReadingMultiMessages(message, scanOptions, unmatchedMessage, function testReadingMultiMessages(
unmatchedCompatibility, desc) { message, scanOptions, unmatchedMessage, desc) {
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
const reader = new NFCReader(); const reader = new NFCReader();
const controller = new AbortController(); const controller = new AbortController();
...@@ -214,7 +214,7 @@ function testReadingMultiMessages(message, scanOptions, unmatchedMessage, ...@@ -214,7 +214,7 @@ function testReadingMultiMessages(message, scanOptions, unmatchedMessage,
reader.scan(scanOptions); reader.scan(scanOptions);
// Unmatched message will not be read // Unmatched message will not be read
mockNFC.setReadingMessage(unmatchedMessage, unmatchedCompatibility); mockNFC.setReadingMessage(unmatchedMessage);
mockNFC.setReadingMessage(message); mockNFC.setReadingMessage(message);
await promise; 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