blob: 09fcfc2b396ce2f86abe09270af58198ed80c2a5 [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
5#ifndef CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_
6#define CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_
7
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"
Eric Willigers25f5ce32021-09-08 02:47:3712#include "build/chromeos_buildflags.h"
Melissa Zhangb330e5ab82020-07-21 05:51:3613#include "chrome/browser/sharesheet/sharesheet_types.h"
Melissa Zhang9ede4892021-08-04 02:28:0014#include "chrome/browser/sharesheet/sharesheet_ui_delegate.h"
Melissa Zhang59ca374f2020-07-22 05:55:5115#include "components/services/app_service/public/mojom/types.mojom.h"
Melissa Zhangc6105cc2021-03-16 05:19:4316#include "ui/base/accelerators/accelerator.h"
Melissa Zhang26c16932020-12-11 05:15:2317#include "ui/gfx/native_widget_types.h"
Melissa Zhangdb4dffa2020-07-01 04:03:1118
Melissa Zhang575490a2020-08-31 07:14:4019class Profile;
Melissa Zhang4fd3f9e2021-04-15 01:13:0820
Melissa Zhang4ac1bc12021-07-05 08:31:5221namespace gfx {
22struct VectorIcon;
23} // namespace gfx
Melissa Zhangdb4dffa2020-07-01 04:03:1124
Melissa Zhang9ede4892021-08-04 02:28:0025namespace ui {
26class Accelerator;
27} // namespace ui
28
Melissa Zhangdb4dffa2020-07-01 04:03:1129namespace views {
30class View;
Melissa Zhang4fd3f9e2021-04-15 01:13:0831} // namespace views
Melissa Zhangdb4dffa2020-07-01 04:03:1132
Melissa Zhangdb4dffa2020-07-01 04:03:1133namespace sharesheet {
34
35class SharesheetService;
36
Melissa Zhang4ac1bc12021-07-05 08:31:5237// The SharesheetServiceDelegate is the interface through which the business
38// logic in SharesheetService communicates with the UI.
Melissa Zhang9ede4892021-08-04 02:28:0039class SharesheetServiceDelegate {
Melissa Zhangdb4dffa2020-07-01 04:03:1140 public:
Melissa Zhang26c16932020-12-11 05:15:2341 SharesheetServiceDelegate(gfx::NativeWindow native_window,
Maggie Cai69305332020-08-04 23:28:2642 SharesheetService* sharesheet_service);
Melissa Zhang9ede4892021-08-04 02:28:0043 ~SharesheetServiceDelegate();
Melissa Zhangdb4dffa2020-07-01 04:03:1144 SharesheetServiceDelegate(const SharesheetServiceDelegate&) = delete;
45 SharesheetServiceDelegate& operator=(const SharesheetServiceDelegate&) =
46 delete;
47
Melissa Zhang4ac1bc12021-07-05 08:31:5248 gfx::NativeWindow GetNativeWindow();
Melissa Zhang9ede4892021-08-04 02:28:0049 SharesheetController* GetSharesheetController();
50
51 // TODO(crbug.com/1233830) : Remove after business logic is moved
52 // out of SharesheetHeaderView.
53 Profile* GetProfile();
54
Melissa Zhang859e8c32021-08-20 02:15:1055 SharesheetUiDelegate* GetUiDelegateForTesting();
56
Melissa Zhang9ede4892021-08-04 02:28:0057 // ==========================================================================
58 // ======================== SHARESHEET SERVICE TO UI ========================
59 // ==========================================================================
Melissa Zhang4ac1bc12021-07-05 08:31:5260
61 // The following are called by the ShareService to communicate with the UI.
Melissa Zhang9ede4892021-08-04 02:28:0062 void ShowBubble(std::vector<TargetInfo> targets,
63 apps::mojom::IntentPtr intent,
64 DeliveredCallback delivered_callback,
65 CloseCallback close_callback);
Kristi Parkb50dd052021-07-07 19:50:3466
Melissa Zhang822bfa322021-04-07 00:42:3167#if BUILDFLAG(IS_CHROMEOS_ASH)
Melissa Zhang9ede4892021-08-04 02:28:0068 // Skips the generic Sharesheet bubble and directly displays the
69 // NearbyShare bubble dialog.
70 void ShowNearbyShareBubbleForArc(apps::mojom::IntentPtr intent,
71 DeliveredCallback delivered_callback,
72 CloseCallback close_callback);
Melissa Zhang822bfa322021-04-07 00:42:3173#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Melissa Zhang4ac1bc12021-07-05 08:31:5274
75 // Invoked immediately after an action has launched in the event that UI
76 // changes need to occur at this point.
Melissa Zhang9ede4892021-08-04 02:28:0077 void OnActionLaunched();
Melissa Zhang4ac1bc12021-07-05 08:31:5278
Melissa Zhang9ede4892021-08-04 02:28:0079 void CloseBubble(SharesheetResult result);
80
81 // ==========================================================================
82 // ======================== UI TO SHARESHEET SERVICE ========================
83 // ==========================================================================
Melissa Zhang4ac1bc12021-07-05 08:31:5284 // The following are called by the UI to communicate with the ShareService.
Jan Wilken Dörriedec99122021-03-11 18:02:3085 void OnBubbleClosed(const std::u16string& active_action);
86 void OnTargetSelected(const std::u16string& target_name,
Melissa Zhangf55c7502020-07-21 12:36:0587 const TargetType type,
Melissa Zhang59ca374f2020-07-22 05:55:5188 apps::mojom::IntentPtr intent,
Melissa Zhangf55c7502020-07-21 12:36:0589 views::View* share_action_view);
Melissa Zhangc6105cc2021-03-16 05:19:4390 bool OnAcceleratorPressed(const ui::Accelerator& accelerator,
91 const std::u16string& active_action);
Jan Wilken Dörriedec99122021-03-11 18:02:3092 const gfx::VectorIcon* GetVectorIcon(const std::u16string& display_name);
Melissa Zhang93826e692020-07-14 04:39:0293
Melissa Zhangdb4dffa2020-07-01 04:03:1194 private:
Melissa Zhang26c16932020-12-11 05:15:2395 // Only used for ID purposes. NativeWindow will always outlive the
96 // SharesheetServiceDelegate.
97 gfx::NativeWindow native_window_;
98
Melissa Zhang93826e692020-07-14 04:39:0299 SharesheetService* sharesheet_service_;
Melissa Zhang9ede4892021-08-04 02:28:00100
101 std::unique_ptr<SharesheetUiDelegate> sharesheet_controller_;
Melissa Zhangdb4dffa2020-07-01 04:03:11102};
103
104} // namespace sharesheet
105
106#endif // CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_