Commit 2f10d737 authored by James Hollyer's avatar James Hollyer Committed by Commit Bot

Warn Developers of the upcoming Gamepad Restrictions

GetGamepad will soon require Secure Context and Permission Policy. This
CL adds a warning to developers to update applications accordingly.

Bug: 1099544
Change-Id: I548f31104aa1e5d9fd2984c49556a49c7098ca98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2382217
Commit-Queue: James Hollyer <jameshollyer@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803301}
parent fd636bb0
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "third_party/blink/renderer/core/dom/events/event.h" #include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/navigator.h" #include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/loader/document_loader.h" #include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trials.h" #include "third_party/blink/renderer/core/origin_trials/origin_trials.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
...@@ -87,17 +88,39 @@ GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator, ...@@ -87,17 +88,39 @@ GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator,
auto* navigator_gamepad = &NavigatorGamepad::From(navigator); auto* navigator_gamepad = &NavigatorGamepad::From(navigator);
if (base::FeatureList::IsEnabled(features::kRestrictGamepadAccess)) { ExecutionContext* context = navigator_gamepad->GetExecutionContext();
ExecutionContext* context = navigator_gamepad->GetExecutionContext(); if (!context || !context->IsSecureContext()) {
if (!context || !context->IsSecureContext()) { if (base::FeatureList::IsEnabled(features::kRestrictGamepadAccess)) {
exception_state.ThrowSecurityError(kSecureContextBlocked); exception_state.ThrowSecurityError(kSecureContextBlocked);
return nullptr; return nullptr;
} else {
context->AddConsoleMessage(
MakeGarbageCollected<ConsoleMessage>(
mojom::blink::ConsoleMessageSource::kJavaScript,
mojom::blink::ConsoleMessageLevel::kWarning,
"getGamepad will now require Secure Context. "
"Please update your application accordingly. "
"For more information see "
"https://github.com/w3c/gamepad/pull/120"),
/*discard_duplicates=*/true);
} }
}
if (!context->IsFeatureEnabled( if (!context->IsFeatureEnabled(
mojom::blink::FeaturePolicyFeature::kGamepad)) { mojom::blink::FeaturePolicyFeature::kGamepad)) {
if (base::FeatureList::IsEnabled(features::kRestrictGamepadAccess)) {
exception_state.ThrowSecurityError(kFeaturePolicyBlocked); exception_state.ThrowSecurityError(kFeaturePolicyBlocked);
return nullptr; return nullptr;
} else {
context->AddConsoleMessage(
MakeGarbageCollected<ConsoleMessage>(
mojom::blink::ConsoleMessageSource::kJavaScript,
mojom::blink::ConsoleMessageLevel::kWarning,
"getGamepad will now require a Permission Policy. "
"Please update your application accordingly. "
"For more information see "
"https://github.com/w3c/gamepad/pull/112"),
/*discard_duplicates=*/true);
} }
} }
......
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