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

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

Issue 64803005: File association for app shims. (Mac) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missed a comma. Created 6 years, 7 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 base::FilePath profile_base_name = base::mac::NSStringToFilePath( 411 base::FilePath profile_base_name = base::mac::NSStringToFilePath(
412 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]); 412 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]);
413 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name) 413 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name)
414 shortcut_info.profile_path = user_data_dir.DirName().DirName(); 414 shortcut_info.profile_path = user_data_dir.DirName().DirName();
415 else 415 else
416 shortcut_info.profile_path = user_data_dir.Append(profile_base_name); 416 shortcut_info.profile_path = user_data_dir.Append(profile_base_name);
417 417
418 return shortcut_info; 418 return shortcut_info;
419 } 419 }
420 420
421 void UpdateFileTypes(NSMutableDictionary* plist,
422 const extensions::FileHandlersInfo& file_handlers_info) {
423 const std::vector<extensions::FileHandlerInfo>& handlers =
424 file_handlers_info.handlers;
425 NSMutableArray* document_types =
426 [NSMutableArray arrayWithCapacity:handlers.size()];
427
428 for (std::vector<extensions::FileHandlerInfo>::const_iterator info_it =
429 handlers.begin();
430 info_it != handlers.end();
431 ++info_it) {
432 const extensions::FileHandlerInfo& info = *info_it;
433
434 NSMutableArray* file_extensions =
435 [NSMutableArray arrayWithCapacity:info.extensions.size()];
436 for (std::set<std::string>::iterator it = info.extensions.begin();
437 it != info.extensions.end();
438 ++it) {
439 [file_extensions addObject:base::SysUTF8ToNSString(*it)];
440 }
441
442 NSMutableArray* mime_types =
443 [NSMutableArray arrayWithCapacity:info.types.size()];
444 for (std::set<std::string>::iterator it = info.types.begin();
445 it != info.types.end();
446 ++it) {
447 [mime_types addObject:base::SysUTF8ToNSString(*it)];
448 }
449
450 NSDictionary* type_dictionary = @{
451 // TODO(jackhou): Add the type name and and icon file once the manifest
452 // supports these.
453 // app_mode::kCFBundleTypeNameKey : ,
454 // app_mode::kCFBundleTypeIconFileKey : ,
455 app_mode::kCFBundleTypeExtensionsKey : file_extensions,
456 app_mode::kCFBundleTypeMIMETypesKey : mime_types,
457 app_mode::kCFBundleTypeRoleKey : app_mode::kBundleTypeRoleViewer
458 };
459 [document_types addObject:type_dictionary];
460 }
461
462 [plist setObject:document_types
463 forKey:app_mode::kCFBundleDocumentTypesKey];
464 }
465
421 } // namespace 466 } // namespace
422 467
423 namespace chrome { 468 namespace chrome {
424 469
425 void ShowCreateChromeAppShortcutsDialog(gfx::NativeWindow /*parent_window*/, 470 void ShowCreateChromeAppShortcutsDialog(gfx::NativeWindow /*parent_window*/,
426 Profile* profile, 471 Profile* profile,
427 const extensions::Extension* app, 472 const extensions::Extension* app,
428 const base::Closure& close_callback) { 473 const base::Closure& close_callback) {
429 // Normally we would show a dialog, but since we always create the app 474 // Normally we would show a dialog, but since we always create the app
430 // shortcut in ~/Applications there are no options for the user to choose. 475 // shortcut in ~/Applications there are no options for the user to choose.
431 web_app::CreateShortcuts(web_app::SHORTCUT_CREATION_BY_USER, 476 web_app::CreateShortcuts(web_app::SHORTCUT_CREATION_BY_USER,
432 web_app::ShortcutLocations(), 477 web_app::ShortcutLocations(),
433 profile, 478 profile,
434 app); 479 app);
435 if (!close_callback.is_null()) 480 if (!close_callback.is_null())
436 close_callback.Run(); 481 close_callback.Run();
437 } 482 }
438 483
439 } // namespace chrome 484 } // namespace chrome
440 485
441 namespace web_app { 486 namespace web_app {
442 487
443 WebAppShortcutCreator::WebAppShortcutCreator( 488 WebAppShortcutCreator::WebAppShortcutCreator(
444 const base::FilePath& app_data_dir, 489 const base::FilePath& app_data_dir,
445 const web_app::ShortcutInfo& shortcut_info) 490 const web_app::ShortcutInfo& shortcut_info,
491 const extensions::FileHandlersInfo& file_handlers_info)
446 : app_data_dir_(app_data_dir), 492 : app_data_dir_(app_data_dir),
447 info_(shortcut_info) {} 493 info_(shortcut_info),
494 file_handlers_info_(file_handlers_info) {}
448 495
449 WebAppShortcutCreator::~WebAppShortcutCreator() {} 496 WebAppShortcutCreator::~WebAppShortcutCreator() {}
450 497
451 base::FilePath WebAppShortcutCreator::GetApplicationsShortcutPath() const { 498 base::FilePath WebAppShortcutCreator::GetApplicationsShortcutPath() const {
452 base::FilePath applications_dir = GetApplicationsDirname(); 499 base::FilePath applications_dir = GetApplicationsDirname();
453 return applications_dir.empty() ? 500 return applications_dir.empty() ?
454 base::FilePath() : applications_dir.Append(GetShortcutBasename()); 501 base::FilePath() : applications_dir.Append(GetShortcutBasename());
455 } 502 }
456 503
457 base::FilePath WebAppShortcutCreator::GetInternalShortcutPath() const { 504 base::FilePath WebAppShortcutCreator::GetInternalShortcutPath() const {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 if (info_.extension_id == app_mode::kAppListModeId) { 719 if (info_.extension_id == app_mode::kAppListModeId) {
673 // Prevent the app list from bouncing in the dock, and getting a run light. 720 // Prevent the app list from bouncing in the dock, and getting a run light.
674 [plist setObject:[NSNumber numberWithBool:YES] 721 [plist setObject:[NSNumber numberWithBool:YES]
675 forKey:kLSUIElement]; 722 forKey:kLSUIElement];
676 } 723 }
677 724
678 base::FilePath app_name = app_path.BaseName().RemoveExtension(); 725 base::FilePath app_name = app_path.BaseName().RemoveExtension();
679 [plist setObject:base::mac::FilePathToNSString(app_name) 726 [plist setObject:base::mac::FilePathToNSString(app_name)
680 forKey:base::mac::CFToNSCast(kCFBundleNameKey)]; 727 forKey:base::mac::CFToNSCast(kCFBundleNameKey)];
681 728
729 if (CommandLine::ForCurrentProcess()->HasSwitch(
730 switches::kEnableAppsFileAssociations)) {
731 UpdateFileTypes(plist, file_handlers_info_);
732 }
733
682 return [plist writeToFile:plist_path 734 return [plist writeToFile:plist_path
683 atomically:YES]; 735 atomically:YES];
684 } 736 }
685 737
686 bool WebAppShortcutCreator::UpdateDisplayName( 738 bool WebAppShortcutCreator::UpdateDisplayName(
687 const base::FilePath& app_path) const { 739 const base::FilePath& app_path) const {
688 // OSX searches for the best language in the order of preferred languages. 740 // OSX searches for the best language in the order of preferred languages.
689 // Since we only have one localization directory, it will choose this one. 741 // Since we only have one localization directory, it will choose this one.
690 base::FilePath localized_dir = GetResourcesPath(app_path).Append("en.lproj"); 742 base::FilePath localized_dir = GetResourcesPath(app_path).Append("en.lproj");
691 if (!base::CreateDirectory(localized_dir)) 743 if (!base::CreateDirectory(localized_dir))
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 if (app_path.empty()) 841 if (app_path.empty())
790 return; 842 return;
791 843
792 [[NSWorkspace sharedWorkspace] 844 [[NSWorkspace sharedWorkspace]
793 selectFile:base::mac::FilePathToNSString(app_path) 845 selectFile:base::mac::FilePathToNSString(app_path)
794 inFileViewerRootedAtPath:nil]; 846 inFileViewerRootedAtPath:nil];
795 } 847 }
796 848
797 base::FilePath GetAppInstallPath( 849 base::FilePath GetAppInstallPath(
798 const web_app::ShortcutInfo& shortcut_info) { 850 const web_app::ShortcutInfo& shortcut_info) {
799 WebAppShortcutCreator shortcut_creator(base::FilePath(), shortcut_info); 851 WebAppShortcutCreator shortcut_creator(
852 base::FilePath(), shortcut_info, extensions::FileHandlersInfo());
800 return shortcut_creator.GetApplicationsShortcutPath(); 853 return shortcut_creator.GetApplicationsShortcutPath();
801 } 854 }
802 855
803 void MaybeLaunchShortcut(const web_app::ShortcutInfo& shortcut_info) { 856 void MaybeLaunchShortcut(const web_app::ShortcutInfo& shortcut_info) {
804 if (!apps::IsAppShimsEnabled()) 857 if (!apps::IsAppShimsEnabled())
805 return; 858 return;
806 859
807 content::BrowserThread::PostTask( 860 content::BrowserThread::PostTask(
808 content::BrowserThread::FILE, FROM_HERE, 861 content::BrowserThread::FILE, FROM_HERE,
809 base::Bind(&LaunchShimOnFileThread, shortcut_info)); 862 base::Bind(&LaunchShimOnFileThread, shortcut_info));
810 } 863 }
811 864
812 namespace internals { 865 namespace internals {
813 866
814 bool CreatePlatformShortcuts( 867 bool CreatePlatformShortcuts(
815 const base::FilePath& app_data_path, 868 const base::FilePath& app_data_path,
816 const web_app::ShortcutInfo& shortcut_info, 869 const web_app::ShortcutInfo& shortcut_info,
817 const extensions::FileHandlersInfo& file_handlers_info, 870 const extensions::FileHandlersInfo& file_handlers_info,
818 const web_app::ShortcutLocations& creation_locations, 871 const web_app::ShortcutLocations& creation_locations,
819 ShortcutCreationReason creation_reason) { 872 ShortcutCreationReason creation_reason) {
820 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 873 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
821 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); 874 WebAppShortcutCreator shortcut_creator(
875 app_data_path, shortcut_info, file_handlers_info);
822 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); 876 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations);
823 } 877 }
824 878
825 void DeletePlatformShortcuts( 879 void DeletePlatformShortcuts(
826 const base::FilePath& app_data_path, 880 const base::FilePath& app_data_path,
827 const web_app::ShortcutInfo& shortcut_info) { 881 const web_app::ShortcutInfo& shortcut_info) {
828 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 882 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
829 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); 883 WebAppShortcutCreator shortcut_creator(
884 app_data_path, shortcut_info, extensions::FileHandlersInfo());
830 shortcut_creator.DeleteShortcuts(); 885 shortcut_creator.DeleteShortcuts();
831 } 886 }
832 887
833 void UpdatePlatformShortcuts( 888 void UpdatePlatformShortcuts(
834 const base::FilePath& app_data_path, 889 const base::FilePath& app_data_path,
835 const base::string16& old_app_title, 890 const base::string16& old_app_title,
836 const web_app::ShortcutInfo& shortcut_info, 891 const web_app::ShortcutInfo& shortcut_info,
837 const extensions::FileHandlersInfo& file_handlers_info) { 892 const extensions::FileHandlersInfo& file_handlers_info) {
838 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 893 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
839 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); 894 WebAppShortcutCreator shortcut_creator(
895 app_data_path, shortcut_info, file_handlers_info);
840 shortcut_creator.UpdateShortcuts(); 896 shortcut_creator.UpdateShortcuts();
841 } 897 }
842 898
843 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { 899 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) {
844 const std::string profile_base_name = profile_path.BaseName().value(); 900 const std::string profile_base_name = profile_path.BaseName().value();
845 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( 901 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath(
846 profile_path.Append(chrome::kWebAppDirname), profile_base_name); 902 profile_path.Append(chrome::kWebAppDirname), profile_base_name);
847 903
848 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); 904 for (std::vector<base::FilePath>::const_iterator it = bundles.begin();
849 it != bundles.end(); ++it) { 905 it != bundles.end(); ++it) {
850 web_app::ShortcutInfo shortcut_info = 906 web_app::ShortcutInfo shortcut_info =
851 BuildShortcutInfoFromBundle(*it); 907 BuildShortcutInfoFromBundle(*it);
852 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info); 908 WebAppShortcutCreator shortcut_creator(
909 it->DirName(), shortcut_info, extensions::FileHandlersInfo());
853 shortcut_creator.DeleteShortcuts(); 910 shortcut_creator.DeleteShortcuts();
854 } 911 }
855 } 912 }
856 913
857 } // namespace internals 914 } // namespace internals
858 915
859 } // namespace web_app 916 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.h ('k') | chrome/browser/web_applications/web_app_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698