Skip to content
Snippets Groups Projects
Commit 7061b12b authored by mdm@chromium.org's avatar mdm@chromium.org
Browse files

Linux: use new xdg-settings "check" feature to determine whether we are the default browser.

BUG=17093
TEST=in GNOME, let Firefox set itself as the default after Chrome has set itself; Chrome should then detect that it is no longer the default

Review URL: http://codereview.chromium.org/155889

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21260 0039d316-1c4b-4281-b951-d872f2087c98
parent 603c389a
No related merge requests found
...@@ -92,7 +92,7 @@ deps_os = { ...@@ -92,7 +92,7 @@ deps_os = {
"unix": { "unix": {
# Linux, really. # Linux, really.
"src/third_party/xdg-utils": "src/third_party/xdg-utils":
"/trunk/deps/third_party/xdg-utils@20073", "/trunk/deps/third_party/xdg-utils@21243",
}, },
} }
......
...@@ -67,33 +67,34 @@ bool ShellIntegration::SetAsDefaultBrowser() { ...@@ -67,33 +67,34 @@ bool ShellIntegration::SetAsDefaultBrowser() {
return success_code == EXIT_SUCCESS; return success_code == EXIT_SUCCESS;
} }
static bool GetDefaultBrowser(std::string* result) { bool ShellIntegration::IsDefaultBrowser() {
std::vector<std::string> argv; std::vector<std::string> argv;
argv.push_back("xdg-settings"); argv.push_back("xdg-settings");
argv.push_back("get"); argv.push_back("check");
argv.push_back("default-web-browser"); argv.push_back("default-web-browser");
return base::GetAppOutput(CommandLine(argv), result); argv.push_back(GetDesktopName());
}
bool ShellIntegration::IsDefaultBrowser() { std::string reply;
std::string browser; if (!base::GetAppOutput(CommandLine(argv), &reply)) {
if (!GetDefaultBrowser(&browser)) { // If xdg-settings fails, we assume that we should pretend we're the default
// If GetDefaultBrowser() fails, we assume xdg-settings does not work for // browser to avoid giving repeated prompts to set ourselves as the default.
// some reason, and that we should pretend we're the default browser to // TODO(mdm): Really, being the default browser should be a ternary query:
// avoid giving repeated prompts to set ourselves as the default browser. // yes, no, and "don't know" so the UI can reflect this more accurately.
// TODO: Really, being the default browser should be a ternary query: yes,
// no, and "don't know" so that the UI can reflect this more accurately.
return true; return true;
} }
// Allow for an optional newline at the end.
if (browser.length() > 0 && browser[browser.length() - 1] == '\n') // Allow any reply that starts with "yes".
browser.resize(browser.length() - 1); return reply.find("yes") == 0;
return !browser.compare(GetDesktopName());
} }
bool ShellIntegration::IsFirefoxDefaultBrowser() { bool ShellIntegration::IsFirefoxDefaultBrowser() {
std::vector<std::string> argv;
argv.push_back("xdg-settings");
argv.push_back("get");
argv.push_back("default-web-browser");
std::string browser; std::string browser;
// We don't care about the return value here. // We don't care about the return value here.
GetDefaultBrowser(&browser); base::GetAppOutput(CommandLine(argv), &browser);
return browser.find("irefox") != std::string::npos; return browser.find("irefox") != std::string::npos;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment