summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authormgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-06 04:12:36 +0000
committermgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-06 04:12:36 +0000
commit58bf9256cac6bbc0bece01cfaf966893bfa0c5b6 (patch)
tree12790826e5a9c309f0362a1dd6ab1a2c1c0f009b /chrome/browser
parent76f269e5bf439557c731aa89ce27c9b858df11a1 (diff)
downloadchromium_src-58bf9256cac6bbc0bece01cfaf966893bfa0c5b6.zip
chromium_src-58bf9256cac6bbc0bece01cfaf966893bfa0c5b6.tar.gz
chromium_src-58bf9256cac6bbc0bece01cfaf966893bfa0c5b6.tar.bz2
shell_integration_linux: Follow the XDG Base Directory Specification.
GetDesktopShortcutTemplate now: - Searches $XDG_DATA_HOME/applications instead of $XDG_DATA_HOME. - If $XDG_DATA_HOME is not found, falls back to $HOME/.local/share/applications. - No longer searches $XDG_DATA_DIRS (without /applications). - Only searches /usr/local/share/applications and /usr/share/applications if $XDG_DATA_DIRS is not found. - Searches /usr/local/share/applications before /usr/share/applications. BUG=179751 Review URL: https://chromiumcodereview.appspot.com/12386077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/shell_integration_linux.cc17
-rw-r--r--chrome/browser/shell_integration_unittest.cc51
2 files changed, 52 insertions, 16 deletions
diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc
index e7412ae..d8f7d7b 100644
--- a/chrome/browser/shell_integration_linux.cc
+++ b/chrome/browser/shell_integration_linux.cc
@@ -463,10 +463,16 @@ bool GetDesktopShortcutTemplate(base::Environment* env,
std::vector<base::FilePath> search_paths;
+ // Search paths as specified in the XDG Base Directory Specification.
+ // http://standards.freedesktop.org/basedir-spec/latest/
std::string xdg_data_home;
+ std::string home;
if (env->GetVar("XDG_DATA_HOME", &xdg_data_home) &&
!xdg_data_home.empty()) {
search_paths.push_back(base::FilePath(xdg_data_home));
+ } else if (env->GetVar("HOME", &home) && !home.empty()) {
+ search_paths.push_back(base::FilePath(home).Append(".local").Append(
+ "share"));
}
std::string xdg_data_dirs;
@@ -476,19 +482,16 @@ bool GetDesktopShortcutTemplate(base::Environment* env,
while (tokenizer.GetNext()) {
base::FilePath data_dir(tokenizer.token());
search_paths.push_back(data_dir);
- search_paths.push_back(data_dir.Append("applications"));
}
+ } else {
+ search_paths.push_back(base::FilePath("/usr/local/share"));
+ search_paths.push_back(base::FilePath("/usr/share"));
}
- // Add some fallback paths for systems which don't have XDG_DATA_DIRS or have
- // it incomplete.
- search_paths.push_back(base::FilePath("/usr/share/applications"));
- search_paths.push_back(base::FilePath("/usr/local/share/applications"));
-
std::string template_filename(GetDesktopName(env));
for (std::vector<base::FilePath>::const_iterator i = search_paths.begin();
i != search_paths.end(); ++i) {
- base::FilePath path = i->Append(template_filename);
+ base::FilePath path = i->Append("applications").Append(template_filename);
VLOG(1) << "Looking for desktop file template in " << path.value();
if (file_util::PathExists(path)) {
VLOG(1) << "Found desktop file template at " << path.value();
diff --git a/chrome/browser/shell_integration_unittest.cc b/chrome/browser/shell_integration_unittest.cc
index 39ca70a..186e14f 100644
--- a/chrome/browser/shell_integration_unittest.cc
+++ b/chrome/browser/shell_integration_unittest.cc
@@ -119,14 +119,41 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
MessageLoop message_loop;
content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
+ // Test that it searches $XDG_DATA_HOME/applications.
{
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
MockEnvironment env;
env.Set("XDG_DATA_HOME", temp_dir.path().value());
+ // Create a file in a non-applications directory. This should be ignored.
ASSERT_TRUE(file_util::WriteFile(
temp_dir.path().AppendASCII(kTemplateFilename),
+ kTestData2, strlen(kTestData2)));
+ ASSERT_TRUE(file_util::CreateDirectory(
+ temp_dir.path().AppendASCII("applications")));
+ ASSERT_TRUE(file_util::WriteFile(
+ temp_dir.path().AppendASCII("applications")
+ .AppendASCII(kTemplateFilename),
+ kTestData1, strlen(kTestData1)));
+ std::string contents;
+ ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
+ &contents));
+ EXPECT_EQ(kTestData1, contents);
+ }
+
+ // Test that it falls back to $HOME/.local/share/applications.
+ {
+ base::ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+
+ MockEnvironment env;
+ env.Set("HOME", temp_dir.path().value());
+ ASSERT_TRUE(file_util::CreateDirectory(
+ temp_dir.path().AppendASCII(".local/share/applications")));
+ ASSERT_TRUE(file_util::WriteFile(
+ temp_dir.path().AppendASCII(".local/share/applications")
+ .AppendASCII(kTemplateFilename),
kTestData1, strlen(kTestData1)));
std::string contents;
ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
@@ -134,6 +161,7 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
EXPECT_EQ(kTestData1, contents);
}
+ // Test that it searches $XDG_DATA_DIRS/applications.
{
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
@@ -152,26 +180,31 @@ TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
EXPECT_EQ(kTestData2, contents);
}
+ // Test that it searches $X/applications for each X in $XDG_DATA_DIRS.
{
- base::ScopedTempDir temp_dir;
- ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ base::ScopedTempDir temp_dir1;
+ ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
+ base::ScopedTempDir temp_dir2;
+ ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
MockEnvironment env;
- env.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" +
- temp_dir.path().AppendASCII("applications").value());
- ASSERT_TRUE(file_util::CreateDirectory(
- temp_dir.path().AppendASCII("applications")));
+ env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" +
+ temp_dir2.path().value());
+ // Create a file in a non-applications directory. This should be ignored.
ASSERT_TRUE(file_util::WriteFile(
- temp_dir.path().AppendASCII(kTemplateFilename),
+ temp_dir1.path().AppendASCII(kTemplateFilename),
kTestData1, strlen(kTestData1)));
+ // Only create a findable desktop file in the second path.
+ ASSERT_TRUE(file_util::CreateDirectory(
+ temp_dir2.path().AppendASCII("applications")));
ASSERT_TRUE(file_util::WriteFile(
- temp_dir.path().AppendASCII("applications")
+ temp_dir2.path().AppendASCII("applications")
.AppendASCII(kTemplateFilename),
kTestData2, strlen(kTestData2)));
std::string contents;
ASSERT_TRUE(ShellIntegrationLinux::GetDesktopShortcutTemplate(&env,
&contents));
- EXPECT_EQ(kTestData1, contents);
+ EXPECT_EQ(kTestData2, contents);
}
}