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

Move Feature Policy checks from Frame to Document

This CL handles the features which are trivially migratable from
calling (Deprecated)IsFeatureEnabled on Frame to calling the equivalent
method on Document.

Bug: 888668
Cq-Include-Trybots: luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: If7c548afd9974f83c86cbcb9876cb51654bb3267
Reviewed-on: https://chromium-review.googlesource.com/1243365
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594103}
parent cfbc356c
......@@ -54,7 +54,7 @@ CSSInterpolationTypesMap::CSSInterpolationTypesMap(
const PropertyRegistry* registry,
const Document& document)
: registry_(registry) {
allow_all_animations_ = document.GetFrame()->DeprecatedIsFeatureEnabled(
allow_all_animations_ = document.IsFeatureEnabled(
blink::mojom::FeaturePolicyFeature::kAnimations);
}
......
......@@ -746,7 +746,7 @@ void Deprecation::CountDeprecationFeaturePolicy(
return;
// If the feature is allowed, don't log a warning.
if (frame->DeprecatedIsFeatureEnabled(feature))
if (document.IsFeatureEnabled(feature))
return;
// If the feature is disabled, log a warning but only if the request is from a
......
......@@ -93,12 +93,10 @@ bool DeviceSingleWindowEventController::IsSameSecurityOriginAsMainFrame()
bool DeviceSingleWindowEventController::CheckPolicyFeatures(
const Vector<mojom::FeaturePolicyFeature>& features) const {
LocalFrame* frame = GetDocument().GetFrame();
if (!frame)
return false;
const Document& document = GetDocument();
return std::all_of(features.begin(), features.end(),
[frame](mojom::FeaturePolicyFeature feature) {
return frame->DeprecatedIsFeatureEnabled(feature);
[&document](mojom::FeaturePolicyFeature feature) {
return document.IsFeatureEnabled(feature);
});
}
......
......@@ -746,9 +746,8 @@ bool XMLHttpRequest::InitSend(ExceptionState& exception_state) {
if (!async_) {
if (GetExecutionContext()->IsDocument() &&
!GetDocument()->GetFrame()->DeprecatedIsFeatureEnabled(
mojom::FeaturePolicyFeature::kSyncXHR,
ReportOptions::kReportOnFailure)) {
!GetDocument()->IsFeatureEnabled(mojom::FeaturePolicyFeature::kSyncXHR,
ReportOptions::kReportOnFailure)) {
LogConsoleError(GetExecutionContext(),
"Synchronous requests are disabled by Feature Policy.");
HandleNetworkError();
......
......@@ -302,8 +302,7 @@ ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess(
ExecutionContext* execution_context = ExecutionContext::From(script_state);
Document* document = ToDocument(execution_context);
if (!document->GetFrame() ||
!document->GetFrame()->DeprecatedIsFeatureEnabled(
if (!document->IsFeatureEnabled(
mojom::FeaturePolicyFeature::kEncryptedMedia)) {
UseCounter::Count(document,
WebFeature::kEncryptedMediaDisabledByFeaturePolicy);
......
......@@ -224,7 +224,7 @@ void Geolocation::StartRequest(GeoNotifier* notifier) {
return;
}
if (!GetFrame()->DeprecatedIsFeatureEnabled(
if (!GetDocument()->IsFeatureEnabled(
mojom::FeaturePolicyFeature::kGeolocation,
ReportOptions::kReportOnFailure)) {
UseCounter::Count(GetDocument(),
......
......@@ -492,17 +492,15 @@ bool UserMediaRequest::IsSecureContextUse(String& error_message) {
// Feature policy deprecation messages.
if (Audio()) {
if (!document->GetFrame()->DeprecatedIsFeatureEnabled(
mojom::FeaturePolicyFeature::kMicrophone,
ReportOptions::kReportOnFailure)) {
if (!document->IsFeatureEnabled(mojom::FeaturePolicyFeature::kMicrophone,
ReportOptions::kReportOnFailure)) {
UseCounter::Count(
document, WebFeature::kMicrophoneDisabledByFeaturePolicyEstimate);
}
}
if (Video()) {
if (!document->GetFrame()->DeprecatedIsFeatureEnabled(
mojom::FeaturePolicyFeature::kCamera,
ReportOptions::kReportOnFailure)) {
if (!document->IsFeatureEnabled(mojom::FeaturePolicyFeature::kCamera,
ReportOptions::kReportOnFailure)) {
UseCounter::Count(document,
WebFeature::kCameraDisabledByFeaturePolicyEstimate);
}
......
......@@ -54,7 +54,7 @@ PictureInPictureControllerImpl::IsDocumentAllowed() const {
// If document is not allowed to use the policy-controlled feature named
// "picture-in-picture", return kDisabledByFeaturePolicy status.
if (RuntimeEnabledFeatures::PictureInPictureAPIEnabled() &&
!frame->DeprecatedIsFeatureEnabled(
!GetSupplementable()->IsFeatureEnabled(
blink::mojom::FeaturePolicyFeature::kPictureInPicture)) {
return Status::kDisabledByFeaturePolicy;
}
......
......@@ -22,11 +22,11 @@ namespace blink {
namespace {
const double kWaitingIntervalThreshold = 0.01;
bool AreFeaturesEnabled(LocalFrame* frame,
bool AreFeaturesEnabled(Document* document,
const Vector<mojom::FeaturePolicyFeature>& features) {
return std::all_of(features.begin(), features.end(),
[frame](mojom::FeaturePolicyFeature feature) {
return frame->DeprecatedIsFeatureEnabled(feature);
[document](mojom::FeaturePolicyFeature feature) {
return document->IsFeatureEnabled(feature);
});
}
......@@ -45,9 +45,9 @@ Sensor::Sensor(ExecutionContext* execution_context,
// [SecureContext] in idl.
DCHECK(execution_context->IsSecureContext());
DCHECK(!features.IsEmpty());
LocalFrame* frame = ToDocument(execution_context)->GetFrame();
Document* document = ToDocument(execution_context);
if (!frame || !AreFeaturesEnabled(frame, features)) {
if (!AreFeaturesEnabled(document, features)) {
exception_state.ThrowSecurityError(
"Access to sensor features is disallowed by feature policy");
return;
......
......@@ -144,8 +144,8 @@ ScriptPromise NavigatorVR::getVRDisplays(ScriptState* script_state) {
script_state, DOMException::Create(DOMExceptionCode::kInvalidStateError,
kNotAssociatedWithDocumentMessage));
}
if (!frame->DeprecatedIsFeatureEnabled(mojom::FeaturePolicyFeature::kWebVr,
ReportOptions::kReportOnFailure)) {
if (!GetDocument()->IsFeatureEnabled(mojom::FeaturePolicyFeature::kWebVr,
ReportOptions::kReportOnFailure)) {
return ScriptPromise::RejectWithDOMException(
script_state, DOMException::Create(DOMExceptionCode::kSecurityError,
kFeaturePolicyBlockedMessage));
......
......@@ -102,9 +102,8 @@ ScriptPromise NavigatorWebMIDI::requestMIDIAccess(ScriptState* script_state,
UseCounter::CountCrossOriginIframe(
document, WebFeature::kRequestMIDIAccessIframe_ObscuredByFootprinting);
if (!document.GetFrame()->DeprecatedIsFeatureEnabled(
mojom::FeaturePolicyFeature::kMidiFeature,
ReportOptions::kReportOnFailure)) {
if (!document.IsFeatureEnabled(mojom::FeaturePolicyFeature::kMidiFeature,
ReportOptions::kReportOnFailure)) {
UseCounter::Count(document, WebFeature::kMidiDisabledByFeaturePolicy);
document.AddConsoleMessage(ConsoleMessage::Create(
kJSMessageSource, kWarningMessageLevel, kFeaturePolicyConsoleWarning));
......
......@@ -73,9 +73,10 @@ ScriptPromise XR::requestDevice(ScriptState* script_state) {
did_log_requestDevice_ = true;
}
if (!frame->DeprecatedIsFeatureEnabled(mojom::FeaturePolicyFeature::kWebVr,
ReportOptions::kReportOnFailure)) {
// Only allow the call to be made if the appropraite feature policy is in
if (!frame->GetDocument()->IsFeatureEnabled(
mojom::FeaturePolicyFeature::kWebVr,
ReportOptions::kReportOnFailure)) {
// Only allow the call to be made if the appropriate feature policy is in
// place.
return ScriptPromise::RejectWithDOMException(
script_state, DOMException::Create(DOMExceptionCode::kSecurityError,
......
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