shell_integration_linux.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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::FilePath& extension_path,
93                                   const base::string16& title,
94                                   const std::string& icon_name,
95                                   const base::FilePath& profile_path,
96                                   bool no_display);
97
98// Returns contents for .directory file named |title| with icon |icon_name|. If
99// |icon_name| is empty, will use the Chrome icon.
100std::string GetDirectoryFileContents(const base::string16& title,
101                                     const std::string& icon_name);
102
103// Create shortcuts on the desktop or in the application menu (as specified by
104// |shortcut_info|), for the web page or extension in |shortcut_info|.
105// For extensions, duplicate shortcuts are avoided, so if a requested shortcut
106// already exists it is deleted first.
107bool CreateDesktopShortcut(
108    const ShellIntegration::ShortcutInfo& shortcut_info,
109    const ShellIntegration::ShortcutLocations& creation_locations);
110
111// Delete any desktop shortcuts on desktop or in the application menu that have
112// been added for the extension with |extension_id| in |profile_path|.
113void DeleteDesktopShortcuts(const base::FilePath& profile_path,
114                            const std::string& extension_id);
115
116// Delete any desktop shortcuts on desktop or in the application menu that have
117// for the profile in |profile_path|.
118void DeleteAllDesktopShortcuts(const base::FilePath& profile_path);
119
120}  // namespace ShellIntegrationLinux
121
122#endif  // CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_
123