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

Unified 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, 11 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/nfc/NFC.cpp
diff --git a/third_party/WebKit/Source/modules/nfc/NFC.cpp b/third_party/WebKit/Source/modules/nfc/NFC.cpp
index 7125180b26c85090bdb24a68f8c1174190e87e7b..f8e710fc419e012f2e5a4c59104909b64fb0ee2e 100644
--- a/third_party/WebKit/Source/modules/nfc/NFC.cpp
+++ b/third_party/WebKit/Source/modules/nfc/NFC.cpp
@@ -780,11 +780,22 @@ void NFC::OnWatch(const WTF::Vector<uint32_t>& ids,
ScriptPromise NFC::rejectIfNotSupported(ScriptState* scriptState) {
String errorMessage;
- if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) {
+ ExecutionContext* context = scriptState->getExecutionContext();
+ if (!context->isSecureContext(errorMessage)) {
return ScriptPromise::rejectWithDOMException(
scriptState, DOMException::create(SecurityError, errorMessage));
}
+ // https://w3c.github.io/web-nfc/#security-policies
+ // WebNFC API must be only accessible from top level browsing context.
+ if (!toDocument(context)->domWindow()->frame() ||
+ !toDocument(context)->frame()->isMainFrame()) {
+ return ScriptPromise::rejectWithDOMException(
+ scriptState,
+ DOMException::create(SecurityError,
+ "Must be in a top-level browsing context."));
+ }
+
if (!m_nfc) {
return ScriptPromise::rejectWithDOMException(
scriptState, DOMException::create(NotSupportedError));
« 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