Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 1 | // 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 | |
| 8 | #include <memory> |
Jan Wilken Dörrie | ad587c3 | 2021-03-11 14:09:27 | [diff] [blame] | 9 | #include <string> |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 10 | |
Melissa Zhang | 12f6a07 | 2020-09-30 21:16:07 | [diff] [blame] | 11 | #include "base/callback.h" |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 12 | #include "chrome/browser/sharesheet/sharesheet_controller.h" |
Melissa Zhang | b330e5ab8 | 2020-07-21 05:51:36 | [diff] [blame] | 13 | #include "chrome/browser/sharesheet/sharesheet_types.h" |
Melissa Zhang | 59ca374f | 2020-07-22 05:55:51 | [diff] [blame] | 14 | #include "components/services/app_service/public/mojom/types.mojom.h" |
Melissa Zhang | c6105cc | 2021-03-16 05:19:43 | [diff] [blame] | 15 | #include "ui/base/accelerators/accelerator.h" |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 16 | #include "ui/gfx/native_widget_types.h" |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 17 | |
Melissa Zhang | 575490a | 2020-08-31 07:14:40 | [diff] [blame] | 18 | class Profile; |
Melissa Zhang | 4fd3f9e | 2021-04-15 01:13:08 | [diff] [blame^] | 19 | |
| 20 | namespace ash { |
| 21 | namespace sharesheet { |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 22 | class SharesheetBubbleView; |
Melissa Zhang | 4fd3f9e | 2021-04-15 01:13:08 | [diff] [blame^] | 23 | } // namespace sharesheet |
| 24 | } // namespace ash |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 25 | |
| 26 | namespace views { |
| 27 | class View; |
Melissa Zhang | 4fd3f9e | 2021-04-15 01:13:08 | [diff] [blame^] | 28 | } // namespace views |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 29 | |
Melissa Zhang | a8a835f | 2020-11-05 05:02:46 | [diff] [blame] | 30 | namespace gfx { |
| 31 | struct VectorIcon; |
Melissa Zhang | 4fd3f9e | 2021-04-15 01:13:08 | [diff] [blame^] | 32 | } // namespace gfx |
Melissa Zhang | a8a835f | 2020-11-05 05:02:46 | [diff] [blame] | 33 | |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 34 | namespace sharesheet { |
| 35 | |
| 36 | class SharesheetService; |
| 37 | |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 38 | // The SharesheetServiceDelegate is the middle point between the UI and the |
| 39 | // business logic in the sharesheet. |
| 40 | class SharesheetServiceDelegate : public SharesheetController { |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 41 | public: |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 42 | SharesheetServiceDelegate(gfx::NativeWindow native_window, |
Maggie Cai | 6930533 | 2020-08-04 23:28:26 | [diff] [blame] | 43 | SharesheetService* sharesheet_service); |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 44 | ~SharesheetServiceDelegate() override; |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 45 | SharesheetServiceDelegate(const SharesheetServiceDelegate&) = delete; |
| 46 | SharesheetServiceDelegate& operator=(const SharesheetServiceDelegate&) = |
| 47 | delete; |
| 48 | |
Melissa Zhang | 59ca374f | 2020-07-22 05:55:51 | [diff] [blame] | 49 | void ShowBubble(std::vector<TargetInfo> targets, |
Melissa Zhang | 12f6a07 | 2020-09-30 21:16:07 | [diff] [blame] | 50 | apps::mojom::IntentPtr intent, |
Melissa Zhang | 822bfa32 | 2021-04-07 00:42:31 | [diff] [blame] | 51 | sharesheet::DeliveredCallback delivered_callback); |
| 52 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Melissa Zhang | 0b02a3b0 | 2021-03-25 04:23:45 | [diff] [blame] | 53 | void ShowNearbyShareBubble(apps::mojom::IntentPtr intent, |
Melissa Zhang | 822bfa32 | 2021-04-07 00:42:31 | [diff] [blame] | 54 | sharesheet::DeliveredCallback delivered_callback); |
| 55 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 56 | void OnBubbleClosed(const std::u16string& active_action); |
| 57 | void OnTargetSelected(const std::u16string& target_name, |
Melissa Zhang | f55c750 | 2020-07-21 12:36:05 | [diff] [blame] | 58 | const TargetType type, |
Melissa Zhang | 59ca374f | 2020-07-22 05:55:51 | [diff] [blame] | 59 | apps::mojom::IntentPtr intent, |
Melissa Zhang | f55c750 | 2020-07-21 12:36:05 | [diff] [blame] | 60 | views::View* share_action_view); |
Melissa Zhang | c6105cc | 2021-03-16 05:19:43 | [diff] [blame] | 61 | bool OnAcceleratorPressed(const ui::Accelerator& accelerator, |
| 62 | const std::u16string& active_action); |
Melissa Zhang | f55c750 | 2020-07-21 12:36:05 | [diff] [blame] | 63 | void OnActionLaunched(); |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 64 | const gfx::VectorIcon* GetVectorIcon(const std::u16string& display_name); |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 65 | gfx::NativeWindow GetNativeWindow(); |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 66 | |
| 67 | // SharesheetController overrides |
Melissa Zhang | 575490a | 2020-08-31 07:14:40 | [diff] [blame] | 68 | Profile* GetProfile() override; |
Melissa Zhang | 0f75f3b | 2020-08-19 05:24:26 | [diff] [blame] | 69 | void SetSharesheetSize(const int& width, const int& height) override; |
Melissa Zhang | d1a8ba9 | 2020-08-07 00:32:49 | [diff] [blame] | 70 | void CloseSharesheet() override; |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 71 | |
| 72 | private: |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 73 | bool is_bubble_open_ = false; |
| 74 | |
| 75 | // Only used for ID purposes. NativeWindow will always outlive the |
| 76 | // SharesheetServiceDelegate. |
| 77 | gfx::NativeWindow native_window_; |
| 78 | |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 79 | std::u16string active_action_; |
Melissa Zhang | 4fd3f9e | 2021-04-15 01:13:08 | [diff] [blame^] | 80 | std::unique_ptr<ash::sharesheet::SharesheetBubbleView> |
| 81 | sharesheet_bubble_view_; |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 82 | SharesheetService* sharesheet_service_; |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | } // namespace sharesheet |
| 86 | |
| 87 | #endif // CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_ |