1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_
6 #define CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_
10 #include "base/files/file_path.h"
11 #include "build/chromeos_buildflags.h"
12 #include "chrome/common/buildflags.h"
13 #include "components/services/app_service/public/cpp/file_handler.h"
14 #include "components/webapps/common/web_app_id.h"
17 #if BUILDFLAG(IS_CHROMEOS_ASH)
18 #error shell_integration_linux is for desktop linux only.
27 struct DesktopActionInfo;
30 namespace shell_integration_linux {
32 // Get the path to write user-specific application data files to, as specified
33 // in the XDG Base Directory Specification:
34 // http://standards.freedesktop.org/basedir-spec/latest/
35 base::FilePath GetDataWriteLocation(base::Environment* env);
37 // Get the list of paths to search for application data files, in order of
38 // preference, as specified in the XDG Base Directory Specification:
39 // http://standards.freedesktop.org/basedir-spec/latest/
40 // Called on the FILE thread.
41 std::vector<base::FilePath> GetDataSearchLocations(base::Environment* env);
43 // Gets the name for use as the res_name of the window's WM_CLASS property.
44 std::string GetProgramClassName();
46 // Gets the name for use as the res_class of the window's WM_CLASS property.
47 std::string GetProgramClassClass();
49 // Returns name of the browser icon (without a path or file extension).
50 std::string GetIconName();
52 // Returns the contents of an existing .desktop file installed in the system.
53 // Searches the "applications" subdirectory of each XDG data directory for a
54 // file named |desktop_filename|. If the file is found, populates |output| with
55 // its contents and returns true. Else, returns false.
56 bool GetExistingShortcutContents(base::Environment* env,
57 const base::FilePath& desktop_filename,
60 // Returns filename for .desktop file based on |url|, sanitized for security.
61 base::FilePath GetWebShortcutFilename(const GURL& url);
63 // Returns a list of filenames for all existing .desktop files corresponding to
64 // on |profile_path| in a given |directory|.
65 std::vector<base::FilePath> GetExistingProfileShortcutFilenames(
66 const base::FilePath& profile_path,
67 const base::FilePath& directory);
69 // Returns contents for .desktop file based on |url| and |title|. If
70 // |no_display| is true, the shortcut will not be visible to the user in menus.
71 std::string GetDesktopFileContents(
72 const base::FilePath& chrome_exe_path,
73 const std::string& app_name,
75 const std::string& extension_id,
76 const std::u16string& title,
77 const std::string& icon_name,
78 const base::FilePath& profile_path,
79 const std::string& categories,
80 const std::string& mime_type,
82 const std::string& run_on_os_login_mode,
83 std::set<web_app::DesktopActionInfo> action_info);
85 // Returns contents for .desktop file that executes command_line. This is a more
86 // general form of GetDesktopFileContents. If |no_display| is true, the shortcut
87 // will not be visible to the user in menus.
88 std::string GetDesktopFileContentsForCommand(
89 const base::CommandLine& command_line,
90 const std::string& app_name,
92 const std::u16string& title,
93 const std::string& icon_name,
94 const std::string& categories,
95 const std::string& mime_type,
97 std::set<web_app::DesktopActionInfo> action_info);
99 // Returns contents for .directory file named |title| with icon |icon_name|. If
100 // |icon_name| is empty, will use the Chrome icon.
101 std::string GetDirectoryFileContents(const std::u16string& title,
102 const std::string& icon_name);
104 // Returns the filename for a .xml file, corresponding to a given |app_id|,
105 // which is passed to `xdg-mime` to register one or more custom MIME types in
107 base::FilePath GetMimeTypesRegistrationFilename(
108 const base::FilePath& profile_path,
109 const webapps::AppId& app_id);
111 // Returns the contents of a .xml file as specified by |file_handlers|, which is
112 // passed to `xdg-mime` to register one or more custom MIME types in Linux.
113 std::string GetMimeTypesRegistrationFileContents(
114 const apps::FileHandlers& file_handlers);
116 // Windows that correspond to web apps need to have a deterministic (and
117 // different) WMClass than normal chrome windows so the window manager groups
118 // them as a separate application.
119 std::string GetWMClassFromAppName(std::string app_name);
121 // Wayland version of GetWMClassFromAppName explained above.
122 // The XDG application ID must match the name of the desktop entry file, where
123 // the latter looks like 'chrome-<web app id>-<profile name>.desktop'.
124 std::string GetXdgAppIdForWebApp(std::string app_name,
125 const base::FilePath& profile_path);
127 // Helper to launch xdg scripts. We don't want them to ask any questions on the
128 // terminal etc. The function returns true if the utility launches and exits
129 // cleanly, in which case |exit_code| returns the utility's exit code.
130 // thread_restrictions.h assumes it to be in shell_integration namespace.
131 bool LaunchXdgUtility(const std::vector<std::string>& argv, int* exit_code);
135 // Exposed for testing. Clients should use the corresponding functions in
136 // shell_integration_linux instead.
137 std::string GetProgramClassName(const base::CommandLine& command_line,
138 const std::string& desktop_file_name);
139 std::string GetProgramClassClass(const base::CommandLine& command_line,
140 const std::string& desktop_file_name);
142 // Get the value of NoDisplay from the [Desktop Entry] section of a .desktop
143 // file, given in |shortcut_contents|. If the key is not found, returns false.
144 bool GetNoDisplayFromDesktopFile(const std::string& shortcut_contents);
146 // Gets the path to the Chrome executable or wrapper script.
147 // Returns an empty path if the executable path could not be found, which should
149 base::FilePath GetChromeExePath();
151 // Get the value of |key| from the [Desktop Entry] section of a .desktop file,
152 // given in |shortcut_contents|. If the key is not found, returns an empty
154 std::string GetDesktopEntryStringValueFromFromDesktopFileForTest(
155 const std::string& key,
156 const std::string& shortcut_contents);
158 } // namespace internal
160 } // namespace shell_integration_linux
162 #endif // CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_