Commit c12c50e9 authored by Ian Clelland's avatar Ian Clelland Committed by Commit Bot

Enable FP reporting for VR/XR policy violations.

This queues a report through the Reporting API whenever VR or XR device
access are requested in a frame in which the 'vr' feature is not allowed
according to feature policy.

Bug: 867471
Cq-Include-Trybots: luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I5e0256c799f986e30b1f3746ef0fce1b6d9f93eb
Reviewed-on: https://chromium-review.googlesource.com/1195438Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590451}
parent 7d9d5aee
<!DOCTYPE html>
<html>
<head>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
</head>
<body>
<script>
var check_report_format = (reports, observer) => {
let report = reports[0];
assert_equals(report.type, "feature-policy");
assert_equals(report.url, document.location.href);
assert_equals(report.body.feature, "vr");
assert_equals(report.body.sourceFile, document.location.href);
assert_equals(typeof report.body.message, "string");
assert_equals(typeof report.body.lineNumber, "number");
assert_equals(typeof report.body.columnNumber, "number");
};
promise_test(async (t) => {
const report = new Promise(resolve => {
new ReportingObserver((reports, observer) => resolve([reports, observer]),
{types: ['feature-policy']}).observe();
});
await promise_rejects(t, 'SecurityError', navigator.getVRDisplays(),
"VR device access should not be allowed in this document.");
const [reports, observer] = await report;
check_report_format(reports, observer);
}, "VR Report Format");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
</head>
<body>
<script>
var check_report_format = (reports, observer) => {
let report = reports[0];
assert_equals(report.type, "feature-policy");
assert_equals(report.url, document.location.href);
assert_equals(report.body.feature, "vr");
assert_equals(report.body.sourceFile, document.location.href);
assert_equals(typeof report.body.message, "string");
assert_equals(typeof report.body.lineNumber, "number");
assert_equals(typeof report.body.columnNumber, "number");
};
promise_test(async (t) => {
const report = new Promise(resolve => {
new ReportingObserver((reports, observer) => resolve([reports, observer]),
{types: ['feature-policy']}).observe();
});
await promise_rejects(t, 'SecurityError', navigator.xr.requestDevice(),
"XR device access should not be allowed in this document.");
const [reports, observer] = await report;
check_report_format(reports, observer);
}, "XR Report Format");
</script>
</body>
</html>
...@@ -144,7 +144,8 @@ ScriptPromise NavigatorVR::getVRDisplays(ScriptState* script_state) { ...@@ -144,7 +144,8 @@ ScriptPromise NavigatorVR::getVRDisplays(ScriptState* script_state) {
script_state, DOMException::Create(DOMExceptionCode::kInvalidStateError, script_state, DOMException::Create(DOMExceptionCode::kInvalidStateError,
kNotAssociatedWithDocumentMessage)); kNotAssociatedWithDocumentMessage));
} }
if (!frame->IsFeatureEnabled(mojom::FeaturePolicyFeature::kWebVr)) { if (!frame->IsFeatureEnabled(mojom::FeaturePolicyFeature::kWebVr,
ReportOptions::kReportOnFailure)) {
return ScriptPromise::RejectWithDOMException( return ScriptPromise::RejectWithDOMException(
script_state, DOMException::Create(DOMExceptionCode::kSecurityError, script_state, DOMException::Create(DOMExceptionCode::kSecurityError,
kFeaturePolicyBlockedMessage)); kFeaturePolicyBlockedMessage));
......
...@@ -73,7 +73,8 @@ ScriptPromise XR::requestDevice(ScriptState* script_state) { ...@@ -73,7 +73,8 @@ ScriptPromise XR::requestDevice(ScriptState* script_state) {
did_log_requestDevice_ = true; did_log_requestDevice_ = true;
} }
if (!frame->IsFeatureEnabled(mojom::FeaturePolicyFeature::kWebVr)) { if (!frame->IsFeatureEnabled(mojom::FeaturePolicyFeature::kWebVr,
ReportOptions::kReportOnFailure)) {
// Only allow the call to be made if the appropraite feature policy is in // Only allow the call to be made if the appropraite feature policy is in
// place. // place.
return ScriptPromise::RejectWithDOMException( return ScriptPromise::RejectWithDOMException(
......
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