| Index: chrome/browser/platform_util_linux.cc
|
| diff --git a/chrome/browser/platform_util_linux.cc b/chrome/browser/platform_util_linux.cc
|
| index 5fd8fbbb430393ec9ac2352cae4a9d1c44ae6056..340d8ab37425a12021289bdc34c7be106a1f9fa9 100644
|
| --- a/chrome/browser/platform_util_linux.cc
|
| +++ b/chrome/browser/platform_util_linux.cc
|
| @@ -5,10 +5,13 @@
|
| #include "chrome/browser/platform_util.h"
|
|
|
| #include "base/bind.h"
|
| +#include "base/command_line.h"
|
| #include "base/files/file_util.h"
|
| #include "base/process/kill.h"
|
| #include "base/process/launch.h"
|
| +#include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/version.h"
|
| #include "chrome/browser/platform_util_internal.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "url/gurl.h"
|
| @@ -19,11 +22,15 @@ namespace platform_util {
|
|
|
| namespace {
|
|
|
| -void XDGUtil(const std::string& util,
|
| - const base::FilePath& working_directory,
|
| - const std::string& arg) {
|
| +const char kNautilusKey[] = "nautilus.desktop";
|
| +const char kNautilusCmd[] = "nautilus";
|
| +const char kSupportedNautilusVersion[] = "3.0.2";
|
| +
|
| +void RunCommand(const std::string& command,
|
| + const base::FilePath& working_directory,
|
| + const std::string& arg) {
|
| std::vector<std::string> argv;
|
| - argv.push_back(util);
|
| + argv.push_back(command);
|
| argv.push_back(arg);
|
|
|
| base::LaunchOptions options;
|
| @@ -49,11 +56,76 @@ void XDGUtil(const std::string& util,
|
| }
|
|
|
| void XDGOpen(const base::FilePath& working_directory, const std::string& path) {
|
| - XDGUtil("xdg-open", working_directory, path);
|
| + RunCommand("xdg-open", working_directory, path);
|
| }
|
|
|
| void XDGEmail(const std::string& email) {
|
| - XDGUtil("xdg-email", base::FilePath(), email);
|
| + RunCommand("xdg-email", base::FilePath(), email);
|
| +}
|
| +
|
| +void ShowFileInNautilus(const base::FilePath& working_directory,
|
| + const std::string& path) {
|
| + RunCommand(kNautilusCmd, working_directory, path);
|
| +}
|
| +
|
| +std::string GetNautilusVersion() {
|
| + std::string output;
|
| + std::string found_version;
|
| +
|
| + base::CommandLine nautilus_cl((base::FilePath(kNautilusCmd)));
|
| + nautilus_cl.AppendArg("--version");
|
| +
|
| + if (base::GetAppOutputAndError(nautilus_cl, &output)) {
|
| + // It is assumed that "nautilus --version" returns something like
|
| + // "GNOME nautilus 3.14.2". First, find the position of the first char of
|
| + // "nautilus " and skip the whole string to get the position of
|
| + // version in the |output| string.
|
| + size_t nautilus_position = output.find("nautilus ");
|
| + size_t version_position = nautilus_position + strlen("nautilus ");
|
| + if (nautilus_position != std::string::npos) {
|
| + found_version = output.substr(version_position);
|
| + base::TrimWhitespaceASCII(found_version,
|
| + base::TRIM_TRAILING,
|
| + &found_version);
|
| + }
|
| + }
|
| + return found_version;
|
| +}
|
| +
|
| +bool CheckNautilusIsDefault() {
|
| + std::string file_browser;
|
| +
|
| + base::CommandLine xdg_mime(base::FilePath("xdg-mime"));
|
| + xdg_mime.AppendArg("query");
|
| + xdg_mime.AppendArg("default");
|
| + xdg_mime.AppendArg("inode/directory");
|
| +
|
| + bool success = base::GetAppOutputAndError(xdg_mime, &file_browser);
|
| + base::TrimWhitespaceASCII(file_browser,
|
| + base::TRIM_TRAILING,
|
| + &file_browser);
|
| +
|
| + if (!success || file_browser != kNautilusKey)
|
| + return false;
|
| +
|
| + const base::Version supported_version(kSupportedNautilusVersion);
|
| + DCHECK(supported_version.IsValid());
|
| + const base::Version current_version(GetNautilusVersion());
|
| + return current_version.IsValid() && current_version >= supported_version;
|
| +}
|
| +
|
| +void ShowItem(Profile* profile,
|
| + const base::FilePath& full_path,
|
| + bool use_nautilus_file_browser) {
|
| + if (use_nautilus_file_browser) {
|
| + OpenItem(profile, full_path, SHOW_ITEM_IN_FOLDER, OpenOperationCallback());
|
| + } else {
|
| + // TODO(estade): It would be nice to be able to select the file in other
|
| + // file managers, but that probably requires extending xdg-open.
|
| + // For now just show the folder for non-Nautilus users.
|
| + OpenItem(profile, full_path.DirName(), OPEN_FOLDER,
|
| + OpenOperationCallback());
|
| + }
|
| }
|
|
|
| } // namespace
|
| @@ -75,16 +147,20 @@ void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType type) {
|
| // time the application invoked by xdg-open inspects the path by name.
|
| XDGOpen(path, ".");
|
| break;
|
| + case SHOW_ITEM_IN_FOLDER:
|
| + ShowFileInNautilus(path.DirName(), path.value());
|
| + break;
|
| }
|
| }
|
| +
|
| } // namespace internal
|
|
|
| void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - // TODO(estade): It would be nice to be able to select the file in the file
|
| - // manager, but that probably requires extending xdg-open. For now just show
|
| - // the folder.
|
| - OpenItem(profile, full_path.DirName(), OPEN_FOLDER, OpenOperationCallback());
|
| + base::PostTaskAndReplyWithResult(content::BrowserThread::GetBlockingPool(),
|
| + FROM_HERE,
|
| + base::Bind(&CheckNautilusIsDefault),
|
| + base::Bind(&ShowItem, profile, full_path));
|
| }
|
|
|
| void OpenExternal(Profile* profile, const GURL& url) {
|
|
|