| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/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 <ShellAPI.h> | 8 #include <ShellAPI.h> |
| 9 #endif // defined(OS_WIN) | 9 #endif // defined(OS_WIN) |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/md5.h" | 17 #include "base/md5.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 20 #include "base/thread.h" | 20 #include "base/thread.h" |
| 21 #include "base/scoped_ptr.h" | 21 #include "base/scoped_ptr.h" |
| 22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 23 #include "chrome/browser/chrome_thread.h" | 23 #include "chrome/browser/chrome_thread.h" |
| 24 #include "chrome/browser/download/download_util.h" |
| 24 #include "chrome/browser/profile.h" | 25 #include "chrome/browser/profile.h" |
| 25 #include "chrome/browser/tab_contents/tab_contents.h" | 26 #include "chrome/browser/tab_contents/tab_contents.h" |
| 26 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
| 27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_plugin_util.h" | 29 #include "chrome/common/chrome_plugin_util.h" |
| 29 #include "chrome/common/notification_registrar.h" | 30 #include "chrome/common/notification_registrar.h" |
| 30 #include "chrome/common/notification_service.h" | 31 #include "chrome/common/notification_service.h" |
| 31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 32 #include "webkit/glue/dom_operations.h" | 33 #include "webkit/glue/dom_operations.h" |
| 33 | 34 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 372 |
| 372 // Sanitize description | 373 // Sanitize description |
| 373 if (shortcut_info_.description.length() >= MAX_PATH) | 374 if (shortcut_info_.description.length() >= MAX_PATH) |
| 374 shortcut_info_.description.resize(MAX_PATH - 1); | 375 shortcut_info_.description.resize(MAX_PATH - 1); |
| 375 | 376 |
| 376 // Generates app id from web app url and profile path. | 377 // Generates app id from web app url and profile path. |
| 377 std::wstring app_id = ShellIntegration::GetAppId( | 378 std::wstring app_id = ShellIntegration::GetAppId( |
| 378 web_app::GenerateApplicationNameFromURL(shortcut_info_.url).c_str(), | 379 web_app::GenerateApplicationNameFromURL(shortcut_info_.url).c_str(), |
| 379 profile_path_); | 380 profile_path_); |
| 380 | 381 |
| 382 FilePath shortcut_to_pin; |
| 383 |
| 381 bool success = true; | 384 bool success = true; |
| 382 for (size_t i = 0; i < shortcut_paths.size(); ++i) { | 385 for (size_t i = 0; i < shortcut_paths.size(); ++i) { |
| 383 FilePath shortcut_file = shortcut_paths[i].Append(file_name). | 386 FilePath shortcut_file = shortcut_paths[i].Append(file_name). |
| 384 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); | 387 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); |
| 388 |
| 389 int unique_number = download_util::GetUniquePathNumber(shortcut_file); |
| 390 if (unique_number == -1) { |
| 391 success = false; |
| 392 continue; |
| 393 } else if (unique_number > 0) { |
| 394 download_util::AppendNumberToPath(&shortcut_file, unique_number); |
| 395 } |
| 396 |
| 385 success &= file_util::CreateShortcutLink(chrome_exe.c_str(), | 397 success &= file_util::CreateShortcutLink(chrome_exe.c_str(), |
| 386 shortcut_file.value().c_str(), | 398 shortcut_file.value().c_str(), |
| 387 chrome_folder.c_str(), | 399 chrome_folder.c_str(), |
| 388 wide_switchs.c_str(), | 400 wide_switchs.c_str(), |
| 389 shortcut_info_.description.c_str(), | 401 shortcut_info_.description.c_str(), |
| 390 icon_file.value().c_str(), | 402 icon_file.value().c_str(), |
| 391 0, | 403 0, |
| 392 app_id.c_str()); | 404 app_id.c_str()); |
| 405 |
| 406 // Any shortcut would work for the pinning. We use the first one. |
| 407 if (success && pin_to_taskbar && shortcut_to_pin.empty()) |
| 408 shortcut_to_pin = shortcut_file; |
| 393 } | 409 } |
| 394 | 410 |
| 395 if (success && pin_to_taskbar) { | 411 if (success && pin_to_taskbar) { |
| 396 // Any shortcut would work for the pinning. We use the first one. | 412 if (!shortcut_to_pin.empty()) { |
| 397 FilePath shortcut_file = shortcut_paths[0].Append(file_name). | 413 success &= file_util::TaskbarPinShortcutLink( |
| 398 ReplaceExtension(FILE_PATH_LITERAL(".lnk")); | 414 shortcut_to_pin.value().c_str()); |
| 399 success &= file_util::TaskbarPinShortcutLink(shortcut_file.value().c_str()); | 415 } else { |
| 416 NOTREACHED(); |
| 417 success = false; |
| 418 } |
| 400 } | 419 } |
| 401 | 420 |
| 402 return success; | 421 return success; |
| 403 #else | 422 #else |
| 404 NOTIMPLEMENTED(); | 423 NOTIMPLEMENTED(); |
| 405 return false; | 424 return false; |
| 406 #endif | 425 #endif |
| 407 } | 426 } |
| 408 | 427 |
| 409 #if defined(OS_WIN) | 428 #if defined(OS_WIN) |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 | 758 |
| 740 void UpdateShortcutForTabContents(TabContents* tab_contents) { | 759 void UpdateShortcutForTabContents(TabContents* tab_contents) { |
| 741 #if defined(OS_WIN) | 760 #if defined(OS_WIN) |
| 742 // UpdateShortcutWorker will delete itself when it's done. | 761 // UpdateShortcutWorker will delete itself when it's done. |
| 743 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); | 762 UpdateShortcutWorker* worker = new UpdateShortcutWorker(tab_contents); |
| 744 worker->Run(); | 763 worker->Run(); |
| 745 #endif // defined(OS_WIN) | 764 #endif // defined(OS_WIN) |
| 746 } | 765 } |
| 747 | 766 |
| 748 }; // namespace web_app | 767 }; // namespace web_app |
| OLD | NEW |