Commit eab92780 authored by Jinho Bang's avatar Jinho Bang Committed by Commit Bot

WebNFC: Use [SecureContext] instead of manual check

Until now, we had to use IsSecureContext() to check whether an execution
context is a secure context manually. But we can use [SecureContext]
instead of the manual check now.

Related spec change:
  https://github.com/w3c/web-nfc/pull/143
  https://github.com/w3c/web-nfc/pull/144

Bug: none
Change-Id: I1396470cc57aeba137ddba65d1f29eb58cf9cf9b
Reviewed-on: https://chromium-review.googlesource.com/989537Reviewed-by: default avatarAlexander Shalamov <alexander.shalamov@intel.com>
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Cr-Commit-Position: refs/heads/master@{#548744}
parent 957a4220
......@@ -6,34 +6,19 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/nfc_help.js"></script>
<h2>Note</h2>
<ol>
<li>
Run test is an insecure context, e.g. http://example.com/
</li>
</ol>
<div id="log"></div>
<script>
"use strict";
promise_test(t => {
return promise_rejects(t, 'SecurityError', navigator.nfc.push(test_text_data));
}, "nfc.push should fail with SecurityError in an insecure context.");
promise_test(t => {
return promise_rejects(t, 'SecurityError', navigator.nfc.cancelPush());
}, "nfc.cancelPush should fail with SecurityError in an insecure context.");
promise_test(t => {
return promise_rejects(t, 'SecurityError', navigator.nfc.watch(noop));
}, "nfc.watch should fail with SecurityError in an insecure context.");
promise_test(t => {
return promise_rejects(t, 'SecurityError', navigator.nfc.cancelWatch());
}, "nfc.cancelWatch should fail with SecurityError in an insecure context.");
test(t => {
assert_false(isSecureContext);
assert_false('nfc' in navigator);
}, 'navigator.nfc requires a secure context');
</script>
......@@ -866,10 +866,6 @@ void NFC::OnWatch(const Vector<uint32_t>& ids,
bool NFC::IsSupportedInContext(ExecutionContext* context,
String& error_message) {
if (!context->IsSecureContext(error_message)) {
return false;
}
// https://w3c.github.io/web-nfc/#security-policies
// WebNFC API must be only accessible from top level browsing context.
if (!ToDocument(context)->domWindow()->GetFrame() ||
......
......@@ -7,7 +7,8 @@
typedef (DOMString or ArrayBuffer or NFCMessage) NFCPushMessage;
[
RuntimeEnabled=WebNFC
RuntimeEnabled=WebNFC,
SecureContext
] interface NFC {
[CallWith=ScriptState, MeasureAs=WebNFCPush] Promise<void> push (NFCPushMessage message, optional NFCPushOptions options);
[CallWith=ScriptState, MeasureAs=WebNFCCancelPush] Promise<void> cancelPush (optional NFCPushTarget target = "any");
......
......@@ -8,5 +8,5 @@
ImplementedAs=NavigatorNFC,
RuntimeEnabled=WebNFC
] partial interface Navigator {
readonly attribute NFC nfc;
[SecureContext, SameObject] readonly attribute NFC nfc;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment