Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: third_party/WebKit/Source/modules/nfc/NFC.cpp

Issue 2524743002: [webnfc] Restrict NFC message size to 32KB (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/push.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/nfc/NFC.cpp
diff --git a/third_party/WebKit/Source/modules/nfc/NFC.cpp b/third_party/WebKit/Source/modules/nfc/NFC.cpp
index ac7a95cf4a12254dd5d38df80fa35a226e8a9eff..a986a5840cfe1362de9143f2dc7eb3d0b983ec0f 100644
--- a/third_party/WebKit/Source/modules/nfc/NFC.cpp
+++ b/third_party/WebKit/Source/modules/nfc/NFC.cpp
@@ -426,7 +426,17 @@ bool setURL(const String& origin,
return originURL.isValid();
}
-} // anonymous namespace
+size_t getNFCMessageSize(
kenneth.r.christiansen 2016/11/22 13:11:23 measure instead of get?
+ const device::nfc::mojom::blink::NFCMessagePtr& message) {
+ size_t messageSize = message->url.charactersSizeInBytes();
+ for (size_t i = 0; i < message->data.size(); ++i) {
+ messageSize += message->data[i]->media_type.charactersSizeInBytes();
+ messageSize += message->data[i]->data.size();
+ }
+ return messageSize;
+}
+
+} // namespace
NFC::NFC(LocalFrame* frame)
: PageVisibilityObserver(frame->page()),
@@ -488,6 +498,12 @@ ScriptPromise NFC::push(ScriptState* scriptState,
return ScriptPromise::rejectWithDOMException(
scriptState, DOMException::create(SyntaxError));
+ if (getNFCMessageSize(message) >
+ device::nfc::mojom::blink::NFCMessage::kMaxSize) {
+ return ScriptPromise::rejectWithDOMException(
+ scriptState, DOMException::create(NotSupportedError));
+ }
+
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
m_requests.add(resolver);
auto callback = convertToBaseCallback(WTF::bind(&NFC::OnRequestCompleted,
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/push.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698