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
|