blob: 176f38265b1b175a7ff73df44ac42a65f867bf93 [file] [log] [blame]
Melissa Zhangdb4dffa2020-07-01 04:03:111// Copyright 2020 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
Melissa Zhangfd66f65a2021-10-14 23:46:305#ifndef CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATOR_H_
6#define CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATOR_H_
Melissa Zhangdb4dffa2020-07-01 04:03:117
Melissa Zhang9ede4892021-08-04 02:28:008#include <memory>
Jan Wilken Dörriead587c32021-03-11 14:09:279#include <string>
Melissa Zhangdb4dffa2020-07-01 04:03:1110
Melissa Zhang12f6a072020-09-30 21:16:0711#include "base/callback.h"
Keishi Hattori0e45c022021-11-27 09:25:5212#include "base/memory/raw_ptr.h"
Eric Willigers25f5ce32021-09-08 02:47:3713#include "build/chromeos_buildflags.h"
Melissa Zhangb330e5ab82020-07-21 05:51:3614#include "chrome/browser/sharesheet/sharesheet_types.h"
Melissa Zhang9ede4892021-08-04 02:28:0015#include "chrome/browser/sharesheet/sharesheet_ui_delegate.h"
Melissa Zhang59ca374f2020-07-22 05:55:5116#include "components/services/app_service/public/mojom/types.mojom.h"
Melissa Zhangc6105cc2021-03-16 05:19:4317#include "ui/base/accelerators/accelerator.h"
Melissa Zhang26c16932020-12-11 05:15:2318#include "ui/gfx/native_widget_types.h"
Melissa Zhangdb4dffa2020-07-01 04:03:1119
Melissa Zhang575490a2020-08-31 07:14:4020class Profile;
Melissa Zhang4fd3f9e2021-04-15 01:13:0821
Melissa Zhang4ac1bc12021-07-05 08:31:5222namespace gfx {
23struct VectorIcon;
24} // namespace gfx
Melissa Zhangdb4dffa2020-07-01 04:03:1125
Melissa Zhang9ede4892021-08-04 02:28:0026namespace ui {
27class Accelerator;
28} // namespace ui
29
Melissa Zhangdb4dffa2020-07-01 04:03:1130namespace views {
31class View;
Melissa Zhang4fd3f9e2021-04-15 01:13:0832} // namespace views
Melissa Zhangdb4dffa2020-07-01 04:03:1133
Melissa Zhangdb4dffa2020-07-01 04:03:1134namespace sharesheet {
35
36class SharesheetService;
37
Melissa Zhangfd66f65a2021-10-14 23:46:3038// The SharesheetServiceDelegator is the interface through which the business
Melissa Zhang4ac1bc12021-07-05 08:31:5239// logic in SharesheetService communicates with the UI.
Melissa Zhangfd66f65a2021-10-14 23:46:3040class SharesheetServiceDelegator {
Melissa Zhangdb4dffa2020-07-01 04:03:1141 public:
Melissa Zhangfd66f65a2021-10-14 23:46:3042 SharesheetServiceDelegator(gfx::NativeWindow native_window,
43 SharesheetService* sharesheet_service);
44 ~SharesheetServiceDelegator();
45 SharesheetServiceDelegator(const SharesheetServiceDelegator&) = delete;
46 SharesheetServiceDelegator& operator=(const SharesheetServiceDelegator&) =
Melissa Zhangdb4dffa2020-07-01 04:03:1147 delete;
48
Melissa Zhang4ac1bc12021-07-05 08:31:5249 gfx::NativeWindow GetNativeWindow();
Melissa Zhang9ede4892021-08-04 02:28:0050 SharesheetController* GetSharesheetController();
51
52 // TODO(crbug.com/1233830) : Remove after business logic is moved
53 // out of SharesheetHeaderView.
54 Profile* GetProfile();
55
Melissa Zhang859e8c32021-08-20 02:15:1056 SharesheetUiDelegate* GetUiDelegateForTesting();
57
Melissa Zhang9ede4892021-08-04 02:28:0058 // ==========================================================================
59 // ======================== SHARESHEET SERVICE TO UI ========================
60 // ==========================================================================
Melissa Zhang4ac1bc12021-07-05 08:31:5261
62 // The following are called by the ShareService to communicate with the UI.
Melissa Zhang9ede4892021-08-04 02:28:0063 void ShowBubble(std::vector<TargetInfo> targets,
64 apps::mojom::IntentPtr intent,
65 DeliveredCallback delivered_callback,
66 CloseCallback close_callback);
Kristi Parkb50dd052021-07-07 19:50:3467
Melissa Zhang822bfa322021-04-07 00:42:3168#if BUILDFLAG(IS_CHROMEOS_ASH)
Melissa Zhang9ede4892021-08-04 02:28:0069 // Skips the generic Sharesheet bubble and directly displays the
70 // NearbyShare bubble dialog.
71 void ShowNearbyShareBubbleForArc(apps::mojom::IntentPtr intent,
72 DeliveredCallback delivered_callback,
73 CloseCallback close_callback);
Melissa Zhang822bfa322021-04-07 00:42:3174#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Melissa Zhang4ac1bc12021-07-05 08:31:5275
76 // Invoked immediately after an action has launched in the event that UI
77 // changes need to occur at this point.
Melissa Zhang19e79adb2021-11-19 01:55:4778 void OnActionLaunched(bool has_action_view);
Melissa Zhang4ac1bc12021-07-05 08:31:5279
Melissa Zhang9ede4892021-08-04 02:28:0080 void CloseBubble(SharesheetResult result);
81
82 // ==========================================================================
83 // ======================== UI TO SHARESHEET SERVICE ========================
84 // ==========================================================================
Melissa Zhang4ac1bc12021-07-05 08:31:5285 // The following are called by the UI to communicate with the ShareService.
Jan Wilken Dörriedec99122021-03-11 18:02:3086 void OnBubbleClosed(const std::u16string& active_action);
87 void OnTargetSelected(const std::u16string& target_name,
Melissa Zhangf55c7502020-07-21 12:36:0588 const TargetType type,
Melissa Zhang59ca374f2020-07-22 05:55:5189 apps::mojom::IntentPtr intent,
Melissa Zhangf55c7502020-07-21 12:36:0590 views::View* share_action_view);
Melissa Zhangc6105cc2021-03-16 05:19:4391 bool OnAcceleratorPressed(const ui::Accelerator& accelerator,
92 const std::u16string& active_action);
Jan Wilken Dörriedec99122021-03-11 18:02:3093 const gfx::VectorIcon* GetVectorIcon(const std::u16string& display_name);
Melissa Zhang93826e692020-07-14 04:39:0294
Melissa Zhangdb4dffa2020-07-01 04:03:1195 private:
Melissa Zhang26c16932020-12-11 05:15:2396 // Only used for ID purposes. NativeWindow will always outlive the
Melissa Zhangfd66f65a2021-10-14 23:46:3097 // SharesheetServiceDelegator.
Melissa Zhang26c16932020-12-11 05:15:2398 gfx::NativeWindow native_window_;
99
Keishi Hattori0e45c022021-11-27 09:25:52100 raw_ptr<SharesheetService> sharesheet_service_;
Melissa Zhang9ede4892021-08-04 02:28:00101
102 std::unique_ptr<SharesheetUiDelegate> sharesheet_controller_;
Melissa Zhangdb4dffa2020-07-01 04:03:11103};
104
105} // namespace sharesheet
106
Melissa Zhangfd66f65a2021-10-14 23:46:30107#endif // CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATOR_H_