Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/shell_integration_linux.cc

Issue 7972011: Fix checking default protocol client on Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update for feedback Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <glib.h> 8 #include <glib.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // into the new .desktop file. 213 // into the new .desktop file.
214 const char* kDesktopKeysToDelete[] = { 214 const char* kDesktopKeysToDelete[] = {
215 "GenericName", 215 "GenericName",
216 "Comment", 216 "Comment",
217 "MimeType", 217 "MimeType",
218 "X-Ayatana-Desktop-Shortcuts", 218 "X-Ayatana-Desktop-Shortcuts",
219 "StartupWMClass", 219 "StartupWMClass",
220 NULL 220 NULL
221 }; 221 };
222 222
223 const char* kDesktopEntry = "Desktop Entry"; 223 const char kDesktopEntry[] = "Desktop Entry";
224 224
225 const char* kXdgOpenShebang = "#!/usr/bin/env xdg-open"; 225 const char kXdgOpenShebang[] = "#!/usr/bin/env xdg-open";
226
227 const char kXdgSettings[] = "xdg-settings";
228 const char kXdgSettingsDefaultBrowser[] = "default-web-browser";
229 const char kXdgSettingsDefaultSchemeHandler[] = "default-url-scheme-handler";
226 230
227 } // namespace 231 } // namespace
228 232
229 // static 233 // static
230 std::string ShellIntegration::GetDesktopName(base::Environment* env) { 234 std::string ShellIntegration::GetDesktopName(base::Environment* env) {
231 #if defined(GOOGLE_CHROME_BUILD) 235 #if defined(GOOGLE_CHROME_BUILD)
232 return "google-chrome.desktop"; 236 return "google-chrome.desktop";
233 #else // CHROMIUM_BUILD 237 #else // CHROMIUM_BUILD
234 // Allow $CHROME_DESKTOP to override the built-in value, so that development 238 // Allow $CHROME_DESKTOP to override the built-in value, so that development
235 // versions can set themselves as the default without interfering with 239 // versions can set themselves as the default without interfering with
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // copy. 290 // copy.
287 291
288 // If |protocol| is empty this function sets Chrome as the default browser, 292 // If |protocol| is empty this function sets Chrome as the default browser,
289 // otherwise it sets Chrome as the default handler application for |protocol|. 293 // otherwise it sets Chrome as the default handler application for |protocol|.
290 bool SetDefaultWebClient(const std::string& protocol) { 294 bool SetDefaultWebClient(const std::string& protocol) {
291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
292 296
293 scoped_ptr<base::Environment> env(base::Environment::Create()); 297 scoped_ptr<base::Environment> env(base::Environment::Create());
294 298
295 std::vector<std::string> argv; 299 std::vector<std::string> argv;
296 argv.push_back("xdg-settings"); 300 argv.push_back(kXdgSettings);
297 argv.push_back("set"); 301 argv.push_back("set");
298 if (protocol.empty()) { 302 if (protocol.empty()) {
299 argv.push_back("default-web-browser"); 303 argv.push_back(kXdgSettingsDefaultBrowser);
300 } else { 304 } else {
301 argv.push_back("default-url-scheme-handler"); 305 argv.push_back(kXdgSettingsDefaultSchemeHandler);
302 argv.push_back(protocol); 306 argv.push_back(protocol);
303 } 307 }
304 argv.push_back(ShellIntegration::GetDesktopName(env.get())); 308 argv.push_back(ShellIntegration::GetDesktopName(env.get()));
305 309
306 int exit_code; 310 int exit_code;
307 bool ran_ok = LaunchXdgUtility(argv, &exit_code); 311 bool ran_ok = LaunchXdgUtility(argv, &exit_code);
308 if (ran_ok && exit_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { 312 if (ran_ok && exit_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) {
309 if (GetChromeVersionOfScript("xdg-settings", &argv[0])) { 313 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) {
310 ran_ok = LaunchXdgUtility(argv, &exit_code); 314 ran_ok = LaunchXdgUtility(argv, &exit_code);
311 } 315 }
312 } 316 }
313 317
314 return ran_ok && exit_code == EXIT_SUCCESS; 318 return ran_ok && exit_code == EXIT_SUCCESS;
315 } 319 }
316 320
317 // If |protocol| is empty this function checks if Chrome is the default browser, 321 // If |protocol| is empty this function checks if Chrome is the default browser,
318 // otherwise it checks if Chrome is the default handler application for 322 // otherwise it checks if Chrome is the default handler application for
319 // |protocol|. 323 // |protocol|.
320 ShellIntegration::DefaultWebClientState GetIsDefaultWebClient( 324 ShellIntegration::DefaultWebClientState GetIsDefaultWebClient(
321 const std::string& protocol) { 325 const std::string& protocol) {
322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
323 327
324 scoped_ptr<base::Environment> env(base::Environment::Create()); 328 scoped_ptr<base::Environment> env(base::Environment::Create());
325 329
326 std::vector<std::string> argv; 330 std::vector<std::string> argv;
327 argv.push_back("xdg-settings"); 331 argv.push_back(kXdgSettings);
328 argv.push_back("check"); 332 argv.push_back("check");
329 if (protocol.empty()) { 333 if (protocol.empty()) {
330 argv.push_back("default-web-browser"); 334 argv.push_back(kXdgSettingsDefaultBrowser);
331 } else { 335 } else {
332 argv.push_back("default-url-scheme-handler"); 336 argv.push_back(kXdgSettingsDefaultSchemeHandler);
333 argv.push_back(protocol); 337 argv.push_back(protocol);
334 } 338 }
335 argv.push_back(ShellIntegration::GetDesktopName(env.get())); 339 argv.push_back(ShellIntegration::GetDesktopName(env.get()));
336 340
337 std::string reply; 341 std::string reply;
338 int success_code; 342 int success_code;
339 bool ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply, 343 bool ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply,
340 &success_code); 344 &success_code);
341 if (ran_ok && success_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { 345 if (ran_ok && success_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) {
342 if (GetChromeVersionOfScript("xdg_settings", &argv[0])) { 346 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) {
343 ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply, 347 ran_ok = base::GetAppOutputWithExitCode(CommandLine(argv), &reply,
344 &success_code); 348 &success_code);
345 } 349 }
346 } 350 }
347 351
348 if (!ran_ok || success_code != EXIT_SUCCESS) { 352 if (!ran_ok || success_code != EXIT_SUCCESS) {
349 // xdg-settings failed: we can't determine or set the default browser. 353 // xdg-settings failed: we can't determine or set the default browser.
350 return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT; 354 return ShellIntegration::UNKNOWN_DEFAULT_WEB_CLIENT;
351 } 355 }
352 356
(...skipping 26 matching lines...) Expand all
379 383
380 // static 384 // static
381 ShellIntegration::DefaultWebClientState 385 ShellIntegration::DefaultWebClientState
382 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { 386 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) {
383 return GetIsDefaultWebClient(protocol); 387 return GetIsDefaultWebClient(protocol);
384 } 388 }
385 389
386 // static 390 // static
387 bool ShellIntegration::IsFirefoxDefaultBrowser() { 391 bool ShellIntegration::IsFirefoxDefaultBrowser() {
388 std::vector<std::string> argv; 392 std::vector<std::string> argv;
389 argv.push_back("xdg-settings"); 393 argv.push_back(kXdgSettings);
390 argv.push_back("get"); 394 argv.push_back("get");
391 argv.push_back("default-web-browser"); 395 argv.push_back(kXdgSettingsDefaultBrowser);
392 396
393 std::string browser; 397 std::string browser;
394 // We don't care about the return value here. 398 // We don't care about the return value here.
395 base::GetAppOutput(CommandLine(argv), &browser); 399 base::GetAppOutput(CommandLine(argv), &browser);
396 return browser.find("irefox") != std::string::npos; 400 return browser.find("irefox") != std::string::npos;
397 } 401 }
398 402
399 // static 403 // static
400 bool ShellIntegration::GetDesktopShortcutTemplate( 404 bool ShellIntegration::GetDesktopShortcutTemplate(
401 base::Environment* env, std::string* output) { 405 base::Environment* env, std::string* output) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 shortcut_info.extension_id, 601 shortcut_info.extension_id,
598 shortcut_info.title, 602 shortcut_info.title,
599 icon_name); 603 icon_name);
600 604
601 if (shortcut_info.create_on_desktop) 605 if (shortcut_info.create_on_desktop)
602 CreateShortcutOnDesktop(shortcut_filename, contents); 606 CreateShortcutOnDesktop(shortcut_filename, contents);
603 607
604 if (shortcut_info.create_in_applications_menu) 608 if (shortcut_info.create_in_applications_menu)
605 CreateShortcutInApplicationsMenu(shortcut_filename, contents); 609 CreateShortcutInApplicationsMenu(shortcut_filename, contents);
606 } 610 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698