Commit 1d2cec0b authored by Wanming Lin's avatar Wanming Lin Committed by Commit Bot

[WebNFC] Remove NDEFPushOptions.timeout

This CL removes NDEFPushOptions.timeout relevant implementation and tests
per spec change at: https://github.com/w3c/web-nfc/pull/428/files

Bug: 520391
Change-Id: Ifea11f4a7bbe8b126d8a4a32169fcaacebfb0f44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1894677
Commit-Queue: Wanming Lin <wanming.lin@intel.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarRijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarLeon Han <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#715542}
parent e609d761
...@@ -16,7 +16,6 @@ import android.nfc.NfcManager; ...@@ -16,7 +16,6 @@ import android.nfc.NfcManager;
import android.nfc.Tag; import android.nfc.Tag;
import android.nfc.TagLostException; import android.nfc.TagLostException;
import android.os.Build; import android.os.Build;
import android.os.Handler;
import android.os.Process; import android.os.Process;
import android.os.Vibrator; import android.os.Vibrator;
import android.util.SparseArray; import android.util.SparseArray;
...@@ -111,16 +110,6 @@ public class NfcImpl implements Nfc { ...@@ -111,16 +110,6 @@ public class NfcImpl implements Nfc {
*/ */
private final SparseArray<NdefScanOptions> mWatchers = new SparseArray<>(); private final SparseArray<NdefScanOptions> mWatchers = new SparseArray<>();
/**
* Handler that runs delayed push timeout task.
*/
private final Handler mPushTimeoutHandler = new Handler();
/**
* Runnable responsible for cancelling push operation after specified timeout.
*/
private Runnable mPushTimeoutRunnable;
/** /**
* Vibrator. @see android.os.Vibrator * Vibrator. @see android.os.Vibrator
*/ */
...@@ -187,7 +176,7 @@ public class NfcImpl implements Nfc { ...@@ -187,7 +176,7 @@ public class NfcImpl implements Nfc {
* passive NFC devices are supported (NdefPushTarget.TAG). * passive NFC devices are supported (NdefPushTarget.TAG).
* *
* @param message that should be pushed to NFC device. * @param message that should be pushed to NFC device.
* @param options that contain information about timeout and target device type. * @param options that contain information about target device type.
* @param callback that is used to notify when push operation is completed. * @param callback that is used to notify when push operation is completed.
*/ */
@Override @Override
...@@ -200,8 +189,7 @@ public class NfcImpl implements Nfc { ...@@ -200,8 +189,7 @@ public class NfcImpl implements Nfc {
} }
// Check NdefPushOptions that are not supported by Android platform. // Check NdefPushOptions that are not supported by Android platform.
if (options.target == NdefPushTarget.PEER || options.timeout < 0 if (options.target == NdefPushTarget.PEER) {
|| (options.timeout > Long.MAX_VALUE && !Double.isInfinite(options.timeout))) {
callback.call(createError(NdefErrorType.NOT_SUPPORTED)); callback.call(createError(NdefErrorType.NOT_SUPPORTED));
return; return;
} }
...@@ -209,13 +197,10 @@ public class NfcImpl implements Nfc { ...@@ -209,13 +197,10 @@ public class NfcImpl implements Nfc {
// If previous pending push operation is not completed, cancel it. // If previous pending push operation is not completed, cancel it.
if (mPendingPushOperation != null) { if (mPendingPushOperation != null) {
mPendingPushOperation.complete(createError(NdefErrorType.OPERATION_CANCELLED)); mPendingPushOperation.complete(createError(NdefErrorType.OPERATION_CANCELLED));
cancelPushTimeoutTask();
} }
mPendingPushOperation = new PendingPushOperation(message, options, callback); mPendingPushOperation = new PendingPushOperation(message, options, callback);
// Schedule push timeout task for new #mPendingPushOperation.
schedulePushTimeoutTask(options);
enableReaderModeIfNeeded(); enableReaderModeIfNeeded();
processPendingPushOperation(); processPendingPushOperation();
} }
...@@ -481,8 +466,8 @@ public class NfcImpl implements Nfc { ...@@ -481,8 +466,8 @@ public class NfcImpl implements Nfc {
} }
/** /**
* Handles completion of pending push operation, cancels timeout task and completes push * Handles completion of pending push operation, completes push operation.
* operation. On error, invalidates #mTagHandler. * On error, invalidates #mTagHandler.
*/ */
private void pendingPushOperationCompleted(NdefError error) { private void pendingPushOperationCompleted(NdefError error) {
completePendingPushOperation(error); completePendingPushOperation(error);
...@@ -495,7 +480,6 @@ public class NfcImpl implements Nfc { ...@@ -495,7 +480,6 @@ public class NfcImpl implements Nfc {
private void completePendingPushOperation(NdefError error) { private void completePendingPushOperation(NdefError error) {
if (mPendingPushOperation == null) return; if (mPendingPushOperation == null) return;
cancelPushTimeoutTask();
mPendingPushOperation.complete(error); mPendingPushOperation.complete(error);
mPendingPushOperation = null; mPendingPushOperation = null;
disableReaderModeIfNeeded(); disableReaderModeIfNeeded();
...@@ -683,33 +667,4 @@ public class NfcImpl implements Nfc { ...@@ -683,33 +667,4 @@ public class NfcImpl implements Nfc {
} }
} }
} }
/**
* Schedules task that is executed after timeout and cancels pending push operation.
*/
private void schedulePushTimeoutTask(NdefPushOptions options) {
assert mPushTimeoutRunnable == null;
// Default timeout value.
if (Double.isInfinite(options.timeout)) return;
// Create and schedule timeout.
mPushTimeoutRunnable = new Runnable() {
@Override
public void run() {
completePendingPushOperation(createError(NdefErrorType.TIMER_EXPIRED));
}
};
mPushTimeoutHandler.postDelayed(mPushTimeoutRunnable, (long) options.timeout);
}
/**
* Cancels push timeout task.
*/
void cancelPushTimeoutTask() {
if (mPushTimeoutRunnable == null) return;
mPushTimeoutHandler.removeCallbacks(mPushTimeoutRunnable);
mPushTimeoutRunnable = null;
}
} }
...@@ -15,7 +15,6 @@ enum NDEFErrorType { ...@@ -15,7 +15,6 @@ enum NDEFErrorType {
NOT_FOUND, NOT_FOUND,
INVALID_MESSAGE, INVALID_MESSAGE,
OPERATION_CANCELLED, OPERATION_CANCELLED,
TIMER_EXPIRED,
CANNOT_CANCEL, CANNOT_CANCEL,
// Transfer data error. // Transfer data error.
IO_ERROR IO_ERROR
...@@ -79,9 +78,6 @@ struct NDEFPushOptions { ...@@ -79,9 +78,6 @@ struct NDEFPushOptions {
// The target of the push operation. // The target of the push operation.
NDEFPushTarget target; NDEFPushTarget target;
// The timeout for the push operation, in milliseconds.
double timeout;
// 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;
...@@ -104,9 +100,7 @@ interface NFC { ...@@ -104,9 +100,7 @@ interface NFC {
SetClient(pending_remote<NFCClient> client); SetClient(pending_remote<NFCClient> client);
// Pushes data to NFC device. // Pushes data to NFC device.
// NDEFPushOptions specify timeout and type of device where data should be // NDEFPushOptions specify type of device where data should be pushed.
// pushed. If timeout is defined and data is not pushed before timeout is
// expired, callback with corresponding error is called.
Push(NDEFMessage message, NDEFPushOptions? options) => (NDEFError? error); Push(NDEFMessage message, NDEFPushOptions? options) => (NDEFError? error);
// Cancels pending push request. // Cancels pending push request.
......
...@@ -8,7 +8,6 @@ enum NDEFPushTarget { "tag", "peer", "any" }; ...@@ -8,7 +8,6 @@ enum NDEFPushTarget { "tag", "peer", "any" };
dictionary NDEFPushOptions { dictionary NDEFPushOptions {
NDEFPushTarget target = "any"; NDEFPushTarget target = "any";
unrestricted double timeout; // in ms
boolean ignoreRead = true; boolean ignoreRead = true;
AbortSignal? signal; AbortSignal? signal;
}; };
...@@ -58,18 +58,7 @@ ScriptPromise NDEFWriter::push(ScriptState* script_state, ...@@ -58,18 +58,7 @@ ScriptPromise NDEFWriter::push(ScriptState* script_state,
"The NFC operation was cancelled.")); "The NFC operation was cancelled."));
} }
// 9. If timeout value is NaN or negative, reject promise with "TypeError" // Step 10.10.1: Run "create NDEF message", if this throws an exception,
// and abort these steps.
if (options->hasTimeout() &&
(std::isnan(options->timeout()) || options->timeout() < 0)) {
return ScriptPromise::Reject(
script_state,
V8ThrowException::CreateTypeError(
script_state->GetIsolate(),
"Invalid NDEFPushOptions.timeout value was provided."));
}
// Step 10.8: Run "create Web NFC message", if this throws an exception,
// reject p with that exception and abort these steps. // reject p with that exception and abort these steps.
NDEFMessage* ndef_message = NDEFMessage* ndef_message =
NDEFMessage::Create(execution_context, push_message, exception_state); NDEFMessage::Create(execution_context, push_message, exception_state);
......
...@@ -58,16 +58,11 @@ TypeConverter<NDEFPushOptionsPtr, const blink::NDEFPushOptions*>::Convert( ...@@ -58,16 +58,11 @@ TypeConverter<NDEFPushOptionsPtr, const blink::NDEFPushOptions*>::Convert(
const blink::NDEFPushOptions* pushOptions) { const blink::NDEFPushOptions* pushOptions) {
// https://w3c.github.io/web-nfc/#the-ndefpushoptions-dictionary // https://w3c.github.io/web-nfc/#the-ndefpushoptions-dictionary
// Default values for NDEFPushOptions dictionary are: // Default values for NDEFPushOptions dictionary are:
// target = 'any', timeout = Infinity, ignoreRead = true // target = 'any', ignoreRead = true
NDEFPushOptionsPtr pushOptionsPtr = NDEFPushOptions::New(); NDEFPushOptionsPtr pushOptionsPtr = NDEFPushOptions::New();
pushOptionsPtr->target = blink::StringToNDEFPushTarget(pushOptions->target()); pushOptionsPtr->target = blink::StringToNDEFPushTarget(pushOptions->target());
pushOptionsPtr->ignore_read = pushOptions->ignoreRead(); pushOptionsPtr->ignore_read = pushOptions->ignoreRead();
if (pushOptions->hasTimeout())
pushOptionsPtr->timeout = pushOptions->timeout();
else
pushOptionsPtr->timeout = std::numeric_limits<double>::infinity();
return pushOptionsPtr; return pushOptionsPtr;
} }
......
...@@ -71,9 +71,6 @@ DOMException* NDEFErrorTypeToDOMException( ...@@ -71,9 +71,6 @@ DOMException* NDEFErrorTypeToDOMException(
case device::mojom::blink::NDEFErrorType::OPERATION_CANCELLED: case device::mojom::blink::NDEFErrorType::OPERATION_CANCELLED:
return MakeGarbageCollected<DOMException>( return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kAbortError, "The NFC operation was cancelled."); DOMExceptionCode::kAbortError, "The NFC operation was cancelled.");
case device::mojom::blink::NDEFErrorType::TIMER_EXPIRED:
return MakeGarbageCollected<DOMException>(DOMExceptionCode::kTimeoutError,
"NFC operation has timed out.");
case device::mojom::blink::NDEFErrorType::CANNOT_CANCEL: case device::mojom::blink::NDEFErrorType::CANNOT_CANCEL:
return MakeGarbageCollected<DOMException>( return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNoModificationAllowedError, DOMExceptionCode::kNoModificationAllowedError,
......
...@@ -79,11 +79,6 @@ function assertNDEFPushOptionsEqual(provided, received) { ...@@ -79,11 +79,6 @@ function assertNDEFPushOptionsEqual(provided, received) {
else else
assert_equals(!!received.ignore_read, true); assert_equals(!!received.ignore_read, true);
if (provided.timeout !== undefined)
assert_equals(provided.timeout, received.timeout);
else
assert_equals(received.timeout, Infinity);
if (provided.target !== undefined) if (provided.target !== undefined)
assert_equals(toMojoNDEFPushTarget(provided.target), received.target); assert_equals(toMojoNDEFPushTarget(provided.target), received.target);
else else
...@@ -176,7 +171,6 @@ var WebNFCTest = (() => { ...@@ -176,7 +171,6 @@ var WebNFCTest = (() => {
this.push_options_ = null; this.push_options_ = null;
this.pending_promise_func_ = null; this.pending_promise_func_ = null;
this.push_completed_ = true; this.push_completed_ = true;
this.push_should_timeout_ = false;
this.client_ = null; this.client_ = null;
this.watchers_ = []; this.watchers_ = [];
this.reading_messages_ = []; this.reading_messages_ = [];
...@@ -202,13 +196,8 @@ var WebNFCTest = (() => { ...@@ -202,13 +196,8 @@ var WebNFCTest = (() => {
this.pending_promise_func_ = resolve; this.pending_promise_func_ = resolve;
if (this.operations_suspended_) { if (this.operations_suspended_) {
// Pends push operation if NFC operation is suspended. // Pends push operation if NFC operation is suspended.
} else if (options.timeout && options.timeout !== Infinity && } else if (!this.push_completed_) {
!this.push_completed_) { // Leaves the push operating pending.
// Resolves with TimeoutError, else pend push operation.
if (this.push_should_timeout_) {
resolve(
createNDEFError(device.mojom.NDEFErrorType.TIMER_EXPIRED));
}
} else if (!this.is_ndef_tech_) { } else if (!this.is_ndef_tech_) {
// Resolves with NotSupportedError if the device does not expose // Resolves with NotSupportedError if the device does not expose
// NDEF technology. // NDEF technology.
...@@ -329,7 +318,6 @@ var WebNFCTest = (() => { ...@@ -329,7 +318,6 @@ var WebNFCTest = (() => {
this.pushed_message_ = null; this.pushed_message_ = null;
this.push_options_ = null; this.push_options_ = null;
this.pending_promise_func_ = null; this.pending_promise_func_ = null;
this.push_should_timeout_ = false;
this.push_completed_ = true; this.push_completed_ = true;
} }
...@@ -353,10 +341,6 @@ var WebNFCTest = (() => { ...@@ -353,10 +341,6 @@ var WebNFCTest = (() => {
} }
} }
setPushShouldTimeout(result) {
this.push_should_timeout_ = result;
}
// Suspends all pending NFC operations. Could be used when web page // Suspends all pending NFC operations. Could be used when web page
// visibility is lost. // visibility is lost.
suspendNFCOperations() { suspendNFCOperations() {
......
...@@ -7,9 +7,6 @@ PASS NDEFWriter.push should fail if signal is not an AbortSignal. ...@@ -7,9 +7,6 @@ PASS NDEFWriter.push should fail if signal is not an AbortSignal.
PASS Synchronously signaled abort. PASS Synchronously signaled abort.
PASS NDEFWriter.push should fail when NFC HW is disabled. PASS NDEFWriter.push should fail when NFC HW is disabled.
PASS NDEFWriter.push should fail when NFC HW is not supported. PASS NDEFWriter.push should fail when NFC HW is not supported.
PASS NDEFWriter.push should fail with TypeError when invalid timeout is provided.
PASS NDEFWriter.push should fail with TypeError when invalid negative timeout value is provided.
PASS NDEFWriter.push should fail with TimeoutError when timer expires.
PASS Reject promise with NotSupportedError if NFC message size exceeds 32KB. PASS Reject promise with NotSupportedError if NFC message size exceeds 32KB.
PASS Reject promise with SyntaxError if WebNFC Id cannot be created from provided URL. PASS Reject promise with SyntaxError if WebNFC Id cannot be created from provided URL.
PASS NDEFWriter.push should fail with TypeError when invalid target value is provided. PASS NDEFWriter.push should fail with TypeError when invalid target value is provided.
......
...@@ -133,8 +133,7 @@ nfc_test(async (t, mockNFC) => { ...@@ -133,8 +133,7 @@ nfc_test(async (t, mockNFC) => {
//Make sure push is pending //Make sure push is pending
mockNFC.setPendingPushCompleted(false); mockNFC.setPendingPushCompleted(false);
const p = writer.push(test_text_data, const p = writer.push(test_text_data, { signal: controller.signal });
{ signal: controller.signal, timeout: 100 });
const rejected = promise_rejects(t, 'AbortError', p); const rejected = promise_rejects(t, 'AbortError', p);
let callback_called = false; let callback_called = false;
await new Promise(resolve => { await new Promise(resolve => {
...@@ -173,8 +172,7 @@ nfc_test(async (t, mockNFC) => { ...@@ -173,8 +172,7 @@ nfc_test(async (t, mockNFC) => {
const writer2 = new NDEFWriter(); const writer2 = new NDEFWriter();
const controller = new AbortController(); const controller = new AbortController();
mockNFC.setPendingPushCompleted(false); mockNFC.setPendingPushCompleted(false);
const p1 = writer1.push(test_text_data, const p1 = writer1.push(test_text_data, { signal: controller.signal });
{ signal: controller.signal, timeout: 100 });
// Even though push request is grantable, // Even though push request is grantable,
// this abort should be processed synchronously. // this abort should be processed synchronously.
...@@ -197,28 +195,6 @@ nfc_test(async (t, mockNFC) => { ...@@ -197,28 +195,6 @@ nfc_test(async (t, mockNFC) => {
await promise_rejects(t, 'NotSupportedError', writer.push(test_text_data)); await promise_rejects(t, 'NotSupportedError', writer.push(test_text_data));
}, "NDEFWriter.push should fail when NFC HW is not supported."); }, "NDEFWriter.push should fail when NFC HW is not supported.");
promise_test(async t => {
const writer = new NDEFWriter();
await promise_rejects(
t, new TypeError(), writer.push(test_text_data, { timeout: "invalid"}));
}, "NDEFWriter.push should fail with TypeError when invalid timeout is \
provided.");
promise_test(async t => {
const writer = new NDEFWriter();
await promise_rejects(
t, new TypeError(), writer.push(test_text_data, { timeout: -1 }));
}, "NDEFWriter.push should fail with TypeError when invalid negative timeout \
value is provided.");
nfc_test(async (t, mockNFC) => {
const writer = new NDEFWriter();
mockNFC.setPendingPushCompleted(false);
const p = writer.push(test_text_data, { timeout: 1 });
mockNFC.setPushShouldTimeout(true);
await promise_rejects(t, 'TimeoutError', p);
}, "NDEFWriter.push should fail with TimeoutError when timer expires.");
promise_test(async t => { promise_test(async t => {
const writer = new NDEFWriter(); const writer = new NDEFWriter();
await promise_rejects( await promise_rejects(
...@@ -279,7 +255,7 @@ promise_test(async () => { ...@@ -279,7 +255,7 @@ promise_test(async () => {
nfc_test(async () => { nfc_test(async () => {
const writer = new NDEFWriter(); const writer = new NDEFWriter();
await writer.push(test_text_data, { timeout: 1 }); await writer.push(test_text_data);
}, 'NDEFWriter.push should succeed when NFC HW is enabled'); }, 'NDEFWriter.push should succeed when NFC HW is enabled');
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
...@@ -324,13 +300,13 @@ nfc_test(async () => { ...@@ -324,13 +300,13 @@ nfc_test(async () => {
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
const writer = new NDEFWriter(); const writer = new NDEFWriter();
await writer.push(test_text_data); await writer.push(test_text_data);
assertNDEFPushOptionsEqual(createNDEFPushOptions('any', Infinity, true), assertNDEFPushOptionsEqual(createNDEFPushOptions('any', true),
mockNFC.pushOptions()); mockNFC.pushOptions());
}, "Check that default NDEFPushOptions values are correctly set."); }, "Check that default NDEFPushOptions values are correctly set.");
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
const writer = new NDEFWriter(); const writer = new NDEFWriter();
let ndefPushOptions = createNDEFPushOptions('tag', 1, false); let ndefPushOptions = createNDEFPushOptions('tag', false);
await writer.push(test_text_data, ndefPushOptions); await writer.push(test_text_data, ndefPushOptions);
assertNDEFPushOptionsEqual(ndefPushOptions, mockNFC.pushOptions()); assertNDEFPushOptionsEqual(ndefPushOptions, mockNFC.pushOptions());
}, "Check that provided NDEFPushOptions values are correctly converted."); }, "Check that provided NDEFPushOptions values are correctly converted.");
...@@ -371,8 +347,8 @@ nfc_test(async (t, mockNFC) => { ...@@ -371,8 +347,8 @@ nfc_test(async (t, mockNFC) => {
const writer1 = new NDEFWriter(); const writer1 = new NDEFWriter();
const writer2 = new NDEFWriter(); const writer2 = new NDEFWriter();
const ndefPushOptions1 = createNDEFPushOptions('tag', 1000, false); const ndefPushOptions1 = createNDEFPushOptions('tag', false);
const ndefPushOptions2 = createNDEFPushOptions('tag', Infinity, true); const ndefPushOptions2 = createNDEFPushOptions('tag', true);
const p1 = writer1.push(test_text_data, ndefPushOptions1); const p1 = writer1.push(test_text_data, ndefPushOptions1);
const p2 = writer2.push(test_url_data, ndefPushOptions2); const p2 = writer2.push(test_url_data, ndefPushOptions2);
......
...@@ -14,7 +14,6 @@ The `WebNFCTest` interface is defined as: ...@@ -14,7 +14,6 @@ The `WebNFCTest` interface is defined as:
setHWStatus(number status); // Sets the hardware status. setHWStatus(number status); // Sets the hardware status.
setReadingMessage(NDEFMessageInit message); // Sets message that is used to deliver NFC reading updates. setReadingMessage(NDEFMessageInit message); // Sets message that is used to deliver NFC reading updates.
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.
pushedMessage(); // Gets the pushed `NDEFMessageSource`. pushedMessage(); // Gets the pushed `NDEFMessageSource`.
pushOptions(); // Gets the pushed `NDEFPushOptions`. pushOptions(); // Gets the pushed `NDEFPushOptions`.
setIsNDEFTech(boolean isNDEF); // Sets if the NFC device exposes NDEF technology. setIsNDEFTech(boolean isNDEF); // Sets if the NFC device exposes NDEF technology.
......
...@@ -124,8 +124,8 @@ function createUrlRecord(url, isAbsUrl) { ...@@ -124,8 +124,8 @@ function createUrlRecord(url, isAbsUrl) {
return createRecord('url', url); return createRecord('url', url);
} }
function createNDEFPushOptions(target, timeout, ignoreRead) { function createNDEFPushOptions(target, ignoreRead) {
return {target, timeout, ignoreRead}; return {target, ignoreRead};
} }
// Compares NDEFMessageSource that was provided to the API // Compares NDEFMessageSource that was provided to the API
......
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