summaryrefslogtreecommitdiffstats
path: root/chrome/browser/shell_integration_linux.cc
diff options
context:
space:
mode:
authorbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-11 06:10:07 +0000
committerbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-11 06:10:07 +0000
commit914636612ba4bf032b809e1dcf09a11f87384515 (patch)
tree93fbe4da0ae3e9ac17064e64430a707621722450 /chrome/browser/shell_integration_linux.cc
parentc15faf37bc7ae6421489be2f69403e95df9ca237 (diff)
downloadchromium_src-914636612ba4bf032b809e1dcf09a11f87384515.zip
chromium_src-914636612ba4bf032b809e1dcf09a11f87384515.tar.gz
chromium_src-914636612ba4bf032b809e1dcf09a11f87384515.tar.bz2
Remove app shortcuts when app is uninstalled on Linux.
To support this, shortcut creation on Linux for extensions has been modified so that the filename encodes the extension ID and the profile. Also, when creating shortcuts any existing shortcuts are removed first. Web page shortcuts are not affected. BUG=130456 TEST=Test uninstalling apps removes their shortcuts; test uninstalling apps is not broken in any way; test shortcuts for web apps are not broken in any way. Review URL: https://chromiumcodereview.appspot.com/10698114 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/shell_integration_linux.cc')
-rw-r--r--chrome/browser/shell_integration_linux.cc65
1 files changed, 62 insertions, 3 deletions
diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc
index 840f056..ea05095 100644
--- a/chrome/browser/shell_integration_linux.cc
+++ b/chrome/browser/shell_integration_linux.cc
@@ -154,6 +154,12 @@ bool CreateShortcutOnDesktop(const FilePath& shortcut_filename,
return true;
}
+void DeleteShortcutOnDesktop(const FilePath& shortcut_filename) {
+ FilePath desktop_path;
+ if (PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path))
+ file_util::Delete(desktop_path.Append(shortcut_filename), false);
+}
+
bool CreateShortcutInApplicationsMenu(const FilePath& shortcut_filename,
const std::string& contents) {
ScopedTempDir temp_dir;
@@ -183,6 +189,22 @@ bool CreateShortcutInApplicationsMenu(const FilePath& shortcut_filename,
return exit_code == 0;
}
+void DeleteShortcutInApplicationsMenu(const FilePath& shortcut_filename) {
+ std::vector<std::string> argv;
+ argv.push_back("xdg-desktop-menu");
+ argv.push_back("uninstall");
+
+ // Uninstall in user mode, to match the install.
+ argv.push_back("--mode");
+ argv.push_back("user");
+
+ // The file does not need to exist anywhere - xdg-desktop-menu will uninstall
+ // items from the menu with a matching name.
+ argv.push_back(shortcut_filename.value());
+ int exit_code;
+ LaunchXdgUtility(argv, &exit_code);
+}
+
// Quote a string such that it appears as one verbatim argument for the Exec
// key in a desktop file.
std::string QuoteArgForDesktopFileExec(const std::string& arg) {
@@ -455,7 +477,7 @@ bool GetDesktopShortcutTemplate(base::Environment* env,
return false;
}
-FilePath GetDesktopShortcutFilename(const GURL& url) {
+FilePath GetWebShortcutFilename(const GURL& url) {
// Use a prefix, because xdg-desktop-menu requires it.
std::string filename =
std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec();
@@ -479,6 +501,20 @@ FilePath GetDesktopShortcutFilename(const GURL& url) {
return FilePath();
}
+FilePath GetExtensionShortcutFilename(const FilePath& profile_path,
+ const std::string& extension_id) {
+ DCHECK(!extension_id.empty());
+
+ // Use a prefix, because xdg-desktop-menu requires it.
+ std::string filename(chrome::kBrowserProcessExecutableName);
+ filename.append("-")
+ .append(extension_id)
+ .append("-")
+ .append(profile_path.BaseName().value());
+ file_util::ReplaceIllegalCharactersInPath(&filename, '_');
+ return FilePath(filename.append(".desktop"));
+}
+
std::string GetDesktopFileContents(
const std::string& template_contents,
const std::string& app_name,
@@ -597,8 +633,19 @@ bool CreateDesktopShortcut(
const std::string& shortcut_template) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- FilePath shortcut_filename =
- ShellIntegrationLinux::GetDesktopShortcutFilename(shortcut_info.url);
+ FilePath shortcut_filename;
+ if (!shortcut_info.extension_id.empty()) {
+ shortcut_filename = GetExtensionShortcutFilename(
+ shortcut_info.profile_path, shortcut_info.extension_id);
+ // For extensions we do not want duplicate shortcuts. So, delete any that
+ // already exist and replace them.
+ if (shortcut_info.create_on_desktop)
+ DeleteShortcutOnDesktop(shortcut_filename);
+ if (shortcut_info.create_in_applications_menu)
+ DeleteShortcutInApplicationsMenu(shortcut_filename);
+ } else {
+ shortcut_filename = GetWebShortcutFilename(shortcut_info.url);
+ }
if (shortcut_filename.empty())
return false;
@@ -629,4 +676,16 @@ bool CreateDesktopShortcut(
return success;
}
+void DeleteDesktopShortcuts(const FilePath& profile_path,
+ const std::string& extension_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ FilePath shortcut_filename = GetExtensionShortcutFilename(
+ profile_path, extension_id);
+ DCHECK(!shortcut_filename.empty());
+
+ DeleteShortcutOnDesktop(shortcut_filename);
+ DeleteShortcutInApplicationsMenu(shortcut_filename);
+}
+
} // namespace ShellIntegrationLinux