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

Side by Side Diff: chrome/browser/platform_util_linux.cc

Issue 352393002: Be explicit about target type in platform_util::OpenItem() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Catch up with changes to JSONStringValueSerializer and address CrOS comment Created 5 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/platform_util_internal.h ('k') | chrome/browser/platform_util_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/platform_util.h" 5 #include "chrome/browser/platform_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/process/kill.h" 9 #include "base/process/kill.h"
10 #include "base/process/launch.h" 10 #include "base/process/launch.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/platform_util_internal.h"
12 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 using content::BrowserThread; 16 using content::BrowserThread;
16 17
18 namespace platform_util {
19
17 namespace { 20 namespace {
18 21
19 void XDGUtil(const std::string& util, const std::string& arg) { 22 void XDGUtil(const std::string& util,
23 const base::FilePath& working_directory,
24 const std::string& arg) {
20 std::vector<std::string> argv; 25 std::vector<std::string> argv;
21 argv.push_back(util); 26 argv.push_back(util);
22 argv.push_back(arg); 27 argv.push_back(arg);
23 28
24 base::LaunchOptions options; 29 base::LaunchOptions options;
30 options.current_directory = working_directory;
25 options.allow_new_privs = true; 31 options.allow_new_privs = true;
26 // xdg-open can fall back on mailcap which eventually might plumb through 32 // xdg-open can fall back on mailcap which eventually might plumb through
27 // to a command that needs a terminal. Set the environment variable telling 33 // to a command that needs a terminal. Set the environment variable telling
28 // it that we definitely don't have a terminal available and that it should 34 // it that we definitely don't have a terminal available and that it should
29 // bring up a new terminal if necessary. See "man mailcap". 35 // bring up a new terminal if necessary. See "man mailcap".
30 options.environ["MM_NOTTTY"] = "1"; 36 options.environ["MM_NOTTTY"] = "1";
31 37
32 // In Google Chrome, we do not let GNOME's bug-buddy intercept our crashes. 38 // In Google Chrome, we do not let GNOME's bug-buddy intercept our crashes.
33 // However, we do not want this environment variable to propagate to external 39 // However, we do not want this environment variable to propagate to external
34 // applications. See http://crbug.com/24120 40 // applications. See http://crbug.com/24120
35 char* disable_gnome_bug_buddy = getenv("GNOME_DISABLE_CRASH_DIALOG"); 41 char* disable_gnome_bug_buddy = getenv("GNOME_DISABLE_CRASH_DIALOG");
36 if (disable_gnome_bug_buddy && 42 if (disable_gnome_bug_buddy &&
37 disable_gnome_bug_buddy == std::string("SET_BY_GOOGLE_CHROME")) 43 disable_gnome_bug_buddy == std::string("SET_BY_GOOGLE_CHROME"))
38 options.environ["GNOME_DISABLE_CRASH_DIALOG"] = std::string(); 44 options.environ["GNOME_DISABLE_CRASH_DIALOG"] = std::string();
39 45
40 base::Process process = base::LaunchProcess(argv, options); 46 base::Process process = base::LaunchProcess(argv, options);
41 if (process.IsValid()) 47 if (process.IsValid())
42 base::EnsureProcessGetsReaped(process.Pid()); 48 base::EnsureProcessGetsReaped(process.Pid());
43 } 49 }
44 50
45 void XDGOpen(const std::string& path) { 51 void XDGOpen(const base::FilePath& working_directory, const std::string& path) {
46 XDGUtil("xdg-open", path); 52 XDGUtil("xdg-open", working_directory, path);
47 } 53 }
48 54
49 void XDGEmail(const std::string& email) { 55 void XDGEmail(const std::string& email) {
50 XDGUtil("xdg-email", email); 56 XDGUtil("xdg-email", base::FilePath(), email);
51 }
52
53 // TODO(estade): It would be nice to be able to select the file in the file
54 // manager, but that probably requires extending xdg-open. For now just
55 // show the folder.
56 void ShowItemInFolderOnFileThread(const base::FilePath& full_path) {
57 base::FilePath dir = full_path.DirName();
58 if (!base::DirectoryExists(dir))
59 return;
60
61 XDGOpen(dir.value());
62 } 57 }
63 58
64 } // namespace 59 } // namespace
65 60
66 namespace platform_util { 61 namespace internal {
62
63 void PlatformOpenVerifiedItem(const base::FilePath& path, OpenItemType type) {
64 switch (type) {
65 case OPEN_FILE:
66 XDGOpen(path.DirName(), path.value());
67 break;
68 case OPEN_FOLDER:
69 // The utility process checks the working directory prior to the
70 // invocation of xdg-open by changing the current directory into it. This
71 // operation only succeeds if |path| is a directory. Opening "." from
72 // there ensures that the target of the operation is a directory. Note
73 // that there remains a TOCTOU race where the directory could be unlinked
74 // between the time the utility process changes into the directory and the
75 // time the application invoked by xdg-open inspects the path by name.
76 XDGOpen(path, ".");
77 break;
78 }
79 }
80 } // namespace internal
67 81
68 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) { 82 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
70 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 84 // TODO(estade): It would be nice to be able to select the file in the file
71 base::Bind(&ShowItemInFolderOnFileThread, full_path)); 85 // manager, but that probably requires extending xdg-open. For now just show
72 } 86 // the folder.
73 87 OpenItem(profile, full_path.DirName(), OPEN_FOLDER, OpenOperationCallback());
74 void OpenItem(Profile* profile, const base::FilePath& full_path) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
77 base::Bind(&XDGOpen, full_path.value()));
78 } 88 }
79 89
80 void OpenExternal(Profile* profile, const GURL& url) { 90 void OpenExternal(Profile* profile, const GURL& url) {
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
82 if (url.SchemeIs("mailto")) 92 if (url.SchemeIs("mailto"))
83 XDGEmail(url.spec()); 93 XDGEmail(url.spec());
84 else 94 else
85 XDGOpen(url.spec()); 95 XDGOpen(base::FilePath(), url.spec());
86 } 96 }
87 97
88 } // namespace platform_util 98 } // namespace platform_util
OLDNEW
« no previous file with comments | « chrome/browser/platform_util_internal.h ('k') | chrome/browser/platform_util_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698