OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/shell_integration.h" |
| 6 |
| 7 #include <stdlib.h> |
| 8 |
| 9 #include <vector> |
| 10 |
| 11 #include "base/process_util.h" |
| 12 |
| 13 #if defined(GOOGLE_CHROME_BUILD) |
| 14 #define DESKTOP_APP_NAME "google-chrome.desktop" |
| 15 #else // CHROMIUM_BUILD |
| 16 #define DESKTOP_APP_NAME "chromium-browser.desktop" |
| 17 #endif |
| 18 |
| 19 // 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 |
| 21 // of it for this to work, obviously, but that's actually the suggested approach |
| 22 // for xdg utilities anyway. |
| 23 |
| 24 bool ShellIntegration::SetAsDefaultBrowser() { |
| 25 std::vector<std::string> argv; |
| 26 argv.push_back("xdg-settings"); |
| 27 argv.push_back("set"); |
| 28 argv.push_back("default-web-browser"); |
| 29 argv.push_back(DESKTOP_APP_NAME); |
| 30 |
| 31 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); |
| 38 return success_code == EXIT_SUCCESS; |
| 39 } |
| 40 |
| 41 static std::string getDefaultBrowser() { |
| 42 std::vector<std::string> argv; |
| 43 argv.push_back("xdg-settings"); |
| 44 argv.push_back("get"); |
| 45 argv.push_back("default-web-browser"); |
| 46 std::string output; |
| 47 base::GetAppOutput(CommandLine(argv), &output); |
| 48 // If GetAppOutput() fails, we'll return the empty string. |
| 49 return output; |
| 50 } |
| 51 |
| 52 bool ShellIntegration::IsDefaultBrowser() { |
| 53 std::string browser = getDefaultBrowser(); |
| 54 // Allow for an optional newline at the end. |
| 55 if (browser.length() > 0 && browser[browser.length() - 1] == '\n') |
| 56 browser.resize(browser.length() - 1); |
| 57 if (!browser.length()) { |
| 58 // We don't know what the default browser is; chances are, we can't |
| 59 // set it either. So, check to see if we were run in the wrapper |
| 60 // and pretend that we are the default unless we were run from it, |
| 61 // to avoid warning that we aren't the default when it's useless. |
| 62 return !getenv("CHROME_WRAPPER"); |
| 63 } |
| 64 return !browser.compare(DESKTOP_APP_NAME); |
| 65 } |
| 66 |
| 67 bool ShellIntegration::IsFirefoxDefaultBrowser() { |
| 68 return getDefaultBrowser().find("irefox") != std::string::npos; |
| 69 } |
OLD | NEW |