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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 | 173 |
| 174 bool ShellIntegration::SetAsDefaultBrowser() { | 174 bool ShellIntegration::SetAsDefaultBrowser() { |
| 175 std::vector<std::string> argv; | 175 std::vector<std::string> argv; |
| 176 argv.push_back("xdg-settings"); | 176 argv.push_back("xdg-settings"); |
| 177 argv.push_back("set"); | 177 argv.push_back("set"); |
| 178 argv.push_back("default-web-browser"); | 178 argv.push_back("default-web-browser"); |
| 179 argv.push_back(GetDesktopName()); | 179 argv.push_back(GetDesktopName()); |
| 180 return LaunchXdgUtility(argv); | 180 return LaunchXdgUtility(argv); |
| 181 } | 181 } |
| 182 | 182 |
| 183 bool ShellIntegration::IsDefaultBrowser() { | 183 ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { |
| 184 std::vector<std::string> argv; | 184 std::vector<std::string> argv; |
| 185 argv.push_back("xdg-settings"); | 185 argv.push_back("xdg-settings"); |
| 186 argv.push_back("check"); | 186 argv.push_back("check"); |
| 187 argv.push_back("default-web-browser"); | 187 argv.push_back("default-web-browser"); |
| 188 argv.push_back(GetDesktopName()); | 188 argv.push_back(GetDesktopName()); |
| 189 | 189 |
| 190 std::string reply; | 190 std::string reply; |
| 191 if (!base::GetAppOutput(CommandLine(argv), &reply)) { | 191 if (!base::GetAppOutput(CommandLine(argv), &reply)) { |
| 192 // If xdg-settings fails, we assume that we should pretend we're the default | 192 // xdg-settings failed: we can't determine or set the default browser. |
| 193 // browser to avoid giving repeated prompts to set ourselves as the default. | 193 return UNKNOWN_DEFAULT_BROWSER; |
| 194 // TODO(mdm): Really, being the default browser should be a ternary query: | |
| 195 // yes, no, and "don't know" so the UI can reflect this more accurately. | |
| 196 return true; | |
| 197 } | 194 } |
| 198 | 195 |
| 199 // Allow any reply that starts with "yes". | 196 // Allow any reply that starts with "yes". |
| 200 return reply.find("yes") == 0; | 197 return (reply.find("yes") == 0) ? IS_DEFAULT_BROWSER : NOT_DEFAULT_BROWSER; |
|
Evan Martin
2009/09/04 22:46:15
I wonder what happens in non-english locales? (No
Mike Mammarella
2009/09/04 22:56:27
I wrote the other end of this in xdg-settings. It
| |
| 201 } | 198 } |
| 202 | 199 |
| 203 bool ShellIntegration::IsFirefoxDefaultBrowser() { | 200 bool ShellIntegration::IsFirefoxDefaultBrowser() { |
| 204 std::vector<std::string> argv; | 201 std::vector<std::string> argv; |
| 205 argv.push_back("xdg-settings"); | 202 argv.push_back("xdg-settings"); |
| 206 argv.push_back("get"); | 203 argv.push_back("get"); |
| 207 argv.push_back("default-web-browser"); | 204 argv.push_back("default-web-browser"); |
| 208 | 205 |
| 209 std::string browser; | 206 std::string browser; |
| 210 // We don't care about the return value here. | 207 // We don't care about the return value here. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 } | 260 } |
| 264 } | 261 } |
| 265 return output_buffer; | 262 return output_buffer; |
| 266 } | 263 } |
| 267 | 264 |
| 268 void ShellIntegration::CreateDesktopShortcut( | 265 void ShellIntegration::CreateDesktopShortcut( |
| 269 const ShortcutInfo& shortcut_info) { | 266 const ShortcutInfo& shortcut_info) { |
| 270 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, | 267 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, |
| 271 new CreateDesktopShortcutTask(shortcut_info)); | 268 new CreateDesktopShortcutTask(shortcut_info)); |
| 272 } | 269 } |
| OLD | NEW |