pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 1 | // Copyright 2016 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_SHELL_INTEGRATION_WIN_H_ |
| 6 | #define CHROME_BROWSER_SHELL_INTEGRATION_WIN_H_ |
| 7 | |
Jay Civelli | d4b8905 | 2017-10-31 17:48:25 | [diff] [blame] | 8 | #include <memory> |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 9 | #include <string> |
| 10 | |
| 11 | #include "base/callback_forward.h" |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
| 13 | #include "base/strings/string16.h" |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 14 | |
Jay Civelli | d4b8905 | 2017-10-31 17:48:25 | [diff] [blame] | 15 | namespace service_manager { |
| 16 | class Connector; |
| 17 | } |
| 18 | |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 19 | namespace shell_integration { |
| 20 | namespace win { |
| 21 | |
| 22 | // Initiates an OS shell flow which (if followed by the user) should set |
| 23 | // Chrome as the default browser. Returns false if the flow cannot be |
| 24 | // initialized, if it is not supported (introduced for Windows 8) or if the |
| 25 | // user cancels the operation. This is a blocking call and requires a FILE |
| 26 | // thread. If Chrome is already default browser, no interactive dialog will be |
| 27 | // shown and this method returns true. |
| 28 | bool SetAsDefaultBrowserUsingIntentPicker(); |
| 29 | |
| 30 | // Initiates the interaction with the system settings for the default browser. |
| 31 | // The function takes care of making sure |on_finished_callback| will get called |
| 32 | // exactly once when the interaction is finished. |
| 33 | void SetAsDefaultBrowserUsingSystemSettings( |
| 34 | const base::Closure& on_finished_callback); |
| 35 | |
| 36 | // Initiates an OS shell flow which (if followed by the user) should set |
| 37 | // Chrome as the default handler for |protocol|. Returns false if the flow |
| 38 | // cannot be initialized, if it is not supported (introduced for Windows 8) |
| 39 | // or if the user cancels the operation. This is a blocking call and requires |
| 40 | // a FILE thread. If Chrome is already default for |protocol|, no interactive |
| 41 | // dialog will be shown and this method returns true. |
| 42 | bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol); |
| 43 | |
pmonette | 0c40087a | 2016-04-21 00:05:16 | [diff] [blame] | 44 | // Initiates the interaction with the system settings for the default handler of |
| 45 | // |protocol|. The function takes care of making sure |on_finished_callback| |
| 46 | // will get called exactly once when the interaction is finished. |
| 47 | void SetAsDefaultProtocolClientUsingSystemSettings( |
| 48 | const std::string& protocol, |
| 49 | const base::Closure& on_finished_callback); |
| 50 | |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 51 | // Generates an application user model ID (AppUserModelId) for a given app |
| 52 | // name and profile path. The returned app id is in the format of |
| 53 | // "|app_name|[.<profile_id>]". "profile_id" is appended when user override |
| 54 | // the default value. |
| 55 | // Note: If the app has an installation specific suffix (e.g. on user-level |
| 56 | // Chrome installs), |app_name| should already be suffixed, this method will |
| 57 | // then further suffix it with the profile id as described above. |
| 58 | base::string16 GetAppModelIdForProfile(const base::string16& app_name, |
| 59 | const base::FilePath& profile_path); |
| 60 | |
| 61 | // Generates an application user model ID (AppUserModelId) for Chromium by |
| 62 | // calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name. |
| 63 | base::string16 GetChromiumModelIdForProfile(const base::FilePath& profile_path); |
| 64 | |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 65 | // Returns the taskbar pin state of Chrome via the IsPinnedToTaskbarCallback. |
| 66 | // The first bool is true if the state could be calculated, and the second bool |
| 67 | // is true if Chrome is pinned to the taskbar. |
| 68 | // The ConnectionErrorCallback is called instead if something wrong happened |
| 69 | // with the connection to the remote process. |
Jay Civelli | d4b8905 | 2017-10-31 17:48:25 | [diff] [blame] | 70 | // |connector| should be a fresh connector unbound to any thread. |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 71 | using ConnectionErrorCallback = base::Closure; |
| 72 | using IsPinnedToTaskbarCallback = base::Callback<void(bool, bool)>; |
| 73 | void GetIsPinnedToTaskbarState( |
Jay Civelli | d4b8905 | 2017-10-31 17:48:25 | [diff] [blame] | 74 | std::unique_ptr<service_manager::Connector> connector, |
pmonette | a9831524 | 2016-11-23 21:39:18 | [diff] [blame] | 75 | const ConnectionErrorCallback& on_error_callback, |
| 76 | const IsPinnedToTaskbarCallback& result_callback); |
pmonette | 5057ca3b | 2016-07-04 16:48:40 | [diff] [blame] | 77 | |
pmonette | 9e4c1a8 | 2016-04-14 18:15:30 | [diff] [blame] | 78 | // Migrates existing chrome taskbar pins by tagging them with correct app id. |
| 79 | // see http://crbug.com/28104 |
| 80 | void MigrateTaskbarPins(); |
| 81 | |
| 82 | // Migrates all shortcuts in |path| which point to |chrome_exe| such that they |
| 83 | // have the appropriate AppUserModelId. Also clears the legacy dual_mode |
| 84 | // property from shortcuts with the default chrome app id. |
| 85 | // Returns the number of shortcuts migrated. |
| 86 | // This method should not be called prior to Windows 7. |
| 87 | // This method is only public for the sake of tests and shouldn't be called |
| 88 | // externally otherwise. |
| 89 | int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, |
| 90 | const base::FilePath& path); |
| 91 | |
pmonette | 32a5cfb4 | 2016-04-11 22:04:44 | [diff] [blame] | 92 | } // namespace win |
| 93 | } // namespace shell_integration |
| 94 | |
| 95 | #endif // CHROME_BROWSER_SHELL_INTEGRATION_WIN_H_ |