1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63

content / shell / browser / bluetooth / ios / shell_bluetooth_chooser_coordinator.mm [blame]

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

#import "content/shell/browser/bluetooth/ios/shell_bluetooth_chooser_coordinator.h"

#import "base/strings/sys_string_conversions.h"
#import "content/shell/browser/bluetooth/ios/shell_bluetooth_chooser_mediator.h"
#import "content/shell/browser/bluetooth/ios/shell_bluetooth_device_list_view_controller.h"
#import "ui/gfx/native_widget_types.h"

@implementation ShellBluetoothChooserCoordinator
- (instancetype)initWithBaseViewController:(UIViewController*)baseViewController
                                     title:(NSString*)title
                          bluetoothChooser:(content::ShellBluetoothChooserIOS*)
                                               bluetoothChooser {
  if (!(self = [super init])) {
    return nil;
  }

  _deviceListViewController =
      [[ShellDeviceListViewController alloc] initWithTitle:title];
  _deviceListViewController.modalPresentationStyle = UIModalPresentationPopover;
  _deviceListViewController.popoverPresentationController.delegate =
      _deviceListViewController;
  _deviceListViewController.popoverPresentationController.sourceView =
      baseViewController.view;
  _deviceListViewController.popoverPresentationController.sourceRect =
      baseViewController.view.bounds;

  _bluetoothChooserMediator = [[ShellBluetoothChooserMediator alloc]
      initWithBluetoothChooser:bluetoothChooser];
  _deviceListViewController.listDelegate = _bluetoothChooserMediator;
  _bluetoothChooserMediator.consumer = _deviceListViewController;
  [baseViewController presentViewController:_deviceListViewController
                                   animated:true
                                 completion:nil];
  return self;
}

namespace content {

ShellBluetoothChooserCoordinatorHolder::ShellBluetoothChooserCoordinatorHolder(
    gfx::NativeWindow native_window,
    content::ShellBluetoothChooserIOS* bluetooth_chooser_ios,
    const std::u16string& title) {
  coordinator_ = [[ShellBluetoothChooserCoordinator alloc]
      initWithBaseViewController:native_window.Get().rootViewController
                           title:base::SysUTF16ToNSString(title)
                bluetoothChooser:bluetooth_chooser_ios];
}

ShellBluetoothChooserCoordinatorHolder::
    ~ShellBluetoothChooserCoordinatorHolder() = default;

ShellBluetoothChooserMediator*
ShellBluetoothChooserCoordinatorHolder::getMediator() {
  return coordinator_.bluetoothChooserMediator;
}

}  // namespace content

@end