Commit 4f8cac3b authored by Jinho Bang's avatar Jinho Bang Committed by Commit Bot

WebBluetooth: 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.

Bug: none
Change-Id: Ibfcd4a9a2eed3e7ac67819b9bf4204f4c73412d8
Reviewed-on: https://chromium-review.googlesource.com/990014Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Cr-Commit-Position: refs/heads/master@{#548464}
parent baede72c
...@@ -7,11 +7,8 @@ ...@@ -7,11 +7,8 @@
if (window.location.origin != get_host_info().UNAUTHENTICATED_ORIGIN) { if (window.location.origin != get_host_info().UNAUTHENTICATED_ORIGIN) {
window.location = get_host_info().UNAUTHENTICATED_ORIGIN + window.location.pathname; window.location = get_host_info().UNAUTHENTICATED_ORIGIN + window.location.pathname;
} else { } else {
promise_test(function(test) { test(t => {
return promise_rejects(test, 'SecurityError', assert_false('requestDevice' in navigator.bluetooth, 'navigator.bluetooth.requestDevice should not be present');
navigator.bluetooth.requestDevice({ }, 'navigator.bluetooth.requestDevice requires a secure context');
filters: [{services: ['generic_access']}]
}));
}, "Requires secure context before user gesture");
} }
</script> </script>
...@@ -164,13 +164,7 @@ ScriptPromise Bluetooth::requestDevice(ScriptState* script_state, ...@@ -164,13 +164,7 @@ ScriptPromise Bluetooth::requestDevice(ScriptState* script_state,
"implementation-status.md")); "implementation-status.md"));
#endif #endif
// If the Relevant settings object is not a secure context, reject promise CHECK(context->IsSecureContext());
// with a SecurityError and abort these steps.
String error_message;
if (!context->IsSecureContext(error_message)) {
return ScriptPromise::RejectWithDOMException(
script_state, DOMException::Create(kSecurityError, error_message));
}
// If the algorithm is not allowed to show a popup, reject promise with a // If the algorithm is not allowed to show a popup, reject promise with a
// SecurityError and abort these steps. // SecurityError and abort these steps.
......
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
[ [
RuntimeEnabled=WebBluetooth RuntimeEnabled=WebBluetooth
] interface Bluetooth { ] interface Bluetooth {
[CallWith=ScriptState, RaisesException, MeasureAs=WebBluetoothRequestDevice] Promise<BluetoothDevice> requestDevice (optional RequestDeviceOptions options); [CallWith=ScriptState, RaisesException, MeasureAs=WebBluetoothRequestDevice, SecureContext] Promise<BluetoothDevice> requestDevice (optional RequestDeviceOptions options);
}; };
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