Home | History | Annotate | Download | only in browser
      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 
     15 namespace base {
     16 class Environment;
     17 }
     18 
     19 namespace 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.
     26 bool 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.
     32 std::vector<base::FilePath> GetDataSearchLocations(base::Environment* env);
     33 
     34 // Returns filename of the desktop shortcut used to launch the browser.
     35 std::string GetDesktopName(base::Environment* env);
     36 
     37 // Returns name of the browser icon (without a path or file extension).
     38 std::string GetIconName();
     39 
     40 // Returns the set of locations in which shortcuts are installed for the
     41 // extension with |extension_id| in |profile_path|.
     42 // This searches the file system for .desktop files in appropriate locations. A
     43 // shortcut with NoDisplay=true causes hidden to become true, instead of
     44 // in_applications_menu.
     45 ShellIntegration::ShortcutLocations GetExistingShortcutLocations(
     46     base::Environment* env,
     47     const base::FilePath& profile_path,
     48     const std::string& extension_id);
     49 
     50 // Version of GetExistingShortcutLocations which takes an explicit path
     51 // to the user's desktop directory. Useful for testing.
     52 // If |desktop_path| is empty, the desktop is not searched.
     53 ShellIntegration::ShortcutLocations GetExistingShortcutLocations(
     54     base::Environment* env,
     55     const base::FilePath& profile_path,
     56     const std::string& extension_id,
     57     const base::FilePath& desktop_path);
     58 
     59 // Returns the contents of an existing .desktop file installed in the system.
     60 // Searches the "applications" subdirectory of each XDG data directory for a
     61 // file named |desktop_filename|. If the file is found, populates |output| with
     62 // its contents and returns true. Else, returns false.
     63 bool GetExistingShortcutContents(base::Environment* env,
     64                                  const base::FilePath& desktop_filename,
     65                                  std::string* output);
     66 
     67 // Returns filename for .desktop file based on |url|, sanitized for security.
     68 base::FilePath GetWebShortcutFilename(const GURL& url);
     69 
     70 // Returns filename for .desktop file based on |profile_path| and
     71 // |extension_id|, sanitized for security.
     72 base::FilePath GetExtensionShortcutFilename(const base::FilePath& profile_path,
     73                                             const std::string& extension_id);
     74 
     75 // Returns a list of filenames for all existing .desktop files corresponding to
     76 // on |profile_path| in a given |directory|.
     77 std::vector<base::FilePath> GetExistingProfileShortcutFilenames(
     78     const base::FilePath& profile_path,
     79     const base::FilePath& directory);
     80 
     81 // Returns contents for .desktop file based on |url| and |title|. If
     82 // |no_display| is true, the shortcut will not be visible to the user in menus.
     83 std::string GetDesktopFileContents(const base::FilePath& chrome_exe_path,
     84                                    const std::string& app_name,
     85                                    const GURL& url,
     86                                    const std::string& extension_id,
     87                                    const base::FilePath& extension_path,
     88                                    const string16& title,
     89                                    const std::string& icon_name,
     90                                    const base::FilePath& profile_path,
     91                                    bool no_display);
     92 
     93 // Returns contents for .directory file named |title| with icon |icon_name|. If
     94 // |icon_name| is empty, will use the Chrome icon.
     95 std::string GetDirectoryFileContents(const string16& title,
     96                                      const std::string& icon_name);
     97 
     98 // Create shortcuts on the desktop or in the application menu (as specified by
     99 // |shortcut_info|), for the web page or extension in |shortcut_info|.
    100 // For extensions, duplicate shortcuts are avoided, so if a requested shortcut
    101 // already exists it is deleted first.
    102 bool CreateDesktopShortcut(
    103     const ShellIntegration::ShortcutInfo& shortcut_info,
    104     const ShellIntegration::ShortcutLocations& creation_locations);
    105 
    106 // Delete any desktop shortcuts on desktop or in the application menu that have
    107 // been added for the extension with |extension_id| in |profile_path|.
    108 void DeleteDesktopShortcuts(const base::FilePath& profile_path,
    109                             const std::string& extension_id);
    110 
    111 // Delete any desktop shortcuts on desktop or in the application menu that have
    112 // for the profile in |profile_path|.
    113 void DeleteAllDesktopShortcuts(const base::FilePath& profile_path);
    114 
    115 }  // namespace ShellIntegrationLinux
    116 
    117 #endif  // CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_
    118