| OLD | NEW |
| 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" |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 return ScriptPromise::rejectWithDOMException( | 629 return ScriptPromise::rejectWithDOMException( |
| 630 scriptState, DOMException::create(SyntaxError)); | 630 scriptState, DOMException::create(SyntaxError)); |
| 631 | 631 |
| 632 if (getNFCMessageSize(message) > | 632 if (getNFCMessageSize(message) > |
| 633 device::nfc::mojom::blink::NFCMessage::kMaxSize) { | 633 device::nfc::mojom::blink::NFCMessage::kMaxSize) { |
| 634 return ScriptPromise::rejectWithDOMException( | 634 return ScriptPromise::rejectWithDOMException( |
| 635 scriptState, DOMException::create(NotSupportedError)); | 635 scriptState, DOMException::create(NotSupportedError)); |
| 636 } | 636 } |
| 637 | 637 |
| 638 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 638 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 639 m_requests.add(resolver); | 639 m_requests.insert(resolver); |
| 640 auto callback = convertToBaseCallback(WTF::bind(&NFC::OnRequestCompleted, | 640 auto callback = convertToBaseCallback(WTF::bind(&NFC::OnRequestCompleted, |
| 641 wrapPersistent(this), | 641 wrapPersistent(this), |
| 642 wrapPersistent(resolver))); | 642 wrapPersistent(resolver))); |
| 643 m_nfc->Push(std::move(message), | 643 m_nfc->Push(std::move(message), |
| 644 device::nfc::mojom::blink::NFCPushOptions::From(options), | 644 device::nfc::mojom::blink::NFCPushOptions::From(options), |
| 645 callback); | 645 callback); |
| 646 | 646 |
| 647 return resolver->promise(); | 647 return resolver->promise(); |
| 648 } | 648 } |
| 649 | 649 |
| 650 // https://w3c.github.io/web-nfc/#dom-nfc-cancelpush | 650 // https://w3c.github.io/web-nfc/#dom-nfc-cancelpush |
| 651 ScriptPromise NFC::cancelPush(ScriptState* scriptState, const String& target) { | 651 ScriptPromise NFC::cancelPush(ScriptState* scriptState, const String& target) { |
| 652 ScriptPromise promise = rejectIfNotSupported(scriptState); | 652 ScriptPromise promise = rejectIfNotSupported(scriptState); |
| 653 if (!promise.isEmpty()) | 653 if (!promise.isEmpty()) |
| 654 return promise; | 654 return promise; |
| 655 | 655 |
| 656 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 656 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 657 m_requests.add(resolver); | 657 m_requests.insert(resolver); |
| 658 auto callback = convertToBaseCallback(WTF::bind(&NFC::OnRequestCompleted, | 658 auto callback = convertToBaseCallback(WTF::bind(&NFC::OnRequestCompleted, |
| 659 wrapPersistent(this), | 659 wrapPersistent(this), |
| 660 wrapPersistent(resolver))); | 660 wrapPersistent(resolver))); |
| 661 m_nfc->CancelPush(mojo::toNFCPushTarget(target), callback); | 661 m_nfc->CancelPush(mojo::toNFCPushTarget(target), callback); |
| 662 | 662 |
| 663 return resolver->promise(); | 663 return resolver->promise(); |
| 664 } | 664 } |
| 665 | 665 |
| 666 // https://w3c.github.io/web-nfc/#watching-for-content | 666 // https://w3c.github.io/web-nfc/#watching-for-content |
| 667 // https://w3c.github.io/web-nfc/#dom-nfc-watch | 667 // https://w3c.github.io/web-nfc/#dom-nfc-watch |
| 668 ScriptPromise NFC::watch(ScriptState* scriptState, | 668 ScriptPromise NFC::watch(ScriptState* scriptState, |
| 669 MessageCallback* callback, | 669 MessageCallback* callback, |
| 670 const NFCWatchOptions& options) { | 670 const NFCWatchOptions& options) { |
| 671 ScriptPromise promise = rejectIfNotSupported(scriptState); | 671 ScriptPromise promise = rejectIfNotSupported(scriptState); |
| 672 if (!promise.isEmpty()) | 672 if (!promise.isEmpty()) |
| 673 return promise; | 673 return promise; |
| 674 | 674 |
| 675 callback->setScriptState(scriptState); | 675 callback->setScriptState(scriptState); |
| 676 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 676 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 677 m_requests.add(resolver); | 677 m_requests.insert(resolver); |
| 678 auto watchCallback = convertToBaseCallback( | 678 auto watchCallback = convertToBaseCallback( |
| 679 WTF::bind(&NFC::OnWatchRegistered, wrapPersistent(this), | 679 WTF::bind(&NFC::OnWatchRegistered, wrapPersistent(this), |
| 680 wrapPersistent(callback), wrapPersistent(resolver))); | 680 wrapPersistent(callback), wrapPersistent(resolver))); |
| 681 m_nfc->Watch(device::nfc::mojom::blink::NFCWatchOptions::From(options), | 681 m_nfc->Watch(device::nfc::mojom::blink::NFCWatchOptions::From(options), |
| 682 watchCallback); | 682 watchCallback); |
| 683 return resolver->promise(); | 683 return resolver->promise(); |
| 684 } | 684 } |
| 685 | 685 |
| 686 // https://w3c.github.io/web-nfc/#dom-nfc-cancelwatch | 686 // https://w3c.github.io/web-nfc/#dom-nfc-cancelwatch |
| 687 ScriptPromise NFC::cancelWatch(ScriptState* scriptState, long id) { | 687 ScriptPromise NFC::cancelWatch(ScriptState* scriptState, long id) { |
| 688 ScriptPromise promise = rejectIfNotSupported(scriptState); | 688 ScriptPromise promise = rejectIfNotSupported(scriptState); |
| 689 if (!promise.isEmpty()) | 689 if (!promise.isEmpty()) |
| 690 return promise; | 690 return promise; |
| 691 | 691 |
| 692 if (id) { | 692 if (id) { |
| 693 m_callbacks.remove(id); | 693 m_callbacks.remove(id); |
| 694 } else { | 694 } else { |
| 695 return ScriptPromise::rejectWithDOMException( | 695 return ScriptPromise::rejectWithDOMException( |
| 696 scriptState, DOMException::create(NotFoundError)); | 696 scriptState, DOMException::create(NotFoundError)); |
| 697 } | 697 } |
| 698 | 698 |
| 699 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 699 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 700 m_requests.add(resolver); | 700 m_requests.insert(resolver); |
| 701 m_nfc->CancelWatch(id, convertToBaseCallback(WTF::bind( | 701 m_nfc->CancelWatch(id, convertToBaseCallback(WTF::bind( |
| 702 &NFC::OnRequestCompleted, wrapPersistent(this), | 702 &NFC::OnRequestCompleted, wrapPersistent(this), |
| 703 wrapPersistent(resolver)))); | 703 wrapPersistent(resolver)))); |
| 704 return resolver->promise(); | 704 return resolver->promise(); |
| 705 } | 705 } |
| 706 | 706 |
| 707 // https://w3c.github.io/web-nfc/#dom-nfc-cancelwatch | 707 // https://w3c.github.io/web-nfc/#dom-nfc-cancelwatch |
| 708 // If watchId is not provided to nfc.cancelWatch, cancel all watch operations. | 708 // If watchId is not provided to nfc.cancelWatch, cancel all watch operations. |
| 709 ScriptPromise NFC::cancelWatch(ScriptState* scriptState) { | 709 ScriptPromise NFC::cancelWatch(ScriptState* scriptState) { |
| 710 ScriptPromise promise = rejectIfNotSupported(scriptState); | 710 ScriptPromise promise = rejectIfNotSupported(scriptState); |
| 711 if (!promise.isEmpty()) | 711 if (!promise.isEmpty()) |
| 712 return promise; | 712 return promise; |
| 713 | 713 |
| 714 m_callbacks.clear(); | 714 m_callbacks.clear(); |
| 715 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 715 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 716 m_requests.add(resolver); | 716 m_requests.insert(resolver); |
| 717 m_nfc->CancelAllWatches(convertToBaseCallback( | 717 m_nfc->CancelAllWatches(convertToBaseCallback( |
| 718 WTF::bind(&NFC::OnRequestCompleted, wrapPersistent(this), | 718 WTF::bind(&NFC::OnRequestCompleted, wrapPersistent(this), |
| 719 wrapPersistent(resolver)))); | 719 wrapPersistent(resolver)))); |
| 720 return resolver->promise(); | 720 return resolver->promise(); |
| 721 } | 721 } |
| 722 | 722 |
| 723 void NFC::pageVisibilityChanged() { | 723 void NFC::pageVisibilityChanged() { |
| 724 // If service is not initialized, there cannot be any pending NFC activities | 724 // If service is not initialized, there cannot be any pending NFC activities |
| 725 if (!m_nfc) | 725 if (!m_nfc) |
| 726 return; | 726 return; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 } | 818 } |
| 819 | 819 |
| 820 DEFINE_TRACE(NFC) { | 820 DEFINE_TRACE(NFC) { |
| 821 PageVisibilityObserver::trace(visitor); | 821 PageVisibilityObserver::trace(visitor); |
| 822 ContextLifecycleObserver::trace(visitor); | 822 ContextLifecycleObserver::trace(visitor); |
| 823 visitor->trace(m_requests); | 823 visitor->trace(m_requests); |
| 824 visitor->trace(m_callbacks); | 824 visitor->trace(m_callbacks); |
| 825 } | 825 } |
| 826 | 826 |
| 827 } // namespace blink | 827 } // namespace blink |
| OLD | NEW |