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
3 // found in the LICENSE file.
5 #include "chrome/browser/platform_util.h"
8 #include "base/file_util.h"
9 #include "base/process/kill.h"
10 #include "base/process/launch.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "content/public/browser/browser_thread.h"
15 using content::BrowserThread
;
19 void XDGUtil(const std::string
& util
, const std::string
& arg
) {
20 std::vector
<std::string
> argv
;
24 base::LaunchOptions options
;
25 // xdg-open can fall back on mailcap which eventually might plumb through
26 // to a command that needs a terminal. Set the environment variable telling
27 // it that we definitely don't have a terminal available and that it should
28 // bring up a new terminal if necessary. See "man mailcap".
29 options
.environ
["MM_NOTTTY"] = "1";
31 // In Google Chrome, we do not let GNOME's bug-buddy intercept our crashes.
32 // However, we do not want this environment variable to propagate to external
33 // applications. See http://crbug.com/24120
34 char* disable_gnome_bug_buddy
= getenv("GNOME_DISABLE_CRASH_DIALOG");
35 if (disable_gnome_bug_buddy
&&
36 disable_gnome_bug_buddy
== std::string("SET_BY_GOOGLE_CHROME"))
37 options
.environ
["GNOME_DISABLE_CRASH_DIALOG"] = std::string();
39 base::ProcessHandle handle
;
40 if (base::LaunchProcess(argv
, options
, &handle
))
41 base::EnsureProcessGetsReaped(handle
);
44 void XDGOpen(const std::string
& path
) {
45 XDGUtil("xdg-open", path
);
48 void XDGEmail(const std::string
& email
) {
49 XDGUtil("xdg-email", email
);
52 // TODO(estade): It would be nice to be able to select the file in the file
53 // manager, but that probably requires extending xdg-open. For now just
55 void ShowItemInFolderOnFileThread(const base::FilePath
& full_path
) {
56 base::FilePath dir
= full_path
.DirName();
57 if (!base::DirectoryExists(dir
))
65 namespace platform_util
{
67 void ShowItemInFolder(Profile
* profile
, const base::FilePath
& full_path
) {
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
69 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE
,
70 base::Bind(&ShowItemInFolderOnFileThread
, full_path
));
73 void OpenItem(Profile
* profile
, const base::FilePath
& full_path
) {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
75 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE
,
76 base::Bind(&XDGOpen
, full_path
.value()));
79 void OpenExternal(Profile
* profile
, const GURL
& url
) {
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
81 if (url
.SchemeIs("mailto"))
87 } // namespace platform_util