Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2570)

Unified Diff: chrome/browser/shell_integration_linux.cc

Issue 10698114: Remove app shortcuts when app is uninstalled on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/shell_integration_linux.cc
diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc
index 840f0569c83dbc32ce7f405b5f75687604fd271a..ea05095b793ee2aac3f6ef78dc0e199dd9c30c5c 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

Powered by Google App Engine
This is Rietveld 408576698