Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / platform_util_linux.cc
blob5fd8fbbb430393ec9ac2352cae4a9d1c44ae6056
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"
7 #include "base/bind.h"
8 #include "base/files/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 "chrome/browser/platform_util_internal.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "url/gurl.h"
16 using content::BrowserThread;
18 namespace platform_util {
20 namespace {
22 void XDGUtil(const std::string& util,
23 const base::FilePath& working_directory,
24 const std::string& arg) {
25 std::vector<std::string> argv;
26 argv.push_back(util);
27 argv.push_back(arg);
29 base::LaunchOptions options;
30 options.current_directory = working_directory;
31 options.allow_new_privs = true;
32 // xdg-open can fall back on mailcap which eventually might plumb through
33 // to a command that needs a terminal. Set the environment variable telling
34 // it that we definitely don't have a terminal available and that it should
35 // bring up a new terminal if necessary. See "man mailcap".
36 options.environ["MM_NOTTTY"] = "1";
38 // In Google Chrome, we do not let GNOME's bug-buddy intercept our crashes.
39 // However, we do not want this environment variable to propagate to external
40 // applications. See http://crbug.com/24120
41 char* disable_gnome_bug_buddy = getenv("GNOME_DISABLE_CRASH_DIALOG");
42 if (disable_gnome_bug_buddy &&
43 disable_gnome_bug_buddy == std::string("SET_BY_GOOGLE_CHROME"))
44 options.environ["GNOME_DISABLE_CRASH_DIALOG"] = std::string();
46 base::Process process = base::LaunchProcess(argv, options);
47 if (process.IsValid())
48 base::EnsureProcessGetsReaped(process.Pid());
51 void XDGOpen(const base::FilePath& working_directory, const std::string& path) {
52 XDGUtil("xdg-open", working_directory, path);
55 void XDGEmail(const std::string& email) {
56 XDGUtil("xdg-email", base::FilePath(), email);
59 } // namespace
61 namespace internal {
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;
80 } // namespace internal
82 void ShowItemInFolder(Profile* profile, const base::FilePath& full_path) {
83 DCHECK_CURRENTLY_ON(BrowserThread::UI);
84 // TODO(estade): It would be nice to be able to select the file in the file
85 // manager, but that probably requires extending xdg-open. For now just show
86 // the folder.
87 OpenItem(profile, full_path.DirName(), OPEN_FOLDER, OpenOperationCallback());
90 void OpenExternal(Profile* profile, const GURL& url) {
91 DCHECK_CURRENTLY_ON(BrowserThread::UI);
92 if (url.SchemeIs("mailto"))
93 XDGEmail(url.spec());
94 else
95 XDGOpen(base::FilePath(), url.spec());
98 } // namespace platform_util