Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/shell_integration_linux.h" | 5 #include "chrome/browser/shell_integration_linux.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <glib.h> | 8 #include <glib.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 return "chromium-browser.desktop"; | 456 return "chromium-browser.desktop"; |
| 457 #endif | 457 #endif |
| 458 } | 458 } |
| 459 | 459 |
| 460 bool GetDesktopShortcutTemplate(base::Environment* env, | 460 bool GetDesktopShortcutTemplate(base::Environment* env, |
| 461 std::string* output) { | 461 std::string* output) { |
| 462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 463 | 463 |
| 464 std::vector<base::FilePath> search_paths; | 464 std::vector<base::FilePath> search_paths; |
| 465 | 465 |
| 466 // Search paths as specified in the XDG Base Directory Specification. | |
|
benwells
2013/03/04 03:58:26
Could you put a link to the spec?
Matt Giuca
2013/03/04 04:18:26
Done.
| |
| 466 std::string xdg_data_home; | 467 std::string xdg_data_home; |
| 468 std::string home; | |
| 467 if (env->GetVar("XDG_DATA_HOME", &xdg_data_home) && | 469 if (env->GetVar("XDG_DATA_HOME", &xdg_data_home) && |
| 468 !xdg_data_home.empty()) { | 470 !xdg_data_home.empty()) { |
| 469 search_paths.push_back(base::FilePath(xdg_data_home)); | 471 search_paths.push_back(base::FilePath(xdg_data_home)); |
| 472 } else if (env->GetVar("HOME", &home) && !home.empty()) { | |
| 473 search_paths.push_back(base::FilePath(home).Append(".local").Append( | |
| 474 "share")); | |
| 470 } | 475 } |
| 471 | 476 |
| 472 std::string xdg_data_dirs; | 477 std::string xdg_data_dirs; |
| 473 if (env->GetVar("XDG_DATA_DIRS", &xdg_data_dirs) && | 478 if (env->GetVar("XDG_DATA_DIRS", &xdg_data_dirs) && |
| 474 !xdg_data_dirs.empty()) { | 479 !xdg_data_dirs.empty()) { |
| 475 base::StringTokenizer tokenizer(xdg_data_dirs, ":"); | 480 base::StringTokenizer tokenizer(xdg_data_dirs, ":"); |
| 476 while (tokenizer.GetNext()) { | 481 while (tokenizer.GetNext()) { |
| 477 base::FilePath data_dir(tokenizer.token()); | 482 base::FilePath data_dir(tokenizer.token()); |
| 478 search_paths.push_back(data_dir); | 483 search_paths.push_back(data_dir); |
| 479 search_paths.push_back(data_dir.Append("applications")); | |
| 480 } | 484 } |
| 485 } else { | |
| 486 search_paths.push_back(base::FilePath("/usr/share")); | |
| 487 search_paths.push_back(base::FilePath("/usr/local/share")); | |
| 481 } | 488 } |
| 482 | 489 |
| 483 // Add some fallback paths for systems which don't have XDG_DATA_DIRS or have | |
| 484 // it incomplete. | |
| 485 search_paths.push_back(base::FilePath("/usr/share/applications")); | |
| 486 search_paths.push_back(base::FilePath("/usr/local/share/applications")); | |
| 487 | |
| 488 std::string template_filename(GetDesktopName(env)); | 490 std::string template_filename(GetDesktopName(env)); |
| 489 for (std::vector<base::FilePath>::const_iterator i = search_paths.begin(); | 491 for (std::vector<base::FilePath>::const_iterator i = search_paths.begin(); |
| 490 i != search_paths.end(); ++i) { | 492 i != search_paths.end(); ++i) { |
| 491 base::FilePath path = i->Append(template_filename); | 493 base::FilePath path = i->Append("applications").Append(template_filename); |
| 492 VLOG(1) << "Looking for desktop file template in " << path.value(); | 494 VLOG(1) << "Looking for desktop file template in " << path.value(); |
| 493 if (file_util::PathExists(path)) { | 495 if (file_util::PathExists(path)) { |
| 494 VLOG(1) << "Found desktop file template at " << path.value(); | 496 VLOG(1) << "Found desktop file template at " << path.value(); |
| 495 return file_util::ReadFileToString(path, output); | 497 return file_util::ReadFileToString(path, output); |
| 496 } | 498 } |
| 497 } | 499 } |
| 498 | 500 |
| 499 LOG(ERROR) << "Could not find desktop file template."; | 501 LOG(ERROR) << "Could not find desktop file template."; |
| 500 return false; | 502 return false; |
| 501 } | 503 } |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 | 727 |
| 726 base::FilePath shortcut_filename = GetExtensionShortcutFilename( | 728 base::FilePath shortcut_filename = GetExtensionShortcutFilename( |
| 727 profile_path, extension_id); | 729 profile_path, extension_id); |
| 728 DCHECK(!shortcut_filename.empty()); | 730 DCHECK(!shortcut_filename.empty()); |
| 729 | 731 |
| 730 DeleteShortcutOnDesktop(shortcut_filename); | 732 DeleteShortcutOnDesktop(shortcut_filename); |
| 731 DeleteShortcutInApplicationsMenu(shortcut_filename); | 733 DeleteShortcutInApplicationsMenu(shortcut_filename); |
| 732 } | 734 } |
| 733 | 735 |
| 734 } // namespace ShellIntegrationLinux | 736 } // namespace ShellIntegrationLinux |
| OLD | NEW |