shell_integration_linux.h revision a02191e04bc25c4935f804f2c080ae28663d096d
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 12a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "chrome/browser/web_applications/web_app.h" 13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class CommandLine; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Environment; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ShellIntegrationLinux { 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 222385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Get the path to write user-specific application data files to, as specified 232385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// in the XDG Base Directory Specification: 242385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// http://standards.freedesktop.org/basedir-spec/latest/ 252385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Returns true on success, or false if no such path could be found. 262385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Called on the FILE thread. 272385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochbool GetDataWriteLocation(base::Environment* env, base::FilePath* search_path); 282385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch 292385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Get the list of paths to search for application data files, in order of 302385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// preference, as specified in the XDG Base Directory Specification: 312385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// http://standards.freedesktop.org/basedir-spec/latest/ 322385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Called on the FILE thread. 332385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochstd::vector<base::FilePath> GetDataSearchLocations(base::Environment* env); 342385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch 3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Gets the name for use as the res_class (and possibly res_name) of the 3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// window's WM_CLASS property. This is the program name from argv[0], with the 3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// first letter capitalized. Equivalent to GDK's gdk_get_program_class(). 3858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)std::string GetProgramClassName(); 3958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns filename of the desktop shortcut used to launch the browser. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)std::string GetDesktopName(base::Environment* env); 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Returns name of the browser icon (without a path or file extension). 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)std::string GetIconName(); 45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the set of locations in which shortcuts are installed for the 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// extension with |extension_id| in |profile_path|. 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This searches the file system for .desktop files in appropriate locations. A 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// shortcut with NoDisplay=true causes hidden to become true, instead of 50a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// creating at APP_MENU_LOCATIONS_SUBDIR_CHROMEAPPS. 51a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochweb_app::ShortcutLocations GetExistingShortcutLocations( 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Environment* env, 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path, 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id); 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Version of GetExistingShortcutLocations which takes an explicit path 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// to the user's desktop directory. Useful for testing. 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// If |desktop_path| is empty, the desktop is not searched. 59a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochweb_app::ShortcutLocations GetExistingShortcutLocations( 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Environment* env, 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path, 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id, 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& desktop_path); 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns the contents of an existing .desktop file installed in the system. 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Searches the "applications" subdirectory of each XDG data directory for a 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// file named |desktop_filename|. If the file is found, populates |output| with 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// its contents and returns true. Else, returns false. 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool GetExistingShortcutContents(base::Environment* env, 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& desktop_filename, 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string* output); 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns filename for .desktop file based on |url|, sanitized for security. 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::FilePath GetWebShortcutFilename(const GURL& url); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns filename for .desktop file based on |profile_path| and 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |extension_id|, sanitized for security. 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::FilePath GetExtensionShortcutFilename(const base::FilePath& profile_path, 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& extension_id); 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 812385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Returns a list of filenames for all existing .desktop files corresponding to 822385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// on |profile_path| in a given |directory|. 832385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochstd::vector<base::FilePath> GetExistingProfileShortcutFilenames( 842385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch const base::FilePath& profile_path, 852385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch const base::FilePath& directory); 862385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Returns contents for .desktop file based on |url| and |title|. If 88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |no_display| is true, the shortcut will not be visible to the user in menus. 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)std::string GetDesktopFileContents(const base::FilePath& chrome_exe_path, 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& app_name, 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& extension_id, 93a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& title, 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& icon_name, 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path, 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool no_display); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Returns contents for .desktop file that executes command_line. This is a more 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// general form of GetDesktopFileContents. If |no_display| is true, the shortcut 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// will not be visible to the user in menus. 101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)std::string GetDesktopFileContentsForCommand( 102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const base::CommandLine& command_line, 103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::string& app_name, 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const GURL& url, 105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const base::string16& title, 106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::string& icon_name, 107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool no_display); 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Returns contents for .directory file named |title| with icon |icon_name|. If 110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |icon_name| is empty, will use the Chrome icon. 111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)std::string GetDirectoryFileContents(const base::string16& title, 112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::string& icon_name); 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Create shortcuts on the desktop or in the application menu (as specified by 115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// |shortcut_info|), for the web page or extension in |shortcut_info|. 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// For extensions, duplicate shortcuts are avoided, so if a requested shortcut 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// already exists it is deleted first. 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool CreateDesktopShortcut( 119a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const web_app::ShortcutInfo& shortcut_info, 120a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch const web_app::ShortcutLocations& creation_locations); 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Create shortcuts in the application menu for the app launcher. Duplicate 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// shortcuts are avoided, so if a requested shortcut already exists it is 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// deleted first. Also creates the icon required by the shortcut. 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool CreateAppListDesktopShortcut(const std::string& wm_class, 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& title); 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Delete any desktop shortcuts on desktop or in the application menu that have 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// been added for the extension with |extension_id| in |profile_path|. 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void DeleteDesktopShortcuts(const base::FilePath& profile_path, 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& extension_id); 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1332385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Delete any desktop shortcuts on desktop or in the application menu that have 1342385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// for the profile in |profile_path|. 1352385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochvoid DeleteAllDesktopShortcuts(const base::FilePath& profile_path); 1362385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ShellIntegrationLinux 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_SHELL_INTEGRATION_LINUX_H_ 140