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/web_applications/web_app.h" | 5 #include "chrome/browser/web_applications/web_app.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 #endif // defined(OS_WIN) | 9 #endif // defined(OS_WIN) |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/i18n/file_util_icu.h" |
13 #include "base/md5.h" | 14 #include "base/md5.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/string_util.h" |
15 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
16 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
17 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
18 #include "chrome/browser/download/download_util.h" | 20 #include "chrome/browser/download/download_util.h" |
19 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
22 #include "content/browser/browser_thread.h" | 24 #include "content/browser/browser_thread.h" |
23 | 25 |
24 #if defined(OS_LINUX) | 26 #if defined(OS_LINUX) |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // properly quoted for a Windows command line. The method on | 334 // properly quoted for a Windows command line. The method on |
333 // CommandLine should probably be renamed to better reflect that | 335 // CommandLine should probably be renamed to better reflect that |
334 // fact. | 336 // fact. |
335 std::wstring wide_switches(cmd_line.command_line_string()); | 337 std::wstring wide_switches(cmd_line.command_line_string()); |
336 | 338 |
337 // Sanitize description | 339 // Sanitize description |
338 if (shortcut_info_.description.length() >= MAX_PATH) | 340 if (shortcut_info_.description.length() >= MAX_PATH) |
339 shortcut_info_.description.resize(MAX_PATH - 1); | 341 shortcut_info_.description.resize(MAX_PATH - 1); |
340 | 342 |
341 // Generates app id from web app url and profile path. | 343 // Generates app id from web app url and profile path. |
342 std::string app_name; | 344 std::string app_name = |
343 if (!shortcut_info_.extension_id.empty()) { | 345 web_app::GenerateApplicationNameFromInfo(shortcut_info_); |
344 app_name = web_app::GenerateApplicationNameFromExtensionId( | |
345 shortcut_info_.extension_id); | |
346 } else { | |
347 app_name = web_app::GenerateApplicationNameFromURL( | |
348 shortcut_info_.url); | |
349 } | |
350 std::wstring app_id = ShellIntegration::GetAppId( | 346 std::wstring app_id = ShellIntegration::GetAppId( |
351 UTF8ToWide(app_name), profile_path_); | 347 UTF8ToWide(app_name), profile_path_); |
352 | 348 |
353 FilePath shortcut_to_pin; | 349 FilePath shortcut_to_pin; |
354 | 350 |
355 bool success = true; | 351 bool success = true; |
356 for (size_t i = 0; i < shortcut_paths.size(); ++i) { | 352 for (size_t i = 0; i < shortcut_paths.size(); ++i) { |
357 FilePath shortcut_file = shortcut_paths[i].Append(file_name). | 353 FilePath shortcut_file = shortcut_paths[i].Append(file_name). |
358 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); | 354 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); |
359 | 355 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 #endif // OS_WIN | 443 #endif // OS_WIN |
448 | 444 |
449 // Returns data directory for given web app url | 445 // Returns data directory for given web app url |
450 FilePath GetWebAppDataDirectory(const FilePath& root_dir, | 446 FilePath GetWebAppDataDirectory(const FilePath& root_dir, |
451 const ShellIntegration::ShortcutInfo& info) { | 447 const ShellIntegration::ShortcutInfo& info) { |
452 return root_dir.Append(GetWebAppDir(info)); | 448 return root_dir.Append(GetWebAppDir(info)); |
453 } | 449 } |
454 | 450 |
455 } // namespace internals | 451 } // namespace internals |
456 | 452 |
| 453 std::string GenerateApplicationNameFromInfo( |
| 454 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 455 if (!shortcut_info.extension_id.empty()) { |
| 456 return web_app::GenerateApplicationNameFromExtensionId( |
| 457 shortcut_info.extension_id); |
| 458 } else { |
| 459 return web_app::GenerateApplicationNameFromURL( |
| 460 shortcut_info.url); |
| 461 } |
| 462 } |
| 463 |
457 std::string GenerateApplicationNameFromURL(const GURL& url) { | 464 std::string GenerateApplicationNameFromURL(const GURL& url) { |
458 std::string t; | 465 std::string t; |
459 t.append(url.host()); | 466 t.append(url.host()); |
460 t.append("_"); | 467 t.append("_"); |
461 t.append(url.path()); | 468 t.append(url.path()); |
462 return t; | 469 return t; |
463 } | 470 } |
464 | 471 |
465 std::string GenerateApplicationNameFromExtensionId(const std::string& id) { | 472 std::string GenerateApplicationNameFromExtensionId(const std::string& id) { |
466 std::string t(web_app::kCrxAppPrefix); | 473 std::string t(web_app::kCrxAppPrefix); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 // We only take square shaped icons (i.e. width == height). | 514 // We only take square shaped icons (i.e. width == height). |
508 if (app_info.icons[i].width == app_info.icons[i].height) { | 515 if (app_info.icons[i].width == app_info.icons[i].height) { |
509 icons->push_back(app_info.icons[i]); | 516 icons->push_back(app_info.icons[i]); |
510 } | 517 } |
511 } | 518 } |
512 | 519 |
513 std::sort(icons->begin(), icons->end(), &IconPrecedes); | 520 std::sort(icons->begin(), icons->end(), &IconPrecedes); |
514 } | 521 } |
515 #endif | 522 #endif |
516 | 523 |
| 524 #if defined(TOOLKIT_GTK) |
| 525 std::string GetWMClassFromAppName(std::string app_name) { |
| 526 file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); |
| 527 TrimString(app_name, "_", &app_name); |
| 528 return app_name; |
| 529 } |
| 530 #endif |
| 531 |
517 } // namespace web_app | 532 } // namespace web_app |
OLD | NEW |