blob: 5992c63fcac5a587842a9413372ef1730c9d562d [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
Jan Wilken Dörriead587c32021-03-11 14:09:278#include <string>
Melissa Zhangdb4dffa2020-07-01 04:03:119
Melissa Zhang12f6a072020-09-30 21:16:0710#include "base/callback.h"
Melissa Zhang93826e692020-07-14 04:39:0211#include "chrome/browser/sharesheet/sharesheet_controller.h"
Melissa Zhangb330e5ab82020-07-21 05:51:3612#include "chrome/browser/sharesheet/sharesheet_types.h"
Melissa Zhang59ca374f2020-07-22 05:55:5113#include "components/services/app_service/public/mojom/types.mojom.h"
Melissa Zhangc6105cc2021-03-16 05:19:4314#include "ui/base/accelerators/accelerator.h"
Melissa Zhang26c16932020-12-11 05:15:2315#include "ui/gfx/native_widget_types.h"
Melissa Zhangdb4dffa2020-07-01 04:03:1116
Melissa Zhang575490a2020-08-31 07:14:4017class Profile;
Melissa Zhang4fd3f9e2021-04-15 01:13:0818
Melissa Zhang4ac1bc12021-07-05 08:31:5219namespace gfx {
20struct VectorIcon;
21} // namespace gfx
Melissa Zhangdb4dffa2020-07-01 04:03:1122
23namespace views {
24class View;
Melissa Zhang4fd3f9e2021-04-15 01:13:0825} // namespace views
Melissa Zhangdb4dffa2020-07-01 04:03:1126
Melissa Zhangdb4dffa2020-07-01 04:03:1127namespace sharesheet {
28
29class SharesheetService;
30
Melissa Zhang4ac1bc12021-07-05 08:31:5231// The SharesheetServiceDelegate is the interface through which the business
32// logic in SharesheetService communicates with the UI.
33class SharesheetServiceDelegate : public ::sharesheet::SharesheetController {
Melissa Zhangdb4dffa2020-07-01 04:03:1134 public:
Melissa Zhang26c16932020-12-11 05:15:2335 SharesheetServiceDelegate(gfx::NativeWindow native_window,
Maggie Cai69305332020-08-04 23:28:2636 SharesheetService* sharesheet_service);
Melissa Zhang4ac1bc12021-07-05 08:31:5237 ~SharesheetServiceDelegate() override = default;
Melissa Zhangdb4dffa2020-07-01 04:03:1138 SharesheetServiceDelegate(const SharesheetServiceDelegate&) = delete;
39 SharesheetServiceDelegate& operator=(const SharesheetServiceDelegate&) =
40 delete;
41
Melissa Zhang4ac1bc12021-07-05 08:31:5242 gfx::NativeWindow GetNativeWindow();
43
44 // The following are called by the ShareService to communicate with the UI.
45 virtual void ShowBubble(std::vector<TargetInfo> targets,
46 apps::mojom::IntentPtr intent,
Kristi Parkb50dd052021-07-07 19:50:3447 sharesheet::DeliveredCallback delivered_callback,
48 sharesheet::CloseCallback close_callback);
49
Melissa Zhang822bfa322021-04-07 00:42:3150#if BUILDFLAG(IS_CHROMEOS_ASH)
Melissa Zhang4ac1bc12021-07-05 08:31:5251 virtual void ShowNearbyShareBubble(
52 apps::mojom::IntentPtr intent,
53 sharesheet::DeliveredCallback delivered_callback,
54 sharesheet::CloseCallback close_callback) = 0;
Melissa Zhang822bfa322021-04-07 00:42:3155#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Melissa Zhang4ac1bc12021-07-05 08:31:5256
57 // Invoked immediately after an action has launched in the event that UI
58 // changes need to occur at this point.
59 virtual void OnActionLaunched();
60
61 // The following are called by the UI to communicate with the ShareService.
Jan Wilken Dörriedec99122021-03-11 18:02:3062 void OnBubbleClosed(const std::u16string& active_action);
63 void OnTargetSelected(const std::u16string& target_name,
Melissa Zhangf55c7502020-07-21 12:36:0564 const TargetType type,
Melissa Zhang59ca374f2020-07-22 05:55:5165 apps::mojom::IntentPtr intent,
Melissa Zhangf55c7502020-07-21 12:36:0566 views::View* share_action_view);
Melissa Zhangc6105cc2021-03-16 05:19:4367 bool OnAcceleratorPressed(const ui::Accelerator& accelerator,
68 const std::u16string& active_action);
Jan Wilken Dörriedec99122021-03-11 18:02:3069 const gfx::VectorIcon* GetVectorIcon(const std::u16string& display_name);
Melissa Zhang93826e692020-07-14 04:39:0270
Melissa Zhang4ac1bc12021-07-05 08:31:5271 // SharesheetController:
Melissa Zhang575490a2020-08-31 07:14:4072 Profile* GetProfile() override;
Melissa Zhang4ac1bc12021-07-05 08:31:5273 // Default implementation does nothing. Override as needed.
74 void SetSharesheetSize(int width, int height) override;
75 // Default implementation does nothing. Override as needed.
Melissa Zhangd1a8ba92020-08-07 00:32:4976 void CloseSharesheet() override;
Melissa Zhangdb4dffa2020-07-01 04:03:1177
78 private:
Melissa Zhang26c16932020-12-11 05:15:2379 // Only used for ID purposes. NativeWindow will always outlive the
80 // SharesheetServiceDelegate.
81 gfx::NativeWindow native_window_;
82
Melissa Zhangb0a050c82021-05-18 04:25:4583 // Owned by views.
Melissa Zhang93826e692020-07-14 04:39:0284 SharesheetService* sharesheet_service_;
Melissa Zhangdb4dffa2020-07-01 04:03:1185};
86
87} // namespace sharesheet
88
89#endif // CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_