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 true)) { | |
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, false); |
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, false); |
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 // 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 // icon cache to ensure correct icon is displayed. Returns true if icon_file |
569 // is up to date or successfully updated. | 570 // is up to date or successfully updated. |
570 bool CheckAndSaveIcon(const base::FilePath& icon_file, | 571 bool CheckAndSaveIcon(const base::FilePath& icon_file, |
571 const gfx::ImageFamily& image) { | 572 const gfx::ImageFamily& image, |
572 if (ShouldUpdateIcon(icon_file, image)) { | 573 bool is_shortcut_creation) { |
573 if (SaveIconWithCheckSum(icon_file, image)) { | 574 if (!ShouldUpdateIcon(icon_file, image)) |
574 // Refresh shell's icon cache. This call is quite disruptive as user would | 575 return true; |
575 // see explorer rebuilding the icon cache. It would be great that we find | |
576 // a better way to achieve this. | |
577 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, | |
578 NULL, NULL); | |
579 } else { | |
580 return false; | |
581 } | |
582 } | |
583 | 576 |
577 if (!SaveIconWithCheckSum(icon_file, image)) | |
578 return false; | |
579 | |
580 // Shortcut creation doesn't require a SHChangeNotify as the icon will be | |
Matt Giuca
2015/03/25 03:31:18
will be ...?
(I hate cliffhangers.)
calamity
2015/03/25 04:37:23
Moved to header comment.
| |
581 if (is_shortcut_creation) | |
582 return true; | |
583 | |
584 // Refresh shell's icon cache. This call is quite disruptive as user would | |
585 // see explorer rebuilding the icon cache. It would be great that we find | |
586 // a better way to achieve this. | |
587 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT, NULL, | |
588 NULL); | |
calamity
2015/03/24 07:35:08
This logic should be identical to the old code exc
Matt Giuca
2015/03/25 03:31:18
I like the refactoring you did here, but I think t
calamity
2015/03/25 04:37:23
Done.
| |
584 return true; | 589 return true; |
585 } | 590 } |
586 | 591 |
587 bool CreatePlatformShortcuts( | 592 bool CreatePlatformShortcuts( |
588 const base::FilePath& web_app_path, | 593 const base::FilePath& web_app_path, |
589 const ShortcutInfo& shortcut_info, | 594 const ShortcutInfo& shortcut_info, |
590 const extensions::FileHandlersInfo& file_handlers_info, | 595 const extensions::FileHandlersInfo& file_handlers_info, |
591 const ShortcutLocations& creation_locations, | 596 const ShortcutLocations& creation_locations, |
592 ShortcutCreationReason creation_reason) { | 597 ShortcutCreationReason creation_reason) { |
593 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 598 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 | 672 // Use the web app path shortcut for pinning to avoid having unique |
668 // numbers in the application name. | 673 // numbers in the application name. |
669 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). | 674 base::FilePath shortcut_to_pin = web_app_path.Append(file_name). |
670 AddExtension(installer::kLnkExt); | 675 AddExtension(installer::kLnkExt); |
671 base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()); | 676 base::win::TaskbarPinShortcutLink(shortcut_to_pin.value().c_str()); |
672 } | 677 } |
673 } | 678 } |
674 | 679 |
675 // Update the icon if necessary. | 680 // Update the icon if necessary. |
676 base::FilePath icon_file = GetIconFilePath(web_app_path, shortcut_info.title); | 681 base::FilePath icon_file = GetIconFilePath(web_app_path, shortcut_info.title); |
677 CheckAndSaveIcon(icon_file, shortcut_info.favicon); | 682 CheckAndSaveIcon(icon_file, shortcut_info.favicon, false); |
678 } | 683 } |
679 | 684 |
680 void DeletePlatformShortcuts(const base::FilePath& web_app_path, | 685 void DeletePlatformShortcuts(const base::FilePath& web_app_path, |
681 const ShortcutInfo& shortcut_info) { | 686 const ShortcutInfo& shortcut_info) { |
682 GetShortcutLocationsAndDeleteShortcuts( | 687 GetShortcutLocationsAndDeleteShortcuts( |
683 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, | 688 web_app_path, shortcut_info.profile_path, shortcut_info.title, NULL, |
684 NULL); | 689 NULL); |
685 | 690 |
686 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. | 691 // If there are no more shortcuts in the Chrome Apps subdirectory, remove it. |
687 base::FilePath chrome_apps_dir; | 692 base::FilePath chrome_apps_dir; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 | 775 |
771 } // namespace internals | 776 } // namespace internals |
772 | 777 |
773 void UpdateShortcutForTabContents(content::WebContents* web_contents) { | 778 void UpdateShortcutForTabContents(content::WebContents* web_contents) { |
774 // UpdateShortcutWorker will delete itself when it's done. | 779 // UpdateShortcutWorker will delete itself when it's done. |
775 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); | 780 UpdateShortcutWorker* worker = new UpdateShortcutWorker(web_contents); |
776 worker->Run(); | 781 worker->Run(); |
777 } | 782 } |
778 | 783 |
779 } // namespace web_app | 784 } // namespace web_app |
OLD | NEW |