weblayer_bluetooth_delegate_impl_client.cc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "weblayer/browser/bluetooth/weblayer_bluetooth_delegate_impl_client.h"
  5. #include "build/build_config.h"
  6. #include "content/public/browser/render_frame_host.h"
  7. #include "weblayer/browser/bluetooth/weblayer_bluetooth_chooser_context_factory.h"
  8. #if BUILDFLAG(IS_ANDROID)
  9. #include "components/permissions/android/bluetooth_chooser_android.h"
  10. #include "components/permissions/android/bluetooth_scanning_prompt_android.h"
  11. #include "weblayer/browser/bluetooth/weblayer_bluetooth_chooser_android_delegate.h"
  12. #include "weblayer/browser/bluetooth/weblayer_bluetooth_scanning_prompt_android_delegate.h"
  13. #endif // BUILDFLAG(IS_ANDROID)
  14. namespace weblayer {
  15. WebLayerBluetoothDelegateImplClient::WebLayerBluetoothDelegateImplClient() =
  16. default;
  17. WebLayerBluetoothDelegateImplClient::~WebLayerBluetoothDelegateImplClient() =
  18. default;
  19. permissions::BluetoothChooserContext*
  20. WebLayerBluetoothDelegateImplClient::GetBluetoothChooserContext(
  21. content::RenderFrameHost* frame) {
  22. return WebLayerBluetoothChooserContextFactory::GetForBrowserContext(
  23. frame->GetBrowserContext());
  24. }
  25. std::unique_ptr<content::BluetoothChooser>
  26. WebLayerBluetoothDelegateImplClient::RunBluetoothChooser(
  27. content::RenderFrameHost* frame,
  28. const content::BluetoothChooser::EventHandler& event_handler) {
  29. #if BUILDFLAG(IS_ANDROID)
  30. // TODO(https://crbug.com/1231932): Return nullptr if suppressed in vr.
  31. return std::make_unique<permissions::BluetoothChooserAndroid>(
  32. frame, event_handler,
  33. std::make_unique<WebLayerBluetoothChooserAndroidDelegate>());
  34. #else
  35. // Web Bluetooth is not supported for desktop in WebLayer.
  36. return nullptr;
  37. #endif
  38. }
  39. std::unique_ptr<content::BluetoothScanningPrompt>
  40. WebLayerBluetoothDelegateImplClient::ShowBluetoothScanningPrompt(
  41. content::RenderFrameHost* frame,
  42. const content::BluetoothScanningPrompt::EventHandler& event_handler) {
  43. #if BUILDFLAG(IS_ANDROID)
  44. return std::make_unique<permissions::BluetoothScanningPromptAndroid>(
  45. frame, event_handler,
  46. std::make_unique<WebLayerBluetoothScanningPromptAndroidDelegate>());
  47. #else
  48. // Web Bluetooth is not supported for desktop in WebLayer.
  49. return nullptr;
  50. #endif
  51. }
  52. void WebLayerBluetoothDelegateImplClient::ShowBluetoothDevicePairDialog(
  53. content::RenderFrameHost* frame,
  54. const std::u16string& device_identifier,
  55. content::BluetoothDelegate::PairPromptCallback callback,
  56. content::BluetoothDelegate::PairingKind,
  57. const absl::optional<std::u16string>& pin) {
  58. // Web Bluetooth is not supported for desktop in WebLayer and Android already
  59. // bonds on demand, so this should not be called on any platform.
  60. std::move(callback).Run(content::BluetoothDelegate::PairPromptResult(
  61. content::BluetoothDelegate::PairPromptStatus::kCancelled));
  62. NOTREACHED();
  63. }
  64. } // namespace weblayer