#include "third_party/blink/renderer/modules/hid/hid_device.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_hid_collection_info.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_hid_report_info.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_piece.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_data_view.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/hid/hid_input_report_event.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
namespace {
const char kDeviceStateChangeInProgress[] = …;
const char kDeviceIsForgotten[] = …;
const char kOpenRequired[] = …;
const char kOpenFailed[] = …;
const char kSendReportFailed[] = …;
const char kSendFeatureReportFailed[] = …;
const char kReceiveFeatureReportFailed[] = …;
const char kUnexpectedClose[] = …;
const char kArrayBufferTooBig[] = …;
const char kContextGone[] = …;
enum ReportType { … };
bool IsProtectedReportType(
const device::mojom::blink::HidUsageAndPage& hid_usage_and_page,
ReportType report_type) { … }
enum HidUnitSystem { … };
uint32_t ConvertHidUsageAndPageToUint32(
const device::mojom::blink::HidUsageAndPage& usage) { … }
String UnitSystemToString(uint8_t unit) { … }
int8_t UnitFactorExponentToInt(uint8_t unit_factor_exponent) { … }
void UnpackUnitValues(uint32_t unit,
String& unit_system,
int8_t& length_exponent,
int8_t& mass_exponent,
int8_t& time_exponent,
int8_t& temperature_exponent,
int8_t& current_exponent,
int8_t& luminous_intensity_exponent) { … }
HIDReportInfo* ToHIDReportInfo(
const device::mojom::blink::HidReportDescription& report_info) { … }
HIDCollectionInfo* ToHIDCollectionInfo(
const device::mojom::blink::HidCollectionInfo& collection) { … }
}
HIDDevice::HIDDevice(ServiceInterface* parent,
device::mojom::blink::HidDeviceInfoPtr info,
ExecutionContext* context)
: … { … }
HIDDevice::~HIDDevice() { … }
ExecutionContext* HIDDevice::GetExecutionContext() const { … }
const AtomicString& HIDDevice::InterfaceName() const { … }
void HIDDevice::OnInputReport(uint8_t report_id,
const Vector<uint8_t>& buffer) { … }
bool HIDDevice::opened() const { … }
uint16_t HIDDevice::vendorId() const { … }
uint16_t HIDDevice::productId() const { … }
String HIDDevice::productName() const { … }
const HeapVector<Member<HIDCollectionInfo>>& HIDDevice::collections() const { … }
ScriptPromise<IDLUndefined> HIDDevice::open(ScriptState* script_state,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> HIDDevice::close(ScriptState* script_state) { … }
ScriptPromise<IDLUndefined> HIDDevice::forget(ScriptState* script_state,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> HIDDevice::sendReport(ScriptState* script_state,
uint8_t report_id,
const DOMArrayPiece& data) { … }
ScriptPromise<IDLUndefined> HIDDevice::sendFeatureReport(
ScriptState* script_state,
uint8_t report_id,
const DOMArrayPiece& data) { … }
ScriptPromise<NotShared<DOMDataView>> HIDDevice::receiveFeatureReport(
ScriptState* script_state,
uint8_t report_id) { … }
void HIDDevice::ContextDestroyed() { … }
bool HIDDevice::HasPendingActivity() const { … }
void HIDDevice::UpdateDeviceInfo(device::mojom::blink::HidDeviceInfoPtr info) { … }
void HIDDevice::ResetIsForgotten() { … }
void HIDDevice::Trace(Visitor* visitor) const { … }
bool HIDDevice::EnsureNoDeviceChangeInProgress(
ScriptPromiseResolverBase* resolver) const { … }
bool HIDDevice::EnsureDeviceIsNotForgotten(
ScriptPromiseResolverBase* resolver) const { … }
void HIDDevice::FinishOpen(
ScriptPromiseResolver<IDLUndefined>* resolver,
mojo::PendingRemote<device::mojom::blink::HidConnection> connection) { … }
void HIDDevice::FinishForget(ScriptPromiseResolver<IDLUndefined>* resolver) { … }
void HIDDevice::OnServiceConnectionError() { … }
void HIDDevice::FinishSendReport(ScriptPromiseResolver<IDLUndefined>* resolver,
bool success) { … }
void HIDDevice::FinishSendFeatureReport(
ScriptPromiseResolver<IDLUndefined>* resolver,
bool success) { … }
void HIDDevice::FinishReceiveFeatureReport(
ScriptPromiseResolver<NotShared<DOMDataView>>* resolver,
bool success,
const std::optional<Vector<uint8_t>>& data) { … }
void HIDDevice::MarkRequestComplete(ScriptPromiseResolverBase* resolver) { … }
HIDReportItem* HIDDevice::ToHIDReportItem(
const device::mojom::blink::HidReportItem& report_item) { … }
}