Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/browser/web_applications/web_app_mac.mm

Issue 231673005: Move ShortcutInfo, ShortcutLocations from ShellIntegration to web_app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Windws Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #import "chrome/browser/web_applications/web_app_mac.h" 5 #import "chrome/browser/web_applications/web_app_mac.h"
6 6
7 #import <Carbon/Carbon.h> 7 #import <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "apps/app_shim/app_shim_mac.h" 10 #include "apps/app_shim/app_shim_mac.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 196 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
197 DCHECK(!user_data_dir.empty()); 197 DCHECK(!user_data_dir.empty());
198 return StartsWithASCII( 198 return StartsWithASCII(
199 base::SysNSStringToUTF8( 199 base::SysNSStringToUTF8(
200 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]), 200 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]),
201 user_data_dir.value(), 201 user_data_dir.value(),
202 true /* case_sensitive */); 202 true /* case_sensitive */);
203 } 203 }
204 204
205 void LaunchShimOnFileThread( 205 void LaunchShimOnFileThread(
206 const ShellIntegration::ShortcutInfo& shortcut_info) { 206 const web_app::ShortcutInfo& shortcut_info) {
207 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 207 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
208 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info); 208 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info);
209 209
210 if (shim_path.empty() || 210 if (shim_path.empty() ||
211 !base::PathExists(shim_path) || 211 !base::PathExists(shim_path) ||
212 !HasSameUserDataDir(shim_path)) { 212 !HasSameUserDataDir(shim_path)) {
213 // The user may have deleted the copy in the Applications folder, use the 213 // The user may have deleted the copy in the Applications folder, use the
214 // one in the web app's |app_data_dir_|. 214 // one in the web app's |app_data_dir_|.
215 base::FilePath app_data_dir = web_app::GetWebAppDataDirectory( 215 base::FilePath app_data_dir = web_app::GetWebAppDataDirectory(
216 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); 216 shortcut_info.profile_path, shortcut_info.extension_id, GURL());
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 base::FileEnumerator::DIRECTORIES); 381 base::FileEnumerator::DIRECTORIES);
382 for (base::FilePath bundle_path = enumerator.Next(); 382 for (base::FilePath bundle_path = enumerator.Next();
383 !bundle_path.empty(); bundle_path = enumerator.Next()) { 383 !bundle_path.empty(); bundle_path = enumerator.Next()) {
384 if (IsShimForProfile(bundle_path.BaseName(), profile_base_name)) 384 if (IsShimForProfile(bundle_path.BaseName(), profile_base_name))
385 bundle_paths.push_back(bundle_path); 385 bundle_paths.push_back(bundle_path);
386 } 386 }
387 387
388 return bundle_paths; 388 return bundle_paths;
389 } 389 }
390 390
391 ShellIntegration::ShortcutInfo BuildShortcutInfoFromBundle( 391 web_app::ShortcutInfo BuildShortcutInfoFromBundle(
392 const base::FilePath& bundle_path) { 392 const base::FilePath& bundle_path) {
393 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path)); 393 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path));
394 394
395 ShellIntegration::ShortcutInfo shortcut_info; 395 web_app::ShortcutInfo shortcut_info;
396 shortcut_info.extension_id = base::SysNSStringToUTF8( 396 shortcut_info.extension_id = base::SysNSStringToUTF8(
397 [plist valueForKey:app_mode::kCrAppModeShortcutIDKey]); 397 [plist valueForKey:app_mode::kCrAppModeShortcutIDKey]);
398 shortcut_info.is_platform_app = true; 398 shortcut_info.is_platform_app = true;
399 shortcut_info.url = GURL(base::SysNSStringToUTF8( 399 shortcut_info.url = GURL(base::SysNSStringToUTF8(
400 [plist valueForKey:app_mode::kCrAppModeShortcutURLKey])); 400 [plist valueForKey:app_mode::kCrAppModeShortcutURLKey]));
401 shortcut_info.title = base::SysNSStringToUTF16( 401 shortcut_info.title = base::SysNSStringToUTF16(
402 [plist valueForKey:app_mode::kCrAppModeShortcutNameKey]); 402 [plist valueForKey:app_mode::kCrAppModeShortcutNameKey]);
403 shortcut_info.profile_name = base::SysNSStringToUTF8( 403 shortcut_info.profile_name = base::SysNSStringToUTF8(
404 [plist valueForKey:app_mode::kCrAppModeProfileNameKey]); 404 [plist valueForKey:app_mode::kCrAppModeProfileNameKey]);
405 405
(...skipping 15 matching lines...) Expand all
421 421
422 namespace chrome { 422 namespace chrome {
423 423
424 void ShowCreateChromeAppShortcutsDialog(gfx::NativeWindow /*parent_window*/, 424 void ShowCreateChromeAppShortcutsDialog(gfx::NativeWindow /*parent_window*/,
425 Profile* profile, 425 Profile* profile,
426 const extensions::Extension* app, 426 const extensions::Extension* app,
427 const base::Closure& close_callback) { 427 const base::Closure& close_callback) {
428 // Normally we would show a dialog, but since we always create the app 428 // Normally we would show a dialog, but since we always create the app
429 // shortcut in ~/Applications there are no options for the user to choose. 429 // shortcut in ~/Applications there are no options for the user to choose.
430 web_app::CreateShortcuts(web_app::SHORTCUT_CREATION_BY_USER, 430 web_app::CreateShortcuts(web_app::SHORTCUT_CREATION_BY_USER,
431 ShellIntegration::ShortcutLocations(), 431 web_app::ShortcutLocations(),
432 profile, 432 profile,
433 app); 433 app);
434 if (!close_callback.is_null()) 434 if (!close_callback.is_null())
435 close_callback.Run(); 435 close_callback.Run();
436 } 436 }
437 437
438 } // namespace chrome 438 } // namespace chrome
439 439
440 namespace web_app { 440 namespace web_app {
441 441
442 WebAppShortcutCreator::WebAppShortcutCreator( 442 WebAppShortcutCreator::WebAppShortcutCreator(
443 const base::FilePath& app_data_dir, 443 const base::FilePath& app_data_dir,
444 const ShellIntegration::ShortcutInfo& shortcut_info) 444 const web_app::ShortcutInfo& shortcut_info)
445 : app_data_dir_(app_data_dir), 445 : app_data_dir_(app_data_dir),
446 info_(shortcut_info) {} 446 info_(shortcut_info) {}
447 447
448 WebAppShortcutCreator::~WebAppShortcutCreator() {} 448 WebAppShortcutCreator::~WebAppShortcutCreator() {}
449 449
450 base::FilePath WebAppShortcutCreator::GetApplicationsShortcutPath() const { 450 base::FilePath WebAppShortcutCreator::GetApplicationsShortcutPath() const {
451 base::FilePath applications_dir = GetApplicationsDirname(); 451 base::FilePath applications_dir = GetApplicationsDirname();
452 return applications_dir.empty() ? 452 return applications_dir.empty() ?
453 base::FilePath() : applications_dir.Append(GetShortcutBasename()); 453 base::FilePath() : applications_dir.Append(GetShortcutBasename());
454 } 454 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 514
515 base::mac::RemoveQuarantineAttribute(dst_path.Append(app_name)); 515 base::mac::RemoveQuarantineAttribute(dst_path.Append(app_name));
516 ++succeeded; 516 ++succeeded;
517 } 517 }
518 518
519 return succeeded; 519 return succeeded;
520 } 520 }
521 521
522 bool WebAppShortcutCreator::CreateShortcuts( 522 bool WebAppShortcutCreator::CreateShortcuts(
523 ShortcutCreationReason creation_reason, 523 ShortcutCreationReason creation_reason,
524 ShellIntegration::ShortcutLocations creation_locations) { 524 web_app::ShortcutLocations creation_locations) {
525 const base::FilePath applications_dir = GetApplicationsDirname(); 525 const base::FilePath applications_dir = GetApplicationsDirname();
526 if (applications_dir.empty() || 526 if (applications_dir.empty() ||
527 !base::DirectoryExists(applications_dir.DirName())) { 527 !base::DirectoryExists(applications_dir.DirName())) {
528 LOG(ERROR) << "Couldn't find an Applications directory to copy app to."; 528 LOG(ERROR) << "Couldn't find an Applications directory to copy app to.";
529 return false; 529 return false;
530 } 530 }
531 531
532 UpdateAppShortcutsSubdirLocalizedName(applications_dir); 532 UpdateAppShortcutsSubdirLocalizedName(applications_dir);
533 533
534 // If non-nil, this path is added to the OSX Dock after creating shortcuts. 534 // If non-nil, this path is added to the OSX Dock after creating shortcuts.
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 base::FilePath app_path = GetApplicationsShortcutPath(); 787 base::FilePath app_path = GetApplicationsShortcutPath();
788 if (app_path.empty()) 788 if (app_path.empty())
789 return; 789 return;
790 790
791 [[NSWorkspace sharedWorkspace] 791 [[NSWorkspace sharedWorkspace]
792 selectFile:base::mac::FilePathToNSString(app_path) 792 selectFile:base::mac::FilePathToNSString(app_path)
793 inFileViewerRootedAtPath:nil]; 793 inFileViewerRootedAtPath:nil];
794 } 794 }
795 795
796 base::FilePath GetAppInstallPath( 796 base::FilePath GetAppInstallPath(
797 const ShellIntegration::ShortcutInfo& shortcut_info) { 797 const web_app::ShortcutInfo& shortcut_info) {
798 WebAppShortcutCreator shortcut_creator(base::FilePath(), shortcut_info); 798 WebAppShortcutCreator shortcut_creator(base::FilePath(), shortcut_info);
799 return shortcut_creator.GetApplicationsShortcutPath(); 799 return shortcut_creator.GetApplicationsShortcutPath();
800 } 800 }
801 801
802 void MaybeLaunchShortcut(const ShellIntegration::ShortcutInfo& shortcut_info) { 802 void MaybeLaunchShortcut(const web_app::ShortcutInfo& shortcut_info) {
803 if (!apps::IsAppShimsEnabled()) 803 if (!apps::IsAppShimsEnabled())
804 return; 804 return;
805 805
806 content::BrowserThread::PostTask( 806 content::BrowserThread::PostTask(
807 content::BrowserThread::FILE, FROM_HERE, 807 content::BrowserThread::FILE, FROM_HERE,
808 base::Bind(&LaunchShimOnFileThread, shortcut_info)); 808 base::Bind(&LaunchShimOnFileThread, shortcut_info));
809 } 809 }
810 810
811 namespace internals { 811 namespace internals {
812 812
813 bool CreatePlatformShortcuts( 813 bool CreatePlatformShortcuts(
814 const base::FilePath& app_data_path, 814 const base::FilePath& app_data_path,
815 const ShellIntegration::ShortcutInfo& shortcut_info, 815 const web_app::ShortcutInfo& shortcut_info,
816 const ShellIntegration::ShortcutLocations& creation_locations, 816 const web_app::ShortcutLocations& creation_locations,
817 ShortcutCreationReason creation_reason) { 817 ShortcutCreationReason creation_reason) {
818 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 818 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
819 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); 819 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info);
820 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); 820 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations);
821 } 821 }
822 822
823 void DeletePlatformShortcuts( 823 void DeletePlatformShortcuts(
824 const base::FilePath& app_data_path, 824 const base::FilePath& app_data_path,
825 const ShellIntegration::ShortcutInfo& shortcut_info) { 825 const web_app::ShortcutInfo& shortcut_info) {
826 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 826 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
827 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); 827 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info);
828 shortcut_creator.DeleteShortcuts(); 828 shortcut_creator.DeleteShortcuts();
829 } 829 }
830 830
831 void UpdatePlatformShortcuts( 831 void UpdatePlatformShortcuts(
832 const base::FilePath& app_data_path, 832 const base::FilePath& app_data_path,
833 const base::string16& old_app_title, 833 const base::string16& old_app_title,
834 const ShellIntegration::ShortcutInfo& shortcut_info) { 834 const web_app::ShortcutInfo& shortcut_info) {
835 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 835 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
836 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); 836 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info);
837 shortcut_creator.UpdateShortcuts(); 837 shortcut_creator.UpdateShortcuts();
838 } 838 }
839 839
840 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { 840 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) {
841 const std::string profile_base_name = profile_path.BaseName().value(); 841 const std::string profile_base_name = profile_path.BaseName().value();
842 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( 842 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath(
843 profile_path.Append(chrome::kWebAppDirname), profile_base_name); 843 profile_path.Append(chrome::kWebAppDirname), profile_base_name);
844 844
845 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); 845 for (std::vector<base::FilePath>::const_iterator it = bundles.begin();
846 it != bundles.end(); ++it) { 846 it != bundles.end(); ++it) {
847 ShellIntegration::ShortcutInfo shortcut_info = 847 web_app::ShortcutInfo shortcut_info =
848 BuildShortcutInfoFromBundle(*it); 848 BuildShortcutInfoFromBundle(*it);
849 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info); 849 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info);
850 shortcut_creator.DeleteShortcuts(); 850 shortcut_creator.DeleteShortcuts();
851 } 851 }
852 } 852 }
853 853
854 } // namespace internals 854 } // namespace internals
855 855
856 } // namespace web_app 856 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698