Commit 8debd334 authored by Matt Reynolds's avatar Matt Reynolds Committed by Commit Bot

Add skeleton for WebHID API feature

This CL adds initial IDL for the navigator.hid object which is
enabled under the experimental web platform features flag.
(chrome://flags/#enable-experimental-web-platform-features)

A FeaturePolicyFeature is also added to control access to HID
within the renderer.

BUG=890096

Change-Id: If75aefdd7dcaaad06ae56cff8d898d0bea0f83a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1441992
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638434}
parent 354a8059
...@@ -371,6 +371,9 @@ const FeaturePolicy::FeatureList& FeaturePolicy::GetDefaultFeatureList() { ...@@ -371,6 +371,9 @@ const FeaturePolicy::FeatureList& FeaturePolicy::GetDefaultFeatureList() {
{mojom::FeaturePolicyFeature::kGyroscope, {mojom::FeaturePolicyFeature::kGyroscope,
FeatureDefaultValue(FeaturePolicy::FeatureDefault::EnableForSelf, FeatureDefaultValue(FeaturePolicy::FeatureDefault::EnableForSelf,
mojom::PolicyValueType::kBool)}, mojom::PolicyValueType::kBool)},
{mojom::FeaturePolicyFeature::kHid,
FeatureDefaultValue(FeaturePolicy::FeatureDefault::EnableForSelf,
mojom::PolicyValueType::kBool)},
{mojom::FeaturePolicyFeature::kUnoptimizedImages, {mojom::FeaturePolicyFeature::kUnoptimizedImages,
FeatureDefaultValue(FeaturePolicy::FeatureDefault::EnableForAll, FeatureDefaultValue(FeaturePolicy::FeatureDefault::EnableForAll,
mojom::PolicyValueType::kBool)}, mojom::PolicyValueType::kBool)},
......
...@@ -120,6 +120,8 @@ enum FeaturePolicyFeature { ...@@ -120,6 +120,8 @@ enum FeaturePolicyFeature {
kFrobulate = 41, kFrobulate = 41,
// Controls access to Serial // Controls access to Serial
kSerial = 42, kSerial = 42,
// Controls access to WebHID.
kHid = 43,
// Don't change assigned numbers of any item, and don't reuse removed slots. // Don't change assigned numbers of any item, and don't reuse removed slots.
// Also, run update_feature_policy_enum.py in // Also, run update_feature_policy_enum.py in
......
...@@ -354,6 +354,9 @@ const FeatureNameMap& GetDefaultFeatureNameMap() { ...@@ -354,6 +354,9 @@ const FeatureNameMap& GetDefaultFeatureNameMap() {
default_feature_name_map.Set("top-navigation", default_feature_name_map.Set("top-navigation",
mojom::FeaturePolicyFeature::kTopNavigation); mojom::FeaturePolicyFeature::kTopNavigation);
} }
if (RuntimeEnabledFeatures::WebHIDEnabled()) {
default_feature_name_map.Set("hid", mojom::FeaturePolicyFeature::kHid);
}
if (RuntimeEnabledFeatures::PaymentRequestEnabled()) { if (RuntimeEnabledFeatures::PaymentRequestEnabled()) {
default_feature_name_map.Set("payment", default_feature_name_map.Set("payment",
mojom::FeaturePolicyFeature::kPayment); mojom::FeaturePolicyFeature::kPayment);
......
...@@ -110,6 +110,7 @@ target("jumbo_" + modules_target_type, "modules") { ...@@ -110,6 +110,7 @@ target("jumbo_" + modules_target_type, "modules") {
"//third_party/blink/renderer/modules/filesystem", "//third_party/blink/renderer/modules/filesystem",
"//third_party/blink/renderer/modules/gamepad", "//third_party/blink/renderer/modules/gamepad",
"//third_party/blink/renderer/modules/geolocation", "//third_party/blink/renderer/modules/geolocation",
"//third_party/blink/renderer/modules/hid",
"//third_party/blink/renderer/modules/idle", "//third_party/blink/renderer/modules/idle",
"//third_party/blink/renderer/modules/imagecapture", "//third_party/blink/renderer/modules/imagecapture",
"//third_party/blink/renderer/modules/indexeddb", "//third_party/blink/renderer/modules/indexeddb",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"CookieStore", "CookieStore",
"MediaKeySession", "MediaKeySession",
"FileWriter", "FileWriter",
"HID",
"IdleStatus", "IdleStatus",
"ImageCapture", "ImageCapture",
"IDBDatabase", "IDBDatabase",
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("hid") {
sources = [
"hid.cc",
"hid.h",
"navigator_hid.cc",
"navigator_hid.h",
]
}
include_rules = [
"+mojo/public/cpp/bindings",
]
mattreynolds@chromium.org
reillyg@chromium.org
# TEAM: device-dev@chromium.org
# COMPONENT: Blink>HID
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/hid/hid.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy.mojom-blink.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
namespace blink {
HID::HID(ExecutionContext& context) : ContextLifecycleObserver(&context) {}
HID::~HID() = default;
ExecutionContext* HID::GetExecutionContext() const {
return ContextLifecycleObserver::GetExecutionContext();
}
const AtomicString& HID::InterfaceName() const {
return event_target_names::kHID;
}
FeatureEnabledState HID::GetFeatureEnabledState() const {
return GetExecutionContext()->GetSecurityContext().GetFeatureEnabledState(
mojom::FeaturePolicyFeature::kHid);
}
void HID::Trace(blink::Visitor* visitor) {
EventTargetWithInlineData::Trace(visitor);
ContextLifecycleObserver::Trace(visitor);
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_HID_HID_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_HID_HID_H_
#include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/execution_context/security_context.h"
namespace blink {
class HID : public EventTargetWithInlineData, public ContextLifecycleObserver {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(HID);
public:
explicit HID(ExecutionContext&);
~HID() override;
// EventTarget overrides.
ExecutionContext* GetExecutionContext() const override;
const AtomicString& InterfaceName() const override;
void Trace(blink::Visitor*) override;
private:
FeatureEnabledState GetFeatureEnabledState() const;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_HID_HID_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Functionality for enumerating and connecting to devices within the HID
// subsystem.
// https://github.com/nondebug/webhid
[
Exposed(Window WebHID),
SecureContext
] interface HID : EventTarget {};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/hid/navigator_hid.h"
#include "third_party/blink/renderer/core/dom/document.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/modules/hid/hid.h"
namespace blink {
NavigatorHID& NavigatorHID::From(Navigator& navigator) {
NavigatorHID* supplement =
Supplement<Navigator>::From<NavigatorHID>(navigator);
if (!supplement) {
supplement = MakeGarbageCollected<NavigatorHID>(navigator);
ProvideTo(navigator, supplement);
}
return *supplement;
}
HID* NavigatorHID::hid(Navigator& navigator) {
return NavigatorHID::From(navigator).hid();
}
HID* NavigatorHID::hid() {
return hid_;
}
void NavigatorHID::Trace(blink::Visitor* visitor) {
visitor->Trace(hid_);
Supplement<Navigator>::Trace(visitor);
}
NavigatorHID::NavigatorHID(Navigator& navigator) {
if (navigator.GetFrame()) {
DCHECK(navigator.GetFrame()->GetDocument());
hid_ = MakeGarbageCollected<HID>(*navigator.GetFrame()->GetDocument());
}
}
const char NavigatorHID::kSupplementName[] = "NavigatorHID";
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_HID_NAVIGATOR_HID_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_HID_NAVIGATOR_HID_H_
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class Navigator;
class HID;
class NavigatorHID final : public GarbageCollected<NavigatorHID>,
public Supplement<Navigator> {
USING_GARBAGE_COLLECTED_MIXIN(NavigatorHID);
public:
static const char kSupplementName[];
// Gets, or creates, NavigatorHID supplement on Navigator.
// See platform/Supplementable.h
static NavigatorHID& From(Navigator&);
static HID* hid(Navigator&);
HID* hid();
void Trace(blink::Visitor*) override;
explicit NavigatorHID(Navigator&);
private:
Member<HID> hid_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_HID_NAVIGATOR_HID_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Partial Navigator interface for functionality related to HID subsystem
// devices.
// https://github.com/nondebug/webhid
[
ImplementedAs=NavigatorHID,
RuntimeEnabled=WebHID,
SecureContext
] partial interface Navigator {
[SameObject] readonly attribute HID hid;
};
...@@ -166,6 +166,7 @@ modules_idl_files = ...@@ -166,6 +166,7 @@ modules_idl_files =
"geolocation/geolocation.idl", "geolocation/geolocation.idl",
"geolocation/position.idl", "geolocation/position.idl",
"geolocation/position_error.idl", "geolocation/position_error.idl",
"hid/hid.idl",
"idle/idle_manager.idl", "idle/idle_manager.idl",
"idle/idle_state.idl", "idle/idle_state.idl",
"idle/idle_status.idl", "idle/idle_status.idl",
...@@ -793,6 +794,7 @@ modules_dependency_idl_files = ...@@ -793,6 +794,7 @@ modules_dependency_idl_files =
"filesystem/window_file_system.idl", "filesystem/window_file_system.idl",
"gamepad/navigator_gamepad.idl", "gamepad/navigator_gamepad.idl",
"geolocation/navigator_geolocation.idl", "geolocation/navigator_geolocation.idl",
"hid/navigator_hid.idl",
"idle/navigator_idle.idl", "idle/navigator_idle.idl",
"idle/worker_navigator_idle.idl", "idle/worker_navigator_idle.idl",
"indexeddb/window_indexed_database.idl", "indexeddb/window_indexed_database.idl",
......
...@@ -1488,6 +1488,10 @@ ...@@ -1488,6 +1488,10 @@
name: "WebGPU", name: "WebGPU",
status: "test", status: "test",
}, },
{
name: "WebHID",
status: "experimental",
},
{ {
name: "WebNFC", name: "WebNFC",
status: "experimental", status: "experimental",
......
...@@ -12,6 +12,7 @@ font-display-late-swap ...@@ -12,6 +12,7 @@ font-display-late-swap
fullscreen fullscreen
geolocation geolocation
gyroscope gyroscope
hid
layout-animations layout-animations
lazyload lazyload
legacy-image-formats legacy-image-formats
......
...@@ -2356,6 +2356,9 @@ interface Gyroscope : Sensor ...@@ -2356,6 +2356,9 @@ interface Gyroscope : Sensor
getter y getter y
getter z getter z
method constructor method constructor
interface HID : EventTarget
attribute @@toStringTag
method constructor
interface HTMLAllCollection interface HTMLAllCollection
attribute @@toStringTag attribute @@toStringTag
getter length getter length
...@@ -4823,6 +4826,7 @@ interface Navigator ...@@ -4823,6 +4826,7 @@ interface Navigator
getter doNotTrack getter doNotTrack
getter geolocation getter geolocation
getter hardwareConcurrency getter hardwareConcurrency
getter hid
getter idle getter idle
getter keyboard getter keyboard
getter language getter language
......
...@@ -21835,6 +21835,7 @@ Called by update_net_error_codes.py.--> ...@@ -21835,6 +21835,7 @@ Called by update_net_error_codes.py.-->
<int value="40" label="Presentation"/> <int value="40" label="Presentation"/>
<int value="41" label="Frobulate"/> <int value="41" label="Frobulate"/>
<int value="42" label="Serial"/> <int value="42" label="Serial"/>
<int value="43" label="Hid"/>
</enum> </enum>
<enum name="FeedbackSource"> <enum name="FeedbackSource">
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