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

Side by Side Diff: third_party/WebKit/Source/modules/nfc/NFC.cpp

Issue 2885813002: [webnfc] Align nfc.push operation with the specification (Closed)
Patch Set: Fixes for comments + new tests. Created 3 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/push.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/nfc/NFC.h" 5 #include "modules/nfc/NFC.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "bindings/core/v8/V8ArrayBuffer.h" 8 #include "bindings/core/v8/V8ArrayBuffer.h"
9 #include "bindings/core/v8/V8StringResource.h" 9 #include "bindings/core/v8/V8StringResource.h"
10 #include "core/dom/DOMArrayBuffer.h" 10 #include "core/dom/DOMArrayBuffer.h"
11 #include "core/dom/DOMException.h" 11 #include "core/dom/DOMException.h"
12 #include "core/dom/Document.h" 12 #include "core/dom/Document.h"
13 #include "core/dom/ExceptionCode.h" 13 #include "core/dom/ExceptionCode.h"
14 #include "core/dom/ExecutionContext.h" 14 #include "core/dom/ExecutionContext.h"
15 #include "core/frame/LocalDOMWindow.h" 15 #include "core/frame/LocalDOMWindow.h"
16 #include "modules/nfc/NFCError.h" 16 #include "modules/nfc/NFCError.h"
17 #include "modules/nfc/NFCMessage.h" 17 #include "modules/nfc/NFCMessage.h"
18 #include "modules/nfc/NFCPushOptions.h" 18 #include "modules/nfc/NFCPushOptions.h"
19 #include "modules/nfc/NFCWatchOptions.h" 19 #include "modules/nfc/NFCWatchOptions.h"
20 #include "platform/mojo/MojoHelper.h" 20 #include "platform/mojo/MojoHelper.h"
21 #include "public/platform/InterfaceProvider.h" 21 #include "public/platform/InterfaceProvider.h"
22 #include "public/platform/Platform.h" 22 #include "public/platform/Platform.h"
23 23
24 namespace { 24 namespace {
25 const char kJsonMimePostfix[] = "+json";
25 const char kJsonMimePrefix[] = "application/"; 26 const char kJsonMimePrefix[] = "application/";
26 const char kJsonMimeType[] = "application/json"; 27 const char kJsonMimeType[] = "application/json";
27 const char kOpaqueMimeType[] = "application/octet-stream"; 28 const char kOpaqueMimeType[] = "application/octet-stream";
28 const char kPlainTextMimeType[] = "text/plain"; 29 const char kPlainTextMimeType[] = "text/plain";
29 const char kPlainTextMimePrefix[] = "text/"; 30 const char kPlainTextMimePrefix[] = "text/";
30 const char kCharSetUTF8[] = ";charset=UTF-8"; 31 const char kCharSetUTF8[] = ";charset=UTF-8";
31 } // anonymous namespace 32 } // anonymous namespace
32 33
33 // Mojo type converters 34 // Mojo type converters
34 namespace mojo { 35 namespace mojo {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (value->IsString()) { 185 if (value->IsString()) {
185 blink::V8StringResource<> stringResource = value; 186 blink::V8StringResource<> stringResource = value;
186 if (stringResource.Prepare()) { 187 if (stringResource.Prepare()) {
187 return mojo::ConvertTo<WTF::Vector<uint8_t>>( 188 return mojo::ConvertTo<WTF::Vector<uint8_t>>(
188 WTF::String(stringResource)); 189 WTF::String(stringResource));
189 } 190 }
190 } 191 }
191 192
192 if (value->IsObject() && !value->IsArray() && !value->IsArrayBuffer()) { 193 if (value->IsObject() && !value->IsArray() && !value->IsArrayBuffer()) {
193 v8::Local<v8::String> jsonString; 194 v8::Local<v8::String> jsonString;
194 if (v8::JSON::Stringify(scriptValue.GetContext(), value.As<v8::Object>()) 195 v8::Isolate* isolate = scriptValue.GetIsolate();
195 .ToLocal(&jsonString)) { 196 v8::TryCatch try_catch(isolate);
196 WTF::String wtfString = blink::V8StringToWebCoreString<WTF::String>( 197 v8::MaybeLocal<v8::String> stringify_result =
197 jsonString, blink::kDoNotExternalize); 198 v8::JSON::Stringify(scriptValue.GetContext(), value.As<v8::Object>());
198 return mojo::ConvertTo<WTF::Vector<uint8_t>>(wtfString); 199
200 // Return null if object cannot be stringified.
201 if (!stringify_result.ToLocal(&jsonString) || try_catch.HasCaught()) {
haraken 2017/05/17 15:11:22 I prefer avoiding using a MaybeLocal handle. v8::
shalamov 2017/05/18 08:34:03 I removed temporary MaybeLocal, but I left try_cat
202 return WTF::nullopt;
199 } 203 }
204
205 WTF::String wtfString = blink::V8StringToWebCoreString<WTF::String>(
haraken 2017/05/17 15:11:22 WTF:: won't be needed. blink:: won't be needed.
shalamov 2017/05/18 08:34:03 WTF:: is not needed. Removed in other places as we
206 jsonString, blink::kDoNotExternalize);
207 return mojo::ConvertTo<WTF::Vector<uint8_t>>(wtfString);
200 } 208 }
201 209
202 if (value->IsArrayBuffer()) 210 if (value->IsArrayBuffer())
203 return mojo::ConvertTo<WTF::Vector<uint8_t>>( 211 return mojo::ConvertTo<WTF::Vector<uint8_t>>(
204 blink::V8ArrayBuffer::toImpl(value.As<v8::Object>())); 212 blink::V8ArrayBuffer::toImpl(value.As<v8::Object>()));
205 213
206 return WTF::nullopt; 214 return WTF::nullopt;
207 } 215 }
208 }; 216 };
209 217
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 354
347 return watchOptionsPtr; 355 return watchOptionsPtr;
348 } 356 }
349 }; 357 };
350 358
351 } // namespace mojo 359 } // namespace mojo
352 360
353 namespace blink { 361 namespace blink {
354 namespace { 362 namespace {
355 363
356 bool IsValidTextRecord(const NFCRecord& record) { 364 ScriptPromise RejectWithTypeError(ScriptState* script_state,
365 const String& message) {
366 return ScriptPromise::Reject(
367 script_state,
368 V8ThrowException::CreateTypeError(script_state->GetIsolate(), message));
369 }
370
371 ScriptPromise RejectWithDOMException(ScriptState* script_state,
372 ExceptionCode ec,
373 const String& message) {
374 return ScriptPromise::RejectWithDOMException(
375 script_state, DOMException::Create(ec, message));
376 }
377
378 ScriptPromise RejectIfInvalidTextRecord(ScriptState* script_state,
379 const NFCRecord& record) {
357 v8::Local<v8::Value> value = record.data().V8Value(); 380 v8::Local<v8::Value> value = record.data().V8Value();
358 if (!value->IsString() && 381 if (!value->IsString() &&
359 !(value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value()))) 382 !(value->IsNumber() && !std::isnan(value.As<v8::Number>()->Value()))) {
360 return false; 383 return RejectWithTypeError(script_state,
384 "The data for the 'text' NFCRecords must be of "
385 "String or UnrestrctedDouble type.");
386 }
361 387
362 if (record.hasMediaType() && 388 if (record.hasMediaType() &&
363 !record.mediaType().StartsWith(kPlainTextMimePrefix, 389 !record.mediaType().StartsWith(kPlainTextMimePrefix,
364 kTextCaseUnicodeInsensitive)) 390 kTextCaseUnicodeInsensitive)) {
365 return false; 391 return RejectWithDOMException(script_state, kSyntaxError,
392 "Invalid media type for 'text' record.");
393 }
366 394
367 return true; 395 return ScriptPromise();
368 } 396 }
369 397
370 bool IsValidURLRecord(const NFCRecord& record) { 398 ScriptPromise RejectIfInvalidURLRecord(ScriptState* script_state,
371 if (!record.data().V8Value()->IsString()) 399 const NFCRecord& record) {
372 return false; 400 if (!record.data().V8Value()->IsString()) {
401 return RejectWithTypeError(
402 script_state,
403 "The data for the 'url' NFCRecord must be of String type.");
404 }
373 405
374 blink::V8StringResource<> string_resource = record.data().V8Value(); 406 blink::V8StringResource<> string_resource = record.data().V8Value();
375 if (!string_resource.Prepare()) 407 if (!string_resource.Prepare() || !KURL(KURL(), string_resource).IsValid()) {
376 return false; 408 return RejectWithDOMException(script_state, kSyntaxError,
409 "Cannot parse data for 'url' record.");
410 }
377 411
378 return KURL(KURL(), string_resource).IsValid(); 412 return ScriptPromise();
379 } 413 }
380 414
381 bool IsValidJSONRecord(const NFCRecord& record) { 415 ScriptPromise RejectIfInvalidJSONRecord(ScriptState* script_state,
416 const NFCRecord& record) {
382 v8::Local<v8::Value> value = record.data().V8Value(); 417 v8::Local<v8::Value> value = record.data().V8Value();
383 if (!value->IsObject() || value->IsArrayBuffer()) 418 if (!value->IsObject() || value->IsArrayBuffer()) {
384 return false; 419 return RejectWithTypeError(
420 script_state,
421 "The data for the 'json' NFCRecord must be of Object type.");
422 }
385 423
386 if (record.hasMediaType() && !record.mediaType().StartsWith( 424 // If JSON record has media type, it must be equal to "application/json" or
387 kJsonMimePrefix, kTextCaseASCIIInsensitive)) 425 // start with "application/" and end with "+json".
388 return false; 426 if (record.hasMediaType() &&
427 (record.mediaType() != kJsonMimeType &&
428 !(record.mediaType().StartsWith(kJsonMimePrefix,
429 kTextCaseASCIIInsensitive) &&
430 record.mediaType().EndsWith(kJsonMimePostfix,
431 kTextCaseASCIIInsensitive)))) {
432 return RejectWithDOMException(script_state, kSyntaxError,
433 "Invalid media type for 'json' record.");
434 }
389 435
390 return true; 436 return ScriptPromise();
391 } 437 }
392 438
393 bool IsValidOpaqueRecord(const NFCRecord& record) { 439 ScriptPromise RejectIfInvalidOpaqueRecord(ScriptState* script_state,
394 return record.data().V8Value()->IsArrayBuffer(); 440 const NFCRecord& record) {
441 if (!record.data().V8Value()->IsArrayBuffer()) {
442 return RejectWithTypeError(
443 script_state,
444 "The data for the 'opaque' NFCRecord must be of ArrayBuffer type.");
445 }
446
447 return ScriptPromise();
395 } 448 }
396 449
397 bool IsValidNFCRecord(const NFCRecord& record) { 450 ScriptPromise RejectIfInvalidNFCRecord(ScriptState* script_state,
451 const NFCRecord& record) {
398 device::nfc::mojom::blink::NFCRecordType type; 452 device::nfc::mojom::blink::NFCRecordType type;
399 if (record.hasRecordType()) { 453 if (record.hasRecordType()) {
400 type = mojo::toNFCRecordType(record.recordType()); 454 type = mojo::toNFCRecordType(record.recordType());
401 } else { 455 } else {
402 type = mojo::deduceRecordTypeFromDataType(record); 456 type = mojo::deduceRecordTypeFromDataType(record);
403 457
404 // https://w3c.github.io/web-nfc/#creating-web-nfc-message 458 // https://w3c.github.io/web-nfc/#creating-web-nfc-message
405 // If NFCRecord.recordType is not set and record type cannot be deduced 459 // If NFCRecord.recordType is not set and record type cannot be deduced
406 // from NFCRecord.data, reject promise with SyntaxError. 460 // from NFCRecord.data, reject promise with TypeError.
407 if (type == device::nfc::mojom::blink::NFCRecordType::EMPTY) 461 if (type == device::nfc::mojom::blink::NFCRecordType::EMPTY)
408 return false; 462 return RejectWithTypeError(script_state, "Unknown NFCRecord type.");
409 } 463 }
410 464
411 // Non-empty records must have data. 465 // Non-empty records must have data.
412 if (!record.hasData() && 466 if (!record.hasData() &&
413 (type != device::nfc::mojom::blink::NFCRecordType::EMPTY)) { 467 (type != device::nfc::mojom::blink::NFCRecordType::EMPTY)) {
414 return false; 468 return RejectWithTypeError(script_state,
469 "Nonempty NFCRecord must have data.");
415 } 470 }
416 471
417 switch (type) { 472 switch (type) {
418 case device::nfc::mojom::blink::NFCRecordType::TEXT: 473 case device::nfc::mojom::blink::NFCRecordType::TEXT:
419 return IsValidTextRecord(record); 474 return RejectIfInvalidTextRecord(script_state, record);
420 case device::nfc::mojom::blink::NFCRecordType::URL: 475 case device::nfc::mojom::blink::NFCRecordType::URL:
421 return IsValidURLRecord(record); 476 return RejectIfInvalidURLRecord(script_state, record);
422 case device::nfc::mojom::blink::NFCRecordType::JSON: 477 case device::nfc::mojom::blink::NFCRecordType::JSON:
423 return IsValidJSONRecord(record); 478 return RejectIfInvalidJSONRecord(script_state, record);
424 case device::nfc::mojom::blink::NFCRecordType::OPAQUE_RECORD: 479 case device::nfc::mojom::blink::NFCRecordType::OPAQUE_RECORD:
425 return IsValidOpaqueRecord(record); 480 return RejectIfInvalidOpaqueRecord(script_state, record);
426 case device::nfc::mojom::blink::NFCRecordType::EMPTY: 481 case device::nfc::mojom::blink::NFCRecordType::EMPTY:
427 return !record.hasData() && record.mediaType().IsEmpty(); 482 return ScriptPromise();
428 } 483 }
429 484
430 NOTREACHED(); 485 NOTREACHED();
431 return false; 486 return RejectWithTypeError(script_state,
487 "Invalid NFCRecordType was provided.");
432 } 488 }
433 489
434 bool IsValidNFCRecordArray(const HeapVector<NFCRecord>& records) { 490 ScriptPromise RejectIfInvalidNFCRecordArray(
435 if (records.IsEmpty()) 491 ScriptState* script_state,
436 return false; 492 const HeapVector<NFCRecord>& records) {
437
438 for (const auto& record : records) { 493 for (const auto& record : records) {
439 if (!IsValidNFCRecord(record)) 494 ScriptPromise isValidRecord =
440 return false; 495 RejectIfInvalidNFCRecord(script_state, record);
496 if (!isValidRecord.IsEmpty())
497 return isValidRecord;
441 } 498 }
442 499
443 return true; 500 return ScriptPromise();
444 } 501 }
445 502
446 bool IsValidNFCPushMessage(const NFCPushMessage& message) { 503 ScriptPromise RejectIfInvalidNFCPushMessage(
504 ScriptState* script_state,
505 const NFCPushMessage& push_message) {
447 // If NFCPushMessage of invalid type, reject promise with TypeError 506 // If NFCPushMessage of invalid type, reject promise with TypeError
448 if (!message.isNFCMessage() && !message.isString() && 507 if (!push_message.isNFCMessage() && !push_message.isString() &&
449 !message.isArrayBuffer()) 508 !push_message.isArrayBuffer()) {
450 return false; 509 return RejectWithTypeError(script_state,
510 "Invalid NFCPushMessage type was provided.");
511 }
451 512
452 if (message.isNFCMessage()) { 513 if (push_message.isNFCMessage()) {
453 // https://w3c.github.io/web-nfc/#the-push-method 514 // https://w3c.github.io/web-nfc/#the-push-method
454 // If NFCMessage.data is empty, reject promise with TypeError 515 // If NFCMessage.data is empty, reject promise with TypeError
455 if (!message.getAsNFCMessage().hasData()) 516 const NFCMessage& message = push_message.getAsNFCMessage();
456 return false; 517 if (!message.hasData() || message.data().IsEmpty()) {
518 return RejectWithTypeError(script_state,
519 "Empty NFCMessage was provided.");
520 }
457 521
458 return IsValidNFCRecordArray(message.getAsNFCMessage().data()); 522 return RejectIfInvalidNFCRecordArray(script_state, message.data());
459 } 523 }
460 524
461 return true; 525 return ScriptPromise();
462 } 526 }
463 527
464 bool SetURL(const String& origin, 528 bool SetURL(const String& origin,
465 device::nfc::mojom::blink::NFCMessagePtr& message) { 529 device::nfc::mojom::blink::NFCMessagePtr& message) {
466 KURL origin_url(kParsedURLString, origin); 530 KURL origin_url(kParsedURLString, origin);
467 531
468 if (!message->url.IsEmpty() && origin_url.CanSetPathname()) { 532 if (!message->url.IsEmpty() && origin_url.CanSetPathname()) {
469 origin_url.SetPath(message->url); 533 origin_url.SetPath(message->url);
470 } 534 }
471 535
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 678
615 // https://w3c.github.io/web-nfc/#writing-or-pushing-content 679 // https://w3c.github.io/web-nfc/#writing-or-pushing-content
616 // https://w3c.github.io/web-nfc/#dom-nfc-push 680 // https://w3c.github.io/web-nfc/#dom-nfc-push
617 ScriptPromise NFC::push(ScriptState* script_state, 681 ScriptPromise NFC::push(ScriptState* script_state,
618 const NFCPushMessage& push_message, 682 const NFCPushMessage& push_message,
619 const NFCPushOptions& options) { 683 const NFCPushOptions& options) {
620 ScriptPromise promise = RejectIfNotSupported(script_state); 684 ScriptPromise promise = RejectIfNotSupported(script_state);
621 if (!promise.IsEmpty()) 685 if (!promise.IsEmpty())
622 return promise; 686 return promise;
623 687
624 if (!IsValidNFCPushMessage(push_message)) { 688 ScriptPromise isValidMessage =
625 return ScriptPromise::Reject( 689 RejectIfInvalidNFCPushMessage(script_state, push_message);
626 script_state, V8ThrowException::CreateTypeError( 690 if (!isValidMessage.IsEmpty())
627 script_state->GetIsolate(), 691 return isValidMessage;
628 "Invalid NFCPushMessage type was provided."));
629 }
630 692
631 // https://w3c.github.io/web-nfc/#dom-nfc-push 693 // https://w3c.github.io/web-nfc/#dom-nfc-push
632 // 9. If timeout value is NaN or negative, reject promise with "TypeError" 694 // 9. If timeout value is NaN or negative, reject promise with "TypeError"
633 // and abort these steps. 695 // and abort these steps.
634 if (options.hasTimeout() && 696 if (options.hasTimeout() &&
635 (std::isnan(options.timeout()) || options.timeout() < 0)) { 697 (std::isnan(options.timeout()) || options.timeout() < 0)) {
636 return ScriptPromise::Reject( 698 return RejectWithTypeError(
637 script_state, 699 script_state, "Invalid NFCPushOptions.timeout value was provided.");
638 V8ThrowException::CreateTypeError(
639 script_state->GetIsolate(),
640 "Invalid NFCPushOptions.timeout value was provided."));
641 } 700 }
642 701
643 device::nfc::mojom::blink::NFCMessagePtr message = 702 device::nfc::mojom::blink::NFCMessagePtr message =
644 device::nfc::mojom::blink::NFCMessage::From(push_message); 703 device::nfc::mojom::blink::NFCMessage::From(push_message);
645 if (!message) 704 if (!message) {
646 return ScriptPromise::RejectWithDOMException( 705 return RejectWithDOMException(script_state, kSyntaxError,
647 script_state, DOMException::Create(kSyntaxError)); 706 "Cannot convert NFCMessage.");
707 }
648 708
649 if (!SetURL( 709 if (!SetURL(
650 ExecutionContext::From(script_state)->GetSecurityOrigin()->ToString(), 710 ExecutionContext::From(script_state)->GetSecurityOrigin()->ToString(),
651 message)) 711 message)) {
652 return ScriptPromise::RejectWithDOMException( 712 return RejectWithDOMException(script_state, kSyntaxError,
653 script_state, DOMException::Create(kSyntaxError)); 713 "Cannot set WebNFC Id.");
714 }
654 715
655 if (GetNFCMessageSize(message) > 716 if (GetNFCMessageSize(message) >
656 device::nfc::mojom::blink::NFCMessage::kMaxSize) { 717 device::nfc::mojom::blink::NFCMessage::kMaxSize) {
657 return ScriptPromise::RejectWithDOMException( 718 return RejectWithDOMException(script_state, kNotSupportedError,
658 script_state, DOMException::Create(kNotSupportedError)); 719 "NFCMessage exceeds maximum supported size.");
659 } 720 }
660 721
661 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 722 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
662 requests_.insert(resolver); 723 requests_.insert(resolver);
663 auto callback = ConvertToBaseCallback(WTF::Bind(&NFC::OnRequestCompleted, 724 auto callback = ConvertToBaseCallback(WTF::Bind(&NFC::OnRequestCompleted,
664 WrapPersistent(this), 725 WrapPersistent(this),
665 WrapPersistent(resolver))); 726 WrapPersistent(resolver)));
666 nfc_->Push(std::move(message), 727 nfc_->Push(std::move(message),
667 device::nfc::mojom::blink::NFCPushOptions::From(options), 728 device::nfc::mojom::blink::NFCPushOptions::From(options),
668 callback); 729 callback);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 769
709 // https://w3c.github.io/web-nfc/#dom-nfc-cancelwatch 770 // https://w3c.github.io/web-nfc/#dom-nfc-cancelwatch
710 ScriptPromise NFC::cancelWatch(ScriptState* script_state, long id) { 771 ScriptPromise NFC::cancelWatch(ScriptState* script_state, long id) {
711 ScriptPromise promise = RejectIfNotSupported(script_state); 772 ScriptPromise promise = RejectIfNotSupported(script_state);
712 if (!promise.IsEmpty()) 773 if (!promise.IsEmpty())
713 return promise; 774 return promise;
714 775
715 if (id) { 776 if (id) {
716 callbacks_.erase(id); 777 callbacks_.erase(id);
717 } else { 778 } else {
718 return ScriptPromise::RejectWithDOMException( 779 return RejectWithDOMException(script_state, kNotFoundError,
719 script_state, DOMException::Create(kNotFoundError)); 780 "Provided watch id cannot be found.");
720 } 781 }
721 782
722 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 783 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
723 requests_.insert(resolver); 784 requests_.insert(resolver);
724 nfc_->CancelWatch(id, ConvertToBaseCallback(WTF::Bind( 785 nfc_->CancelWatch(id, ConvertToBaseCallback(WTF::Bind(
725 &NFC::OnRequestCompleted, WrapPersistent(this), 786 &NFC::OnRequestCompleted, WrapPersistent(this),
726 WrapPersistent(resolver)))); 787 WrapPersistent(resolver))));
727 return resolver->Promise(); 788 return resolver->Promise();
728 } 789 }
729 790
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 return false; 871 return false;
811 } 872 }
812 873
813 return true; 874 return true;
814 } 875 }
815 876
816 ScriptPromise NFC::RejectIfNotSupported(ScriptState* script_state) { 877 ScriptPromise NFC::RejectIfNotSupported(ScriptState* script_state) {
817 String error_message; 878 String error_message;
818 if (!IsSupportedInContext(ExecutionContext::From(script_state), 879 if (!IsSupportedInContext(ExecutionContext::From(script_state),
819 error_message)) { 880 error_message)) {
820 return ScriptPromise::RejectWithDOMException( 881 return RejectWithDOMException(script_state, kSecurityError, error_message);
821 script_state, DOMException::Create(kSecurityError, error_message));
822 } 882 }
823 883
824 if (!nfc_) { 884 if (!nfc_) {
825 return ScriptPromise::RejectWithDOMException( 885 return RejectWithDOMException(script_state, kNotSupportedError,
826 script_state, DOMException::Create(kNotSupportedError)); 886 "WebNFC is not supported.");
827 } 887 }
828 888
829 return ScriptPromise(); 889 return ScriptPromise();
830 } 890 }
831 891
832 void NFC::OnWatchRegistered(MessageCallback* callback, 892 void NFC::OnWatchRegistered(MessageCallback* callback,
833 ScriptPromiseResolver* resolver, 893 ScriptPromiseResolver* resolver,
834 uint32_t id, 894 uint32_t id,
835 device::nfc::mojom::blink::NFCErrorPtr error) { 895 device::nfc::mojom::blink::NFCErrorPtr error) {
836 requests_.erase(resolver); 896 requests_.erase(resolver);
(...skipping 17 matching lines...) Expand all
854 } 914 }
855 915
856 DEFINE_TRACE(NFC) { 916 DEFINE_TRACE(NFC) {
857 PageVisibilityObserver::Trace(visitor); 917 PageVisibilityObserver::Trace(visitor);
858 ContextLifecycleObserver::Trace(visitor); 918 ContextLifecycleObserver::Trace(visitor);
859 visitor->Trace(requests_); 919 visitor->Trace(requests_);
860 visitor->Trace(callbacks_); 920 visitor->Trace(callbacks_);
861 } 921 }
862 922
863 } // namespace blink 923 } // namespace blink
OLDNEW
« 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