[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / shell_integration_linux.h
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.
4
5 #ifndef CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_
6 #define CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_
7
8 #include <string>
9
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"
15 #include "url/gurl.h"
16
17 #if BUILDFLAG(IS_CHROMEOS_ASH)
18 #error shell_integration_linux is for desktop linux only.
19 #endif
20
21 namespace base {
22 class CommandLine;
23 class Environment;
24 }
25
26 namespace web_app {
27 struct DesktopActionInfo;
28 }
29
30 namespace shell_integration_linux {
31
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);
36
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);
42
43 // Gets the name for use as the res_name of the window's WM_CLASS property.
44 std::string GetProgramClassName();
45
46 // Gets the name for use as the res_class of the window's WM_CLASS property.
47 std::string GetProgramClassClass();
48
49 // Returns name of the browser icon (without a path or file extension).
50 std::string GetIconName();
51
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,
58                                  std::string* output);
59
60 // Returns filename for .desktop file based on |url|, sanitized for security.
61 base::FilePath GetWebShortcutFilename(const GURL& url);
62
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);
68
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,
74     const GURL& url,
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,
81     bool no_display,
82     const std::string& run_on_os_login_mode,
83     std::set<web_app::DesktopActionInfo> action_info);
84
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,
91     const GURL& url,
92     const std::u16string& title,
93     const std::string& icon_name,
94     const std::string& categories,
95     const std::string& mime_type,
96     bool no_display,
97     std::set<web_app::DesktopActionInfo> action_info);
98
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);
103
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
106 // Linux.
107 base::FilePath GetMimeTypesRegistrationFilename(
108     const base::FilePath& profile_path,
109     const webapps::AppId& app_id);
110
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);
115
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);
120
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);
126
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);
132
133 namespace internal {
134
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);
141
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);
145
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
148 // never happen.
149 base::FilePath GetChromeExePath();
150
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
153 // string.
154 std::string GetDesktopEntryStringValueFromFromDesktopFileForTest(
155     const std::string& key,
156     const std::string& shortcut_contents);
157
158 }  // namespace internal
159
160 }  // namespace shell_integration_linux
161
162 #endif  // CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_