shell_integration_linux.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright (c) 2012 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_LINUX_H_
6#define CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/files/file_path.h"
12#include "chrome/browser/shell_integration.h"
13#include "url/gurl.h"
14
15namespace base {
16class Environment;
17}
18
19namespace ShellIntegrationLinux {
20
21// Get the path to write user-specific application data files to, as specified
22// in the XDG Base Directory Specification:
23// http://standards.freedesktop.org/basedir-spec/latest/
24// Returns true on success, or false if no such path could be found.
25// Called on the FILE thread.
26bool GetDataWriteLocation(base::Environment* env, base::FilePath* search_path);
27
28// Get the list of paths to search for application data files, in order of
29// preference, as specified in the XDG Base Directory Specification:
30// http://standards.freedesktop.org/basedir-spec/latest/
31// Called on the FILE thread.
32std::vector<base::FilePath> GetDataSearchLocations(base::Environment* env);
33
34// Gets the name for use as the res_class (and possibly res_name) of the
35// window's WM_CLASS property. This is the program name from argv[0], with the
36// first letter capitalized. Equivalent to GDK's gdk_get_program_class().
37std::string GetProgramClassName();
38
39// Returns filename of the desktop shortcut used to launch the browser.
40std::string GetDesktopName(base::Environment* env);
41
42// Returns name of the browser icon (without a path or file extension).
43std::string GetIconName();
44
45// Returns the set of locations in which shortcuts are installed for the
46// extension with |extension_id| in |profile_path|.
47// This searches the file system for .desktop files in appropriate locations. A
48// shortcut with NoDisplay=true causes hidden to become true, instead of
49// creating at APP_MENU_LOCATIONS_SUBDIR_CHROMEAPPS.
50ShellIntegration::ShortcutLocations GetExistingShortcutLocations(
51    base::Environment* env,
52    const base::FilePath& profile_path,
53    const std::string& extension_id);
54
55// Version of GetExistingShortcutLocations which takes an explicit path
56// to the user's desktop directory. Useful for testing.
57// If |desktop_path| is empty, the desktop is not searched.
58ShellIntegration::ShortcutLocations GetExistingShortcutLocations(
59    base::Environment* env,
60    const base::FilePath& profile_path,
61    const std::string& extension_id,
62    const base::FilePath& desktop_path);
63
64// Returns the contents of an existing .desktop file installed in the system.
65// Searches the "applications" subdirectory of each XDG data directory for a
66// file named |desktop_filename|. If the file is found, populates |output| with
67// its contents and returns true. Else, returns false.
68bool GetExistingShortcutContents(base::Environment* env,
69                                 const base::FilePath& desktop_filename,
70                                 std::string* output);
71
72// Returns filename for .desktop file based on |url|, sanitized for security.
73base::FilePath GetWebShortcutFilename(const GURL& url);
74
75// Returns filename for .desktop file based on |profile_path| and
76// |extension_id|, sanitized for security.
77base::FilePath GetExtensionShortcutFilename(const base::FilePath& profile_path,
78                                            const std::string& extension_id);
79
80// Returns a list of filenames for all existing .desktop files corresponding to
81// on |profile_path| in a given |directory|.
82std::vector<base::FilePath> GetExistingProfileShortcutFilenames(
83    const base::FilePath& profile_path,
84    const base::FilePath& directory);
85
86// Returns contents for .desktop file based on |url| and |title|. If
87// |no_display| is true, the shortcut will not be visible to the user in menus.
88std::string GetDesktopFileContents(const base::FilePath& chrome_exe_path,
89                                   const std::string& app_name,
90                                   const GURL& url,
91                                   const std::string& extension_id,
92                                   const base::string16& title,
93                                   const std::string& icon_name,
94                                   const base::FilePath& profile_path,
95                                   bool no_display);
96
97// Returns contents for .desktop file that executes command_line. This is a more
98// general form of GetDesktopFileContents. If |no_display| is true, the shortcut
99// will not be visible to the user in menus.
100std::string GetDesktopFileContentsForCommand(const CommandLine& command_line,
101                                             const std::string& app_name,
102                                             const GURL& url,
103                                             const base::string16& title,
104                                             const std::string& icon_name,
105                                             bool no_display);
106
107// Returns contents for .directory file named |title| with icon |icon_name|. If
108// |icon_name| is empty, will use the Chrome icon.
109std::string GetDirectoryFileContents(const base::string16& title,
110                                     const std::string& icon_name);
111
112// Create shortcuts on the desktop or in the application menu (as specified by
113// |shortcut_info|), for the web page or extension in |shortcut_info|.
114// For extensions, duplicate shortcuts are avoided, so if a requested shortcut
115// already exists it is deleted first.
116bool CreateDesktopShortcut(
117    const ShellIntegration::ShortcutInfo& shortcut_info,
118    const ShellIntegration::ShortcutLocations& creation_locations);
119
120// Create shortcuts in the application menu for the app launcher. Duplicate
121// shortcuts are avoided, so if a requested shortcut already exists it is
122// deleted first. Also creates the icon required by the shortcut.
123bool CreateAppListDesktopShortcut(const std::string& wm_class,
124                                  const std::string& title);
125
126// Delete any desktop shortcuts on desktop or in the application menu that have
127// been added for the extension with |extension_id| in |profile_path|.
128void DeleteDesktopShortcuts(const base::FilePath& profile_path,
129                            const std::string& extension_id);
130
131// Delete any desktop shortcuts on desktop or in the application menu that have
132// for the profile in |profile_path|.
133void DeleteAllDesktopShortcuts(const base::FilePath& profile_path);
134
135}  // namespace ShellIntegrationLinux
136
137#endif  // CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_
138