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 | |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 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" |
Eric Willigers | 25f5ce3 | 2021-09-08 02:47:37 | [diff] [blame^] | 12 | #include "build/chromeos_buildflags.h" |
Melissa Zhang | b330e5ab8 | 2020-07-21 05:51:36 | [diff] [blame] | 13 | #include "chrome/browser/sharesheet/sharesheet_types.h" |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 14 | #include "chrome/browser/sharesheet/sharesheet_ui_delegate.h" |
Melissa Zhang | 59ca374f | 2020-07-22 05:55:51 | [diff] [blame] | 15 | #include "components/services/app_service/public/mojom/types.mojom.h" |
Melissa Zhang | c6105cc | 2021-03-16 05:19:43 | [diff] [blame] | 16 | #include "ui/base/accelerators/accelerator.h" |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 17 | #include "ui/gfx/native_widget_types.h" |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 18 | |
Melissa Zhang | 575490a | 2020-08-31 07:14:40 | [diff] [blame] | 19 | class Profile; |
Melissa Zhang | 4fd3f9e | 2021-04-15 01:13:08 | [diff] [blame] | 20 | |
Melissa Zhang | 4ac1bc1 | 2021-07-05 08:31:52 | [diff] [blame] | 21 | namespace gfx { |
| 22 | struct VectorIcon; |
| 23 | } // namespace gfx |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 24 | |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 25 | namespace ui { |
| 26 | class Accelerator; |
| 27 | } // namespace ui |
| 28 | |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 29 | namespace views { |
| 30 | class View; |
Melissa Zhang | 4fd3f9e | 2021-04-15 01:13:08 | [diff] [blame] | 31 | } // namespace views |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 32 | |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 33 | namespace sharesheet { |
| 34 | |
| 35 | class SharesheetService; |
| 36 | |
Melissa Zhang | 4ac1bc1 | 2021-07-05 08:31:52 | [diff] [blame] | 37 | // The SharesheetServiceDelegate is the interface through which the business |
| 38 | // logic in SharesheetService communicates with the UI. |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 39 | class SharesheetServiceDelegate { |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 40 | public: |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 41 | SharesheetServiceDelegate(gfx::NativeWindow native_window, |
Maggie Cai | 6930533 | 2020-08-04 23:28:26 | [diff] [blame] | 42 | SharesheetService* sharesheet_service); |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 43 | ~SharesheetServiceDelegate(); |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 44 | SharesheetServiceDelegate(const SharesheetServiceDelegate&) = delete; |
| 45 | SharesheetServiceDelegate& operator=(const SharesheetServiceDelegate&) = |
| 46 | delete; |
| 47 | |
Melissa Zhang | 4ac1bc1 | 2021-07-05 08:31:52 | [diff] [blame] | 48 | gfx::NativeWindow GetNativeWindow(); |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 49 | SharesheetController* GetSharesheetController(); |
| 50 | |
| 51 | // TODO(crbug.com/1233830) : Remove after business logic is moved |
| 52 | // out of SharesheetHeaderView. |
| 53 | Profile* GetProfile(); |
| 54 | |
Melissa Zhang | 859e8c3 | 2021-08-20 02:15:10 | [diff] [blame] | 55 | SharesheetUiDelegate* GetUiDelegateForTesting(); |
| 56 | |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 57 | // ========================================================================== |
| 58 | // ======================== SHARESHEET SERVICE TO UI ======================== |
| 59 | // ========================================================================== |
Melissa Zhang | 4ac1bc1 | 2021-07-05 08:31:52 | [diff] [blame] | 60 | |
| 61 | // The following are called by the ShareService to communicate with the UI. |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 62 | void ShowBubble(std::vector<TargetInfo> targets, |
| 63 | apps::mojom::IntentPtr intent, |
| 64 | DeliveredCallback delivered_callback, |
| 65 | CloseCallback close_callback); |
Kristi Park | b50dd05 | 2021-07-07 19:50:34 | [diff] [blame] | 66 | |
Melissa Zhang | 822bfa32 | 2021-04-07 00:42:31 | [diff] [blame] | 67 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 68 | // 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 Zhang | 822bfa32 | 2021-04-07 00:42:31 | [diff] [blame] | 73 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Melissa Zhang | 4ac1bc1 | 2021-07-05 08:31:52 | [diff] [blame] | 74 | |
| 75 | // Invoked immediately after an action has launched in the event that UI |
| 76 | // changes need to occur at this point. |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 77 | void OnActionLaunched(); |
Melissa Zhang | 4ac1bc1 | 2021-07-05 08:31:52 | [diff] [blame] | 78 | |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 79 | void CloseBubble(SharesheetResult result); |
| 80 | |
| 81 | // ========================================================================== |
| 82 | // ======================== UI TO SHARESHEET SERVICE ======================== |
| 83 | // ========================================================================== |
Melissa Zhang | 4ac1bc1 | 2021-07-05 08:31:52 | [diff] [blame] | 84 | // 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] | 85 | void OnBubbleClosed(const std::u16string& active_action); |
| 86 | void OnTargetSelected(const std::u16string& target_name, |
Melissa Zhang | f55c750 | 2020-07-21 12:36:05 | [diff] [blame] | 87 | const TargetType type, |
Melissa Zhang | 59ca374f | 2020-07-22 05:55:51 | [diff] [blame] | 88 | apps::mojom::IntentPtr intent, |
Melissa Zhang | f55c750 | 2020-07-21 12:36:05 | [diff] [blame] | 89 | views::View* share_action_view); |
Melissa Zhang | c6105cc | 2021-03-16 05:19:43 | [diff] [blame] | 90 | bool OnAcceleratorPressed(const ui::Accelerator& accelerator, |
| 91 | const std::u16string& active_action); |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 92 | const gfx::VectorIcon* GetVectorIcon(const std::u16string& display_name); |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 93 | |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 94 | private: |
Melissa Zhang | 26c1693 | 2020-12-11 05:15:23 | [diff] [blame] | 95 | // Only used for ID purposes. NativeWindow will always outlive the |
| 96 | // SharesheetServiceDelegate. |
| 97 | gfx::NativeWindow native_window_; |
| 98 | |
Melissa Zhang | 93826e69 | 2020-07-14 04:39:02 | [diff] [blame] | 99 | SharesheetService* sharesheet_service_; |
Melissa Zhang | 9ede489 | 2021-08-04 02:28:00 | [diff] [blame] | 100 | |
| 101 | std::unique_ptr<SharesheetUiDelegate> sharesheet_controller_; |
Melissa Zhang | db4dffa | 2020-07-01 04:03:11 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | } // namespace sharesheet |
| 105 | |
| 106 | #endif // CHROME_BROWSER_SHARESHEET_SHARESHEET_SERVICE_DELEGATE_H_ |