Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <fcntl.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 close(devnull); | 60 close(devnull); |
| 61 return false; | 61 return false; |
| 62 } | 62 } |
| 63 close(devnull); | 63 close(devnull); |
| 64 | 64 |
| 65 int success_code; | 65 int success_code; |
| 66 base::WaitForExitCode(handle, &success_code); | 66 base::WaitForExitCode(handle, &success_code); |
| 67 return success_code == EXIT_SUCCESS; | 67 return success_code == EXIT_SUCCESS; |
| 68 } | 68 } |
| 69 | 69 |
| 70 static bool GetDefaultBrowser(std::string* result) { | 70 bool ShellIntegration::IsDefaultBrowser() { |
| 71 std::vector<std::string> argv; | |
| 72 argv.push_back("xdg-settings"); | |
| 73 argv.push_back("check"); | |
| 74 argv.push_back("default-web-browser"); | |
| 75 argv.push_back(GetDesktopName()); | |
| 76 | |
| 77 std::string reply; | |
| 78 if (!base::GetAppOutput(CommandLine(argv), &reply)) { | |
| 79 // If xdg-settings fails, we assume that we should pretend we're the default | |
| 80 // browser to avoid giving repeated prompts to set ourselves as the default. | |
| 81 // TODO(mdm): Really, being the default browser should be a ternary query: | |
| 82 // yes, no, and "don't know" so the UI can reflect this more accurately. | |
| 83 return true; | |
| 84 } | |
| 85 | |
| 86 // Allow any reply that starts with "yes" | |
|
Evan Stade
2009/07/22 01:36:33
. at end of comment
| |
| 87 return reply.find("yes") == 0; | |
| 88 } | |
| 89 | |
| 90 bool ShellIntegration::IsFirefoxDefaultBrowser() { | |
| 71 std::vector<std::string> argv; | 91 std::vector<std::string> argv; |
| 72 argv.push_back("xdg-settings"); | 92 argv.push_back("xdg-settings"); |
| 73 argv.push_back("get"); | 93 argv.push_back("get"); |
| 74 argv.push_back("default-web-browser"); | 94 argv.push_back("default-web-browser"); |
| 75 return base::GetAppOutput(CommandLine(argv), result); | |
| 76 } | |
| 77 | 95 |
| 78 bool ShellIntegration::IsDefaultBrowser() { | |
| 79 std::string browser; | |
| 80 if (!GetDefaultBrowser(&browser)) { | |
| 81 // If GetDefaultBrowser() fails, we assume xdg-settings does not work for | |
| 82 // some reason, and that we should pretend we're the default browser to | |
| 83 // avoid giving repeated prompts to set ourselves as the default browser. | |
| 84 // TODO: Really, being the default browser should be a ternary query: yes, | |
| 85 // no, and "don't know" so that the UI can reflect this more accurately. | |
| 86 return true; | |
| 87 } | |
| 88 // Allow for an optional newline at the end. | |
| 89 if (browser.length() > 0 && browser[browser.length() - 1] == '\n') | |
| 90 browser.resize(browser.length() - 1); | |
| 91 return !browser.compare(GetDesktopName()); | |
| 92 } | |
| 93 | |
| 94 bool ShellIntegration::IsFirefoxDefaultBrowser() { | |
| 95 std::string browser; | 96 std::string browser; |
| 96 // We don't care about the return value here. | 97 // We don't care about the return value here. |
| 97 GetDefaultBrowser(&browser); | 98 base::GetAppOutput(CommandLine(argv), &browser); |
| 98 return browser.find("irefox") != std::string::npos; | 99 return browser.find("irefox") != std::string::npos; |
| 99 } | 100 } |
| OLD | NEW |