#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/modules/bluetooth/bluetooth.h"
#include <utility>
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "mojo/public/cpp/bindings/associated_receiver_set.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom-blink.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.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/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_string_unsignedlong.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_bluetooth_advertising_event_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_bluetooth_data_filter_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_bluetooth_le_scan_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_bluetooth_manufacturer_data_filter_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_request_device_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_typedefs.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/execution_context/security_context.h"
#include "third_party/blink/renderer/core/frame/frame.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.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/web_feature.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/modules/bluetooth/bluetooth_device.h"
#include "third_party/blink/renderer/modules/bluetooth/bluetooth_error.h"
#include "third_party/blink/renderer/modules/bluetooth/bluetooth_le_scan.h"
#include "third_party/blink/renderer/modules/bluetooth/bluetooth_manufacturer_data_map.h"
#include "third_party/blink/renderer/modules/bluetooth/bluetooth_remote_gatt_characteristic.h"
#include "third_party/blink/renderer/modules/bluetooth/bluetooth_service_data_map.h"
#include "third_party/blink/renderer/modules/bluetooth/bluetooth_uuid.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/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
namespace blink {
namespace {
const size_t kMaxDeviceNameLength = …;
const char kDeviceNameTooLong[] = …;
const char kInactiveDocumentError[] = …;
const char kHandleGestureForPermissionRequest[] = …;
const char kFencedFrameError[] = …;
const char kPermissionsPolicyBlocked[] = …;
bool IsRequestDenied(LocalDOMWindow* window, ExceptionState& exception_state) { … }
bool IsFeatureEnabled(LocalDOMWindow* window) { … }
void AddUnsupportedPlatformConsoleMessage(ExecutionContext* context) { … }
void CanonicalizeFilter(
const BluetoothLEScanFilterInit* filter,
mojom::blink::WebBluetoothLeScanFilterPtr& canonicalized_filter,
ExceptionState& exception_state) { … }
void ConvertRequestDeviceOptions(
const RequestDeviceOptions* options,
mojom::blink::WebBluetoothRequestDeviceOptionsPtr& result,
ExecutionContext* execution_context,
ExceptionState& exception_state) { … }
}
ScriptPromise<IDLBoolean> Bluetooth::getAvailability(
ScriptState* script_state,
ExceptionState& exception_state) { … }
void Bluetooth::GetDevicesCallback(
ScriptPromiseResolver<IDLSequence<BluetoothDevice>>* resolver,
Vector<mojom::blink::WebBluetoothDevicePtr> devices) { … }
void Bluetooth::RequestDeviceCallback(
ScriptPromiseResolver<BluetoothDevice>* resolver,
mojom::blink::WebBluetoothResult result,
mojom::blink::WebBluetoothDevicePtr device) { … }
ScriptPromise<IDLSequence<BluetoothDevice>> Bluetooth::getDevices(
ScriptState* script_state,
ExceptionState& exception_state) { … }
ScriptPromise<BluetoothDevice> Bluetooth::requestDevice(
ScriptState* script_state,
const RequestDeviceOptions* options,
ExceptionState& exception_state) { … }
static void ConvertRequestLEScanOptions(
const BluetoothLEScanOptions* options,
mojom::blink::WebBluetoothRequestLEScanOptionsPtr& result,
ExceptionState& exception_state) { … }
void Bluetooth::RequestScanningCallback(
ScriptPromiseResolver<BluetoothLEScan>* resolver,
mojo::ReceiverId id,
mojom::blink::WebBluetoothRequestLEScanOptionsPtr options,
mojom::blink::WebBluetoothResult result) { … }
ScriptPromise<BluetoothLEScan> Bluetooth::requestLEScan(
ScriptState* script_state,
const BluetoothLEScanOptions* options,
ExceptionState& exception_state) { … }
void Bluetooth::AdvertisingEvent(
mojom::blink::WebBluetoothAdvertisingEventPtr advertising_event) { … }
void Bluetooth::PageVisibilityChanged() { … }
void Bluetooth::CancelScan(mojo::ReceiverId id) { … }
bool Bluetooth::IsScanActive(mojo::ReceiverId id) const { … }
const WTF::AtomicString& Bluetooth::InterfaceName() const { … }
ExecutionContext* Bluetooth::GetExecutionContext() const { … }
void Bluetooth::Trace(Visitor* visitor) const { … }
const char Bluetooth::kSupplementName[] = …;
Bluetooth* Bluetooth::bluetooth(Navigator& navigator) { … }
Bluetooth::Bluetooth(Navigator& navigator)
: … { … }
Bluetooth::~Bluetooth() = default;
BluetoothDevice* Bluetooth::GetBluetoothDeviceRepresentingDevice(
mojom::blink::WebBluetoothDevicePtr device_ptr,
ExecutionContext* context) { … }
void Bluetooth::EnsureServiceConnection(ExecutionContext* context) { … }
}