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

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

Issue 2657023005: [webnfc] Allow access to WebNFC API only from main frame (Closed)
Patch Set: Created 3 years, 10 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/resources/push-from-iframe.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"
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/resources/push-from-iframe.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698