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 = {
"unix": {
# Linux, really.
"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() {
return success_code == EXIT_SUCCESS;
}
static bool GetDefaultBrowser(std::string* result) {
bool ShellIntegration::IsDefaultBrowser() {
std::vector<std::string> argv;
argv.push_back("xdg-settings");
argv.push_back("get");
argv.push_back("check");
argv.push_back("default-web-browser");
return base::GetAppOutput(CommandLine(argv), result);
}
argv.push_back(GetDesktopName());
bool ShellIntegration::IsDefaultBrowser() {
std::string browser;
if (!GetDefaultBrowser(&browser)) {
// If GetDefaultBrowser() fails, we assume xdg-settings does not work for
// some reason, and that we should pretend we're the default browser to
// avoid giving repeated prompts to set ourselves as the default browser.
// 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.
std::string reply;
if (!base::GetAppOutput(CommandLine(argv), &reply)) {
// If xdg-settings fails, we assume that we should pretend we're the default
// browser to avoid giving repeated prompts to set ourselves as the default.
// TODO(mdm): Really, being the default browser should be a ternary query:
// yes, no, and "don't know" so the UI can reflect this more accurately.
return true;
}
// Allow for an optional newline at the end.
if (browser.length() > 0 && browser[browser.length() - 1] == '\n')
browser.resize(browser.length() - 1);
return !browser.compare(GetDesktopName());
// Allow any reply that starts with "yes".
return reply.find("yes") == 0;
}
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;
// We don't care about the return value here.
GetDefaultBrowser(&browser);
base::GetAppOutput(CommandLine(argv), &browser);
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