OLD | NEW |
---|---|
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 <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 11 matching lines...) Expand all Loading... | |
22 #include "base/memory/scoped_temp_dir.h" | 22 #include "base/memory/scoped_temp_dir.h" |
23 #include "base/message_loop.h" | 23 #include "base/message_loop.h" |
24 #include "base/path_service.h" | 24 #include "base/path_service.h" |
25 #include "base/process_util.h" | 25 #include "base/process_util.h" |
26 #include "base/string_number_conversions.h" | 26 #include "base/string_number_conversions.h" |
27 #include "base/string_tokenizer.h" | 27 #include "base/string_tokenizer.h" |
28 #include "base/string_util.h" | 28 #include "base/string_util.h" |
29 #include "base/task.h" | 29 #include "base/task.h" |
30 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
31 #include "base/utf_string_conversions.h" | 31 #include "base/utf_string_conversions.h" |
32 #include "chrome/browser/web_applications/web_app.h" | |
32 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
33 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
34 #include "content/browser/browser_thread.h" | 35 #include "content/browser/browser_thread.h" |
35 #include "googleurl/src/gurl.h" | 36 #include "googleurl/src/gurl.h" |
36 #include "ui/gfx/codec/png_codec.h" | 37 #include "ui/gfx/codec/png_codec.h" |
37 | 38 |
38 namespace { | 39 namespace { |
39 | 40 |
40 // Helper to launch xdg scripts. We don't want them to ask any questions on the | 41 // Helper to launch xdg scripts. We don't want them to ask any questions on the |
41 // terminal etc. | 42 // terminal etc. |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 } else { | 354 } else { |
354 return FilePath(alternative_filepath).BaseName(); | 355 return FilePath(alternative_filepath).BaseName(); |
355 } | 356 } |
356 } | 357 } |
357 | 358 |
358 return FilePath(); | 359 return FilePath(); |
359 } | 360 } |
360 | 361 |
361 // static | 362 // static |
362 std::string ShellIntegration::GetDesktopFileContents( | 363 std::string ShellIntegration::GetDesktopFileContents( |
363 const std::string& template_contents, const GURL& url, | 364 const std::string& template_contents, |
364 const std::string& extension_id, const string16& title, | 365 const std::string& app_name, |
366 const GURL& url, | |
367 const std::string& extension_id, | |
368 const string16& title, | |
365 const std::string& icon_name) { | 369 const std::string& icon_name) { |
366 // See http://standards.freedesktop.org/desktop-entry-spec/latest/ | 370 // See http://standards.freedesktop.org/desktop-entry-spec/latest/ |
367 // Although not required by the spec, Nautilus on Ubuntu Karmic creates its | 371 // Although not required by the spec, Nautilus on Ubuntu Karmic creates its |
368 // launchers with an xdg-open shebang. Follow that convention. | 372 // launchers with an xdg-open shebang. Follow that convention. |
369 std::string output_buffer("#!/usr/bin/env xdg-open\n"); | 373 std::string output_buffer("#!/usr/bin/env xdg-open\n"); |
370 StringTokenizer tokenizer(template_contents, "\n"); | 374 StringTokenizer tokenizer(template_contents, "\n"); |
371 while (tokenizer.GetNext()) { | 375 while (tokenizer.GetNext()) { |
372 if (tokenizer.token().substr(0, 5) == "Exec=") { | 376 if (tokenizer.token().substr(0, 5) == "Exec=") { |
373 std::string exec_path = tokenizer.token().substr(5); | 377 std::string exec_path = tokenizer.token().substr(5); |
374 StringTokenizer exec_tokenizer(exec_path, " "); | 378 StringTokenizer exec_tokenizer(exec_path, " "); |
(...skipping 28 matching lines...) Expand all Loading... | |
403 final_title = url.spec(); | 407 final_title = url.spec(); |
404 } | 408 } |
405 output_buffer += StringPrintf("Name=%s\n", final_title.c_str()); | 409 output_buffer += StringPrintf("Name=%s\n", final_title.c_str()); |
406 } else if (tokenizer.token().substr(0, 11) == "GenericName" || | 410 } else if (tokenizer.token().substr(0, 11) == "GenericName" || |
407 tokenizer.token().substr(0, 7) == "Comment" || | 411 tokenizer.token().substr(0, 7) == "Comment" || |
408 tokenizer.token().substr(0, 1) == "#") { | 412 tokenizer.token().substr(0, 1) == "#") { |
409 // Skip comment lines. | 413 // Skip comment lines. |
410 } else if (tokenizer.token().substr(0, 9) == "MimeType=") { | 414 } else if (tokenizer.token().substr(0, 9) == "MimeType=") { |
411 // Skip MimeType lines, they are only relevant for a web browser | 415 // Skip MimeType lines, they are only relevant for a web browser |
412 // shortcut, not a web application shortcut. | 416 // shortcut, not a web application shortcut. |
417 } else if (tokenizer.token().substr(0, 15) == "StartupWMClass=") { | |
418 // Skip StartupWMClass; it will cerrtainly be wrong since we emit a | |
Evan Stade
2011/04/05 21:12:08
certainly
| |
419 // different one based on the app name below. | |
413 } else if (tokenizer.token().substr(0, 5) == "Icon=" && | 420 } else if (tokenizer.token().substr(0, 5) == "Icon=" && |
414 !icon_name.empty()) { | 421 !icon_name.empty()) { |
415 output_buffer += StringPrintf("Icon=%s\n", icon_name.c_str()); | 422 output_buffer += StringPrintf("Icon=%s\n", icon_name.c_str()); |
416 } else { | 423 } else { |
417 output_buffer += tokenizer.token() + "\n"; | 424 output_buffer += tokenizer.token() + "\n"; |
418 } | 425 } |
419 } | 426 } |
427 | |
428 output_buffer += "StartupWMClass="; | |
Evan Stade
2011/04/05 21:12:08
I'd slightly prefer
output_buffer += foo + bar
| |
429 output_buffer += web_app::GetWMClassFromAppName(app_name); | |
430 output_buffer += "\n"; | |
431 | |
420 return output_buffer; | 432 return output_buffer; |
421 } | 433 } |
422 | 434 |
423 // static | 435 // static |
424 void ShellIntegration::CreateDesktopShortcut( | 436 void ShellIntegration::CreateDesktopShortcut( |
425 const ShortcutInfo& shortcut_info, const std::string& shortcut_template) { | 437 const ShortcutInfo& shortcut_info, const std::string& shortcut_template) { |
426 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. | 438 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. |
427 | 439 |
428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
429 | 441 |
430 FilePath shortcut_filename = GetDesktopShortcutFilename(shortcut_info.url); | 442 FilePath shortcut_filename = GetDesktopShortcutFilename(shortcut_info.url); |
431 if (shortcut_filename.empty()) | 443 if (shortcut_filename.empty()) |
432 return; | 444 return; |
433 | 445 |
434 std::string icon_name = CreateShortcutIcon(shortcut_info, shortcut_filename); | 446 std::string icon_name = CreateShortcutIcon(shortcut_info, shortcut_filename); |
435 | 447 |
448 std::string app_name = | |
449 web_app::GenerateApplicationNameFromInfo(shortcut_info); | |
436 std::string contents = GetDesktopFileContents( | 450 std::string contents = GetDesktopFileContents( |
437 shortcut_template, shortcut_info.url, shortcut_info.extension_id, | 451 shortcut_template, |
438 shortcut_info.title, icon_name); | 452 app_name, |
453 shortcut_info.url, | |
454 shortcut_info.extension_id, | |
455 shortcut_info.title, | |
456 icon_name); | |
439 | 457 |
440 if (shortcut_info.create_on_desktop) | 458 if (shortcut_info.create_on_desktop) |
441 CreateShortcutOnDesktop(shortcut_filename, contents); | 459 CreateShortcutOnDesktop(shortcut_filename, contents); |
442 | 460 |
443 if (shortcut_info.create_in_applications_menu) | 461 if (shortcut_info.create_in_applications_menu) |
444 CreateShortcutInApplicationsMenu(shortcut_filename, contents); | 462 CreateShortcutInApplicationsMenu(shortcut_filename, contents); |
445 } | 463 } |
OLD | NEW |