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" |
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/frame/LocalDOMWindow.h" | 15 #include "core/frame/LocalDOMWindow.h" |
15 #include "modules/nfc/NFCError.h" | 16 #include "modules/nfc/NFCError.h" |
16 #include "modules/nfc/NFCMessage.h" | 17 #include "modules/nfc/NFCMessage.h" |
17 #include "modules/nfc/NFCPushOptions.h" | 18 #include "modules/nfc/NFCPushOptions.h" |
18 #include "modules/nfc/NFCWatchOptions.h" | 19 #include "modules/nfc/NFCWatchOptions.h" |
19 #include "platform/mojo/MojoHelper.h" | 20 #include "platform/mojo/MojoHelper.h" |
20 #include "public/platform/InterfaceProvider.h" | 21 #include "public/platform/InterfaceProvider.h" |
21 #include "public/platform/Platform.h" | 22 #include "public/platform/Platform.h" |
22 | 23 |
23 namespace { | 24 namespace { |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 if (exception) | 618 if (exception) |
618 return ScriptPromise::RejectWithDOMException(script_state, exception); | 619 return ScriptPromise::RejectWithDOMException(script_state, exception); |
619 | 620 |
620 device::nfc::mojom::blink::NFCMessagePtr message = | 621 device::nfc::mojom::blink::NFCMessagePtr message = |
621 device::nfc::mojom::blink::NFCMessage::From(push_message); | 622 device::nfc::mojom::blink::NFCMessage::From(push_message); |
622 if (!message) | 623 if (!message) |
623 return ScriptPromise::RejectWithDOMException( | 624 return ScriptPromise::RejectWithDOMException( |
624 script_state, DOMException::Create(kSyntaxError)); | 625 script_state, DOMException::Create(kSyntaxError)); |
625 | 626 |
626 if (!SetURL( | 627 if (!SetURL( |
627 script_state->GetExecutionContext()->GetSecurityOrigin()->ToString(), | 628 ExecutionContext::From(script_state)->GetSecurityOrigin()->ToString(), |
628 message)) | 629 message)) |
629 return ScriptPromise::RejectWithDOMException( | 630 return ScriptPromise::RejectWithDOMException( |
630 script_state, DOMException::Create(kSyntaxError)); | 631 script_state, DOMException::Create(kSyntaxError)); |
631 | 632 |
632 if (GetNFCMessageSize(message) > | 633 if (GetNFCMessageSize(message) > |
633 device::nfc::mojom::blink::NFCMessage::kMaxSize) { | 634 device::nfc::mojom::blink::NFCMessage::kMaxSize) { |
634 return ScriptPromise::RejectWithDOMException( | 635 return ScriptPromise::RejectWithDOMException( |
635 script_state, DOMException::Create(kNotSupportedError)); | 636 script_state, DOMException::Create(kNotSupportedError)); |
636 } | 637 } |
637 | 638 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 DCHECK(script_state); | 769 DCHECK(script_state); |
769 ScriptState::Scope scope(script_state); | 770 ScriptState::Scope scope(script_state); |
770 NFCMessage nfc_message = ToNFCMessage(script_state, message); | 771 NFCMessage nfc_message = ToNFCMessage(script_state, message); |
771 callback->handleMessage(nfc_message); | 772 callback->handleMessage(nfc_message); |
772 } | 773 } |
773 } | 774 } |
774 } | 775 } |
775 | 776 |
776 ScriptPromise NFC::RejectIfNotSupported(ScriptState* script_state) { | 777 ScriptPromise NFC::RejectIfNotSupported(ScriptState* script_state) { |
777 String error_message; | 778 String error_message; |
778 ExecutionContext* context = script_state->GetExecutionContext(); | 779 ExecutionContext* context = ExecutionContext::From(script_state); |
779 if (!context->IsSecureContext(error_message)) { | 780 if (!context->IsSecureContext(error_message)) { |
780 return ScriptPromise::RejectWithDOMException( | 781 return ScriptPromise::RejectWithDOMException( |
781 script_state, DOMException::Create(kSecurityError, error_message)); | 782 script_state, DOMException::Create(kSecurityError, error_message)); |
782 } | 783 } |
783 | 784 |
784 // https://w3c.github.io/web-nfc/#security-policies | 785 // https://w3c.github.io/web-nfc/#security-policies |
785 // WebNFC API must be only accessible from top level browsing context. | 786 // WebNFC API must be only accessible from top level browsing context. |
786 if (!ToDocument(context)->domWindow()->GetFrame() || | 787 if (!ToDocument(context)->domWindow()->GetFrame() || |
787 !ToDocument(context)->GetFrame()->IsMainFrame()) { | 788 !ToDocument(context)->GetFrame()->IsMainFrame()) { |
788 return ScriptPromise::RejectWithDOMException( | 789 return ScriptPromise::RejectWithDOMException( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 } | 825 } |
825 | 826 |
826 DEFINE_TRACE(NFC) { | 827 DEFINE_TRACE(NFC) { |
827 PageVisibilityObserver::Trace(visitor); | 828 PageVisibilityObserver::Trace(visitor); |
828 ContextLifecycleObserver::Trace(visitor); | 829 ContextLifecycleObserver::Trace(visitor); |
829 visitor->Trace(requests_); | 830 visitor->Trace(requests_); |
830 visitor->Trace(callbacks_); | 831 visitor->Trace(callbacks_); |
831 } | 832 } |
832 | 833 |
833 } // namespace blink | 834 } // namespace blink |
OLD | NEW |