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

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

Issue 155796: Make standard input /dev/null when running xdg-settings to set the default browser. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | « no previous file | no next file » | 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include <fcntl.h>
7 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <sys/stat.h>
10 #include <sys/types.h>
11 #include <unistd.h>
8 12
9 #include <vector> 13 #include <vector>
10 14
11 #include "base/process_util.h" 15 #include "base/process_util.h"
12 16
13 #if defined(GOOGLE_CHROME_BUILD) 17 #if defined(GOOGLE_CHROME_BUILD)
14 #define DESKTOP_APP_NAME "google-chrome.desktop" 18 #define DESKTOP_APP_NAME "google-chrome.desktop"
15 #else // CHROMIUM_BUILD 19 #else // CHROMIUM_BUILD
16 #define DESKTOP_APP_NAME "chromium-browser.desktop" 20 #define DESKTOP_APP_NAME "chromium-browser.desktop"
17 #endif 21 #endif
18 22
19 // We delegate the difficult of setting the default browser in Linux desktop 23 // We delegate the difficult of setting the default browser in Linux desktop
20 // environments to a new xdg utility, xdg-settings. We'll have to include a copy 24 // environments to a new xdg utility, xdg-settings. We'll have to include a copy
21 // of it for this to work, obviously, but that's actually the suggested approach 25 // of it for this to work, obviously, but that's actually the suggested approach
22 // for xdg utilities anyway. 26 // for xdg utilities anyway.
23 27
24 bool ShellIntegration::SetAsDefaultBrowser() { 28 bool ShellIntegration::SetAsDefaultBrowser() {
25 std::vector<std::string> argv; 29 std::vector<std::string> argv;
26 argv.push_back("xdg-settings"); 30 argv.push_back("xdg-settings");
27 argv.push_back("set"); 31 argv.push_back("set");
28 argv.push_back("default-web-browser"); 32 argv.push_back("default-web-browser");
29 argv.push_back(DESKTOP_APP_NAME); 33 argv.push_back(DESKTOP_APP_NAME);
30 34
35 // xdg-settings internally runs xdg-mime, which uses mv to move newly-created
36 // files on top of originals after making changes to them. In the event that
37 // the original files are owned by another user (e.g. root, which can happen
38 // if they are updated within sudo), mv will prompt the user to confirm if
39 // standard input is a terminal (otherwise it just does it). So make sure it's
40 // not, to avoid locking everything up waiting for mv.
41 int devnull = open("/dev/null", O_RDONLY);
42 if (devnull < 0)
43 return false;
44 base::file_handle_mapping_vector no_stdin;
45 no_stdin.push_back(std::make_pair(devnull, STDIN_FILENO));
46
47 base::ProcessHandle handle;
48 if (!base::LaunchApp(argv, no_stdin, false, &handle)) {
49 close(devnull);
50 return false;
51 }
52 close(devnull);
53
31 int success_code; 54 int success_code;
32 base::ProcessHandle handle;
33 base::file_handle_mapping_vector no_files;
34 if (!base::LaunchApp(argv, no_files, false, &handle))
35 return false;
36
37 base::WaitForExitCode(handle, &success_code); 55 base::WaitForExitCode(handle, &success_code);
38 return success_code == EXIT_SUCCESS; 56 return success_code == EXIT_SUCCESS;
39 } 57 }
40 58
41 static bool GetDefaultBrowser(std::string* result) { 59 static bool GetDefaultBrowser(std::string* result) {
42 std::vector<std::string> argv; 60 std::vector<std::string> argv;
43 argv.push_back("xdg-settings"); 61 argv.push_back("xdg-settings");
44 argv.push_back("get"); 62 argv.push_back("get");
45 argv.push_back("default-web-browser"); 63 argv.push_back("default-web-browser");
46 return base::GetAppOutput(CommandLine(argv), result); 64 return base::GetAppOutput(CommandLine(argv), result);
(...skipping 14 matching lines...) Expand all
61 browser.resize(browser.length() - 1); 79 browser.resize(browser.length() - 1);
62 return !browser.compare(DESKTOP_APP_NAME); 80 return !browser.compare(DESKTOP_APP_NAME);
63 } 81 }
64 82
65 bool ShellIntegration::IsFirefoxDefaultBrowser() { 83 bool ShellIntegration::IsFirefoxDefaultBrowser() {
66 std::string browser; 84 std::string browser;
67 // We don't care about the return value here. 85 // We don't care about the return value here.
68 GetDefaultBrowser(&browser); 86 GetDefaultBrowser(&browser);
69 return browser.find("irefox") != std::string::npos; 87 return browser.find("irefox") != std::string::npos;
70 } 88 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698