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