chromium/third_party/blink/renderer/modules/bluetooth/bluetooth.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#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 {

// Per the Bluetooth Spec: The name is a user-friendly name associated with the
// device and consists of a maximum of 248 bytes coded according to the UTF-8
// standard.
const size_t kMaxDeviceNameLength =;
const char kDeviceNameTooLong[] =;
const char kInactiveDocumentError[] =;
const char kHandleGestureForPermissionRequest[] =;
const char kFencedFrameError[] =;
const char kPermissionsPolicyBlocked[] =;

// Does basic checks that are common to all IDL calls, mainly that the window is
// valid, and the request is not being done from a fenced frame tree. Returns
// true if exceptions have been flagged, and false otherwise.
bool IsRequestDenied(LocalDOMWindow* window, ExceptionState& exception_state) {}

// Checks whether the document is allowed by Permissions Policy to call Web
// Bluetooth API methods.
bool IsFeatureEnabled(LocalDOMWindow* window) {}

// Remind developers when they are using Web Bluetooth on unsupported platforms.
// TODO(https://crbug.com/570344): Remove this method when all platforms are
// supported.
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) {}

}  // namespace

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) {}

// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
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) {}

// https://webbluetoothcg.github.io/web-bluetooth/scanning.html#dom-bluetooth-requestlescan
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 {}

// static
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) {}

}  // namespace blink