File: sharesheet_service_delegator.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (133 lines) | stat: -rw-r--r-- 4,505 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/sharesheet/sharesheet_service_delegator.h"

#include <utility>

#include "base/functional/callback.h"
#include "base/notimplemented.h"
#include "build/build_config.h"
#include "chrome/browser/sharesheet/sharesheet_service.h"
#include "chrome/browser/ui/ash/sharesheet/sharesheet_bubble_view_delegate.h"
#include "chrome/browser/ui/ash/sharesheet/sharesheet_header_view.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/views/view.h"

namespace sharesheet {

SharesheetServiceDelegator::SharesheetServiceDelegator(
    gfx::NativeWindow native_window,
    SharesheetService* sharesheet_service)
    : native_window_(native_window), sharesheet_service_(sharesheet_service) {
#if BUILDFLAG(IS_CHROMEOS)
  sharesheet_controller_ =
      std::make_unique<ash::sharesheet::SharesheetBubbleViewDelegate>(
          native_window_, this);
#else
  NOTIMPLEMENTED();
#endif  // BUILDFLAG(IS_CHROMEOS)
}

SharesheetServiceDelegator::~SharesheetServiceDelegator() = default;

gfx::NativeWindow SharesheetServiceDelegator::GetNativeWindow() {
  DCHECK(native_window_);
  return native_window_;
}

SharesheetController* SharesheetServiceDelegator::GetSharesheetController() {
  DCHECK(sharesheet_controller_);
  return sharesheet_controller_.get();
}

Profile* SharesheetServiceDelegator::GetProfile() {
  DCHECK(sharesheet_service_);
  return sharesheet_service_->GetProfile();
}

SharesheetUiDelegate* SharesheetServiceDelegator::GetUiDelegateForTesting() {
  return sharesheet_controller_.get();
}

void SharesheetServiceDelegator::ShowBubble(
    std::vector<TargetInfo> targets,
    apps::IntentPtr intent,
    DeliveredCallback delivered_callback,
    CloseCallback close_callback) {
  if (sharesheet_controller_) {
    sharesheet_controller_->ShowBubble(std::move(targets), std::move(intent),
                                       std::move(delivered_callback),
                                       std::move(close_callback));
    return;
  }
  NOTREACHED();
}

#if BUILDFLAG(IS_CHROMEOS)
// Skips the generic Sharesheet bubble and directly displays the
// NearbyShare bubble dialog.
void SharesheetServiceDelegator::ShowNearbyShareBubbleForArc(
    apps::IntentPtr intent,
    DeliveredCallback delivered_callback,
    CloseCallback close_callback) {
  DCHECK(sharesheet_controller_);
  sharesheet_controller_->ShowNearbyShareBubbleForArc(
      std::move(intent), std::move(delivered_callback),
      std::move(close_callback));
}
#endif  // BUILDFLAG(IS_CHROMEOS)

// Invoked immediately after an action has launched in the event that UI
// changes need to occur at this point.
void SharesheetServiceDelegator::OnActionLaunched(bool has_action_view) {
  if (sharesheet_controller_) {
    sharesheet_controller_->OnActionLaunched(has_action_view);
    return;
  }
  NOTREACHED();
}

void SharesheetServiceDelegator::CloseBubble(SharesheetResult result) {
  if (sharesheet_controller_) {
    sharesheet_controller_->CloseBubble(result);
    return;
  }
  NOTREACHED();
}

void SharesheetServiceDelegator::OnBubbleClosed(
    const std::optional<ShareActionType>& share_action_type) {
  DCHECK(sharesheet_service_);
  sharesheet_service_->OnBubbleClosed(native_window_, share_action_type);
  // This object is now deleted and nothing can be accessed any more.
}

void SharesheetServiceDelegator::OnTargetSelected(
    const TargetType type,
    const std::optional<ShareActionType>& share_action_type,
    const std::optional<std::u16string>& app_name,
    apps::IntentPtr intent,
    views::View* share_action_view) {
  DCHECK(sharesheet_service_);
  sharesheet_service_->OnTargetSelected(native_window_, type, share_action_type,
                                        app_name, std::move(intent),
                                        share_action_view);
}

bool SharesheetServiceDelegator::OnAcceleratorPressed(
    const ui::Accelerator& accelerator,
    const ShareActionType share_action_type) {
  DCHECK(sharesheet_service_);
  return sharesheet_service_->OnAcceleratorPressed(accelerator,
                                                   share_action_type);
}

const gfx::VectorIcon* SharesheetServiceDelegator::GetVectorIcon(
    const std::optional<ShareActionType>& share_action_type) {
  DCHECK(sharesheet_service_);
  return sharesheet_service_->GetVectorIcon(share_action_type);
}

}  // namespace sharesheet