| 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 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 DCHECK(scriptState); | 773 DCHECK(scriptState); |
| 774 ScriptState::Scope scope(scriptState); | 774 ScriptState::Scope scope(scriptState); |
| 775 NFCMessage nfcMessage = toNFCMessage(scriptState, message); | 775 NFCMessage nfcMessage = toNFCMessage(scriptState, message); |
| 776 callback->handleMessage(nfcMessage); | 776 callback->handleMessage(nfcMessage); |
| 777 } | 777 } |
| 778 } | 778 } |
| 779 } | 779 } |
| 780 | 780 |
| 781 ScriptPromise NFC::rejectIfNotSupported(ScriptState* scriptState) { | 781 ScriptPromise NFC::rejectIfNotSupported(ScriptState* scriptState) { |
| 782 String errorMessage; | 782 String errorMessage; |
| 783 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { | 783 ExecutionContext* context = scriptState->getExecutionContext(); |
| 784 if (!context->isSecureContext(errorMessage)) { |
| 784 return ScriptPromise::rejectWithDOMException( | 785 return ScriptPromise::rejectWithDOMException( |
| 785 scriptState, DOMException::create(SecurityError, errorMessage)); | 786 scriptState, DOMException::create(SecurityError, errorMessage)); |
| 786 } | 787 } |
| 787 | 788 |
| 789 // https://w3c.github.io/web-nfc/#security-policies |
| 790 // WebNFC API must be only accessible from top level browsing context. |
| 791 if (!toDocument(context)->domWindow()->frame() || |
| 792 !toDocument(context)->frame()->isMainFrame()) { |
| 793 return ScriptPromise::rejectWithDOMException( |
| 794 scriptState, |
| 795 DOMException::create(SecurityError, |
| 796 "Must be in a top-level browsing context.")); |
| 797 } |
| 798 |
| 788 if (!m_nfc) { | 799 if (!m_nfc) { |
| 789 return ScriptPromise::rejectWithDOMException( | 800 return ScriptPromise::rejectWithDOMException( |
| 790 scriptState, DOMException::create(NotSupportedError)); | 801 scriptState, DOMException::create(NotSupportedError)); |
| 791 } | 802 } |
| 792 | 803 |
| 793 return ScriptPromise(); | 804 return ScriptPromise(); |
| 794 } | 805 } |
| 795 | 806 |
| 796 void NFC::OnWatchRegistered(MessageCallback* callback, | 807 void NFC::OnWatchRegistered(MessageCallback* callback, |
| 797 ScriptPromiseResolver* resolver, | 808 ScriptPromiseResolver* resolver, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 818 } | 829 } |
| 819 | 830 |
| 820 DEFINE_TRACE(NFC) { | 831 DEFINE_TRACE(NFC) { |
| 821 PageVisibilityObserver::trace(visitor); | 832 PageVisibilityObserver::trace(visitor); |
| 822 ContextLifecycleObserver::trace(visitor); | 833 ContextLifecycleObserver::trace(visitor); |
| 823 visitor->trace(m_requests); | 834 visitor->trace(m_requests); |
| 824 visitor->trace(m_callbacks); | 835 visitor->trace(m_callbacks); |
| 825 } | 836 } |
| 826 | 837 |
| 827 } // namespace blink | 838 } // namespace blink |
| OLD | NEW |