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