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

Unified Diff: chrome/browser/platform_util_linux.cc

Issue 1867533002: (TOBEDELETED)Select downloaded file in the folder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Lel Zhang comments Created 4 years, 8 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
« no previous file with comments | « chrome/browser/platform_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..81dadbf5d12cb6607a9a98ac8d78cff632838908 100644
--- a/chrome/browser/platform_util_linux.cc
+++ b/chrome/browser/platform_util_linux.cc
@@ -5,10 +5,12 @@
#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/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"
@@ -56,6 +58,68 @@ void XDGEmail(const std::string& email) {
XDGUtil("xdg-email", base::FilePath(), email);
}
+const char kNautilusKey[] = "nautilus.desktop";
+const char kNautilusCmd[] = "nautilus";
+const char kSupportedNautilusVersion[] = "3.0.2";
+
+void ShowFileInNautilus(const base::FilePath& working_directory,
+ const std::string& path) {
+ XDGUtil(kNautilusCmd, working_directory, path);
Lei Zhang 2016/04/20 20:45:57 XDGUtil() should be renamed since it's not just la
+}
+
+std::string GetNautilusVersion() {
+ std::string output;
+ std::string found_version;
+
+ base::CommandLine nautilus_cl((base::FilePath(kNautilusCmd)));
+ nautilus_cl.AppendArg("--version");
Lei Zhang 2016/04/20 20:45:57 nit: indentation
+
+ if (base::GetAppOutputAndError(nautilus_cl, &output)) {
+ const std::size_t version_position = output.find(kNautilusCmd) +
Lei Zhang 2016/04/20 20:45:57 Shouldn't you check the output.find() result befor
+ std::strlen(kNautilusCmd) + 1;
+ found_version = output.substr(version_position);
+
+ if (!found_version.empty() &&
+ (found_version[found_version.length() - 1]) == '\n') {
Lei Zhang 2016/04/20 20:45:57 Why do you need the parenthesis around foo[bar] ?
+ found_version.erase(found_version.length()-1);
+ }
+ }
+
+ return found_version;
+}
+
+std::string CheckNautilusIsDefault() {
Lei Zhang 2016/04/20 20:45:57 Why not just return a bool?
+ const base::Version supported_version(kSupportedNautilusVersion);
+ std::string file_browser;
+
+ base::CommandLine xdg_mime(base::FilePath("xdg-mime"));
+ xdg_mime.AppendArg("query");
Lei Zhang 2016/04/20 20:45:57 Also indentation. If you are not familiar with Chr
+ xdg_mime.AppendArg("default");
+ xdg_mime.AppendArg("inode/directory");
+
+ if (base::GetAppOutputAndError(xdg_mime, &file_browser)) {
+ if (file_browser.find(kNautilusKey) != std::string::npos) {
+ base::Version current_version(GetNautilusVersion());
+ if ((current_version.IsValid() && supported_version.IsValid()) &&
+ (current_version >= supported_version)) {
+ file_browser = kNautilusKey;
+ return file_browser;
+ }
+ }
+ }
+ return file_browser;
+}
+
+void ShowItem(Profile* profile, const base::FilePath& full_path,
+ const std::string& file_browser) {
+ if (file_browser == kNautilusKey) {
+ OpenItem(profile, full_path, SHOW_ITEM_IN_FOLDER, OpenOperationCallback());
+ } else {
+ OpenItem(profile, full_path.DirName(), OPEN_FOLDER,
Lei Zhang 2016/04/20 20:45:57 The TODO from estade still applies, for non-Nautil
+ OpenOperationCallback());
+ }
+}
+
} // namespace
namespace internal {
@@ -75,16 +139,21 @@ 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) {
« no previous file with comments | « chrome/browser/platform_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698