OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_win.h" | 5 #include "chrome/browser/web_applications/web_app_win.h" |
6 | 6 |
7 #include <shlobj.h> | 7 #include <shlobj.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 std::vector<base::FilePath>* out_filenames) { | 176 std::vector<base::FilePath>* out_filenames) { |
177 // Ensure web_app_path exists. | 177 // Ensure web_app_path exists. |
178 if (!base::PathExists(web_app_path) && | 178 if (!base::PathExists(web_app_path) && |
179 !base::CreateDirectory(web_app_path)) { | 179 !base::CreateDirectory(web_app_path)) { |
180 return false; | 180 return false; |
181 } | 181 } |
182 | 182 |
183 // Generates file name to use with persisted ico and shortcut file. | 183 // Generates file name to use with persisted ico and shortcut file. |
184 base::FilePath icon_file = | 184 base::FilePath icon_file = |
185 web_app::internals::GetIconFilePath(web_app_path, shortcut_info.title); | 185 web_app::internals::GetIconFilePath(web_app_path, shortcut_info.title); |
186 if (!web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon)) { | 186 if (!web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon, |
| 187 false)) { |
187 return false; | 188 return false; |
188 } | 189 } |
189 | 190 |
190 base::FilePath chrome_exe; | 191 base::FilePath chrome_exe; |
191 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 192 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
192 NOTREACHED(); | 193 NOTREACHED(); |
193 return false; | 194 return false; |
194 } | 195 } |
195 | 196 |
196 // Working directory. | 197 // Working directory. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 return; | 351 return; |
351 } | 352 } |
352 command_line.SetProgram(chrome_exe); | 353 command_line.SetProgram(chrome_exe); |
353 ui::win::SetRelaunchDetailsForWindow( | 354 ui::win::SetRelaunchDetailsForWindow( |
354 command_line.GetCommandLineString(), shortcut_info.title, hwnd); | 355 command_line.GetCommandLineString(), shortcut_info.title, hwnd); |
355 | 356 |
356 if (!base::PathExists(web_app_path) && !base::CreateDirectory(web_app_path)) | 357 if (!base::PathExists(web_app_path) && !base::CreateDirectory(web_app_path)) |
357 return; | 358 return; |
358 | 359 |
359 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); | 360 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); |
360 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); | 361 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon, true); |
361 } | 362 } |
362 | 363 |
363 void OnShortcutInfoLoadedForSetRelaunchDetails( | 364 void OnShortcutInfoLoadedForSetRelaunchDetails( |
364 HWND hwnd, | 365 HWND hwnd, |
365 const web_app::ShortcutInfo& shortcut_info) { | 366 const web_app::ShortcutInfo& shortcut_info) { |
366 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 367 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
367 | 368 |
368 // Set window's icon to the one we're about to create/update in the web app | 369 // Set window's icon to the one we're about to create/update in the web app |
369 // path. The icon cache will refresh on icon creation. | 370 // path. The icon cache will refresh on icon creation. |
370 base::FilePath web_app_path = | 371 base::FilePath web_app_path = |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 CreateShortcutsInPaths(web_app_dir, | 537 CreateShortcutsInPaths(web_app_dir, |
537 shortcut_info, | 538 shortcut_info, |
538 paths, | 539 paths, |
539 SHORTCUT_CREATION_BY_USER, | 540 SHORTCUT_CREATION_BY_USER, |
540 &out_filenames); | 541 &out_filenames); |
541 DCHECK_EQ(out_filenames.size(), 1u); | 542 DCHECK_EQ(out_filenames.size(), 1u); |
542 DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value()); | 543 DCHECK_EQ(out_filenames[0].value(), web_app_dir_shortcut.value()); |
543 } else { | 544 } else { |
544 internals::CheckAndSaveIcon( | 545 internals::CheckAndSaveIcon( |
545 internals::GetIconFilePath(web_app_dir, shortcut_info.title), | 546 internals::GetIconFilePath(web_app_dir, shortcut_info.title), |
546 shortcut_info.favicon); | 547 shortcut_info.favicon, true); |
547 } | 548 } |
548 return web_app_dir_shortcut; | 549 return web_app_dir_shortcut; |
549 } | 550 } |
550 | 551 |
551 void UpdateRelaunchDetailsForApp(Profile* profile, | 552 void UpdateRelaunchDetailsForApp(Profile* profile, |
552 const extensions::Extension* extension, | 553 const extensions::Extension* extension, |
553 HWND hwnd) { | 554 HWND hwnd) { |
554 web_app::GetShortcutInfoForApp( | 555 web_app::GetShortcutInfoForApp( |
555 extension, | 556 extension, |
556 profile, | 557 profile, |
557 base::Bind(&OnShortcutInfoLoadedForSetRelaunchDetails, hwnd)); | 558 base::Bind(&OnShortcutInfoLoadedForSetRelaunchDetails, hwnd)); |
558 } | 559 } |
559 | 560 |
560 void UpdateShortcutsForAllApps(Profile* profile, | 561 void UpdateShortcutsForAllApps(Profile* profile, |
561 const base::Closure& callback) { | 562 const base::Closure& callback) { |
562 callback.Run(); | 563 callback.Run(); |
563 } | 564 } |
564 | 565 |
565 namespace internals { | 566 namespace internals { |
566 | 567 |
567 // Saves |image| to |icon_file| if the file is outdated and refresh shell's | |
568 // icon cache to ensure correct icon is displayed. Returns true if icon_file | |
569 // is up to date or successfully updated. | |
570 bool CheckAndSaveIcon(const base::FilePath& icon_file, | 568 bool CheckAndSaveIcon(const base::FilePath& icon_file, |
571 const gfx::ImageFamily& image) { | 569 const gfx::ImageFamily& image, |
572 if (ShouldUpdateIcon(icon_file, image)) { | 570 bool refresh_shell_icon_cache) { |
573 if (SaveIconWithCheckSum(icon_file, image)) { | 571 if (!ShouldUpdateIcon(icon_file, image)) |
574 // Refresh shell's icon cache. This call is quite disruptive as user would | 572 return true; |
575 // see explorer rebuilding the icon cache. It would be great that we find | 573 |
576 // a better way to achieve this. | 574 if (!SaveIconWithCheckSum(icon_file, image)) |
577 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, | 575 return false; |
578 NULL, NULL); | 576 |
579 } else { | 577 if (refresh_shell_icon_cache) { |
580 return false; | 578 // Refresh shell's icon cache. This call is quite disruptive as user would |
581 } | 579 // see explorer rebuilding the icon cache. It would be great that we find |
| 580 // a better way to achieve this. |
| 581 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, |
| 582 NULL); |
582 } | 583 } |
583 | |
584 return true; | 584 return true; |
585 } | 585 } |
586 | 586 |
587 bool CreatePlatformShortcuts( | 587 bool CreatePlatformShortcuts( |
588 const base::FilePath& web_app_path, | 588 const base::FilePath& web_app_path, |
589 const ShortcutInfo& shortcut_info, | 589 const ShortcutInfo& shortcut_info, |
590 const extensions::FileHandlersInfo& file_handlers_info, | 590 const extensions::FileHandlersInfo& file_handlers_info, |
591 const ShortcutLocations& creation_locations, | 591 const ShortcutLocations& creation_locations, |
592 ShortcutCreationReason creation_reason) { | 592 ShortcutCreationReason creation_reason) { |
593 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 593 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 // Use the web app path shortcut for pinning to avoid having unique | 667 // Use the web app path shortcut for pinning to avoid having unique |
668 // numbers in the application name. | 668 // numbers in the application name. |
669 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). | 669 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). |
670 AddExtension(installer::kLnkExt); | 670 AddExtension(installer::kLnkExt); |
671 base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()); | 671 base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()); |
672 } | 672 } |
673 } | 673 } |
674 | 674 |
675 // Update the icon if necessary. | 675 // Update the icon if necessary. |
676 base::FilePath icon_file = GetIconFilePath(web_app_path, shortcut_info.title); | 676 base::FilePath icon_file = GetIconFilePath(web_app_path, shortcut_info.title); |
677 CheckAndSaveIcon(icon_file, shortcut_info.favicon); | 677 CheckAndSaveIcon(icon_file, shortcut_info.favicon, true); |
678 } | 678 } |
679 | 679 |
680 void DeletePlatformShortcuts(const base::FilePath& web_app_path, | 680 void DeletePlatformShortcuts(const base::FilePath& web_app_path, |
681 const ShortcutInfo& shortcut_info) { | 681 const ShortcutInfo& shortcut_info) { |
682 GetShortcutLocationsAndDeleteShortcuts( | 682 GetShortcutLocationsAndDeleteShortcuts( |
683 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, | 683 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, |
684 NULL); | 684 NULL); |
685 | 685 |
686 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. | 686 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. |
687 base::FilePath chrome_apps_dir; | 687 base::FilePath chrome_apps_dir; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 | 770 |
771 } // namespace internals | 771 } // namespace internals |
772 | 772 |
773 void UpdateShortcutForTabContents(content::WebContents* web_contents) { | 773 void UpdateShortcutForTabContents(content::WebContents* web_contents) { |
774 // UpdateShortcutWorker will delete itself when it's done. | 774 // UpdateShortcutWorker will delete itself when it's done. |
775 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); | 775 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); |
776 worker->Run(); | 776 worker->Run(); |
777 } | 777 } |
778 | 778 |
779 } // namespace web_app | 779 } // namespace web_app |
OLD | NEW |