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