Commit b9004eca authored by Leon Han's avatar Leon Han Committed by Commit Bot

[webnfc] Remove the limitation on the size of NDEF message

Per the discussion at
https://github.com/w3c/web-nfc/issues/523#issuecomment-581785547,
such size limitation does not make much sense and does not bring much
benefit to WebDevs.

The spec issue:
https://github.com/w3c/web-nfc/issues/523

BUG=520391,1048096

Change-Id: Id5fcc8c349ac220c460646f055b78b812da8aeba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2037310Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarFrançois Beaufort <beaufort.francois@gmail.com>
Commit-Queue: Leon Han <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#738900}
parent 6c5f20cb
......@@ -543,10 +543,6 @@ public class NfcImpl implements Nfc {
notifyMatchingWatchers(webNdefMessage);
return;
}
if (message.getByteArrayLength() > NdefMessage.MAX_SIZE) {
Log.w(TAG, "Cannot read data from NFC tag. NdefMessage exceeds allowed size.");
return;
}
NdefMessage webNdefMessage = NdefMessageUtils.toNdefMessage(message);
notifyMatchingWatchers(webNdefMessage);
} catch (UnsupportedEncodingException e) {
......
......@@ -82,12 +82,18 @@ struct NDEFRecord {
NDEFMessage? payload_message;
};
// Mojo has a maximum size limit usually in megabytes for messages sent/received
// via message pipes, possibly like 256M or 128M.
//
// On the reading direction, the NDEFMessage is read from an NFC tag which can
// never have so large storage, so we'll never exceed the size limit above.
//
// On the writing direction, if the NDEFMessage input from users exceeds the
// limit, Mojo will raise a crash for the sender process, which is specifically
// the renderer process for our WebNFC impl.
struct NDEFMessage {
// The body of the NDEFMessage is a collection of NDEFRecord objects.
array<NDEFRecord> data;
// Maximum size of NFC message that can be sent over IPC is 32KB.
const uint32 kMaxSize = 32768;
};
struct NDEFWriteOptions {
......
......@@ -77,14 +77,6 @@ ScriptPromise NDEFWriter::write(ScriptState* script_state,
auto message = device::mojom::blink::NDEFMessage::From(ndef_message);
DCHECK(message);
if (GetNDEFMessageSize(*message) >
device::mojom::blink::NDEFMessage::kMaxSize) {
exception_state.ThrowDOMException(
DOMExceptionCode::kNotSupportedError,
"NDEFMessage exceeds maximum supported size.");
return ScriptPromise();
}
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
requests_.insert(resolver);
InitNfcProxyIfNeeded();
......
......@@ -12,15 +12,6 @@
namespace blink {
size_t GetNDEFMessageSize(const device::mojom::blink::NDEFMessage& message) {
size_t message_size = 0;
for (wtf_size_t i = 0; i < message.data.size(); ++i) {
message_size += message.data[i]->media_type.CharactersSizeInBytes();
message_size += message.data[i]->data.size();
}
return message_size;
}
DOMException* NDEFErrorTypeToDOMException(
device::mojom::blink::NDEFErrorType error_type,
const String& error_message) {
......
......@@ -12,8 +12,6 @@ namespace blink {
class DOMException;
size_t GetNDEFMessageSize(const device::mojom::blink::NDEFMessage& message);
DOMException* NDEFErrorTypeToDOMException(
device::mojom::blink::NDEFErrorType error_type,
const String& error_message);
......
......@@ -9,7 +9,6 @@ PASS NDEFWriter.write should fail if signal is not an AbortSignal.
PASS Synchronously signaled abort.
PASS NDEFWriter.write should fail when NFC HW is disabled.
PASS NDEFWriter.write should fail when NFC HW is not supported.
PASS Reject promise with NotSupportedError if NFC message size exceeds 32KB.
PASS Test that WebNFC API is not accessible from iframe context.
PASS NDEFWriter.write should succeed when NFC HW is enabled
PASS NDEFWriter.write NDEFMessage containing text, mime, unknown, url, absolute-url and external records with default NDEFWriteOptions.
......
......@@ -223,12 +223,6 @@ nfc_test(async (t, mockNFC) => {
await promise_rejects(t, 'NotSupportedError', writer.write(test_text_data));
}, "NDEFWriter.write should fail when NFC HW is not supported.");
promise_test(async t => {
const writer = new NDEFWriter();
await promise_rejects(
t, 'NotSupportedError', writer.write(new ArrayBuffer(32 * 1024 + 1)));
}, "Reject promise with NotSupportedError if NFC message size exceeds 32KB.");
promise_test(async () => {
await new Promise((resolve,reject) => {
const iframe = document.createElement('iframe');
......
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