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

Unified 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: Redo after refactoring. Put behind flag. Tests. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/web_applications/web_app_mac.mm
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
index 28ad88595f88bd172c1e6aa39cea7c75f0d00c64..fa3673b829b83901fc3ba2c0ebfda9b2d0bbd1b7 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -441,9 +441,11 @@ namespace web_app {
WebAppShortcutCreator::WebAppShortcutCreator(
const base::FilePath& app_data_dir,
- const ShellIntegration::ShortcutInfo& shortcut_info)
+ const ShellIntegration::ShortcutInfo& shortcut_info,
+ const extensions::FileHandlersInfo& file_handlers_info)
: app_data_dir_(app_data_dir),
- info_(shortcut_info) {}
+ info_(shortcut_info),
+ file_handlers_info_(file_handlers_info) {}
WebAppShortcutCreator::~WebAppShortcutCreator() {}
@@ -624,6 +626,41 @@ base::FilePath WebAppShortcutCreator::GetApplicationsDirname() const {
return path.Append(GetLocalizableAppShortcutsSubdirName());
}
+void UpdateFileTypes(NSMutableDictionary* plist,
tapted 2014/04/17 04:37:50 move to anonymous namespace
jackhou1 2014/04/22 04:40:19 Done.
+ const extensions::FileHandlersInfo& file_handlers_info) {
+ NSMutableArray* document_types = [NSMutableArray array];
tapted 2014/04/17 04:37:50 I think +[.. array] is only defined on NSArray.. M
jackhou1 2014/04/22 04:40:19 Done.
+
+ for (unsigned int i = 0; i < file_handlers_info.handlers->size(); ++i) {
tapted 2014/04/17 04:37:50 vector::const_iterator?
jackhou1 2014/04/22 04:40:19 Done.
+ const extensions::FileHandlerInfo& info =
+ file_handlers_info.handlers->at(i);
+
+ NSMutableArray* file_extensions = [NSMutableArray array];
+ for (std::set<std::string>::iterator it = info.extensions.begin();
+ it != info.extensions.end(); ++it) {
+ [file_extensions addObject:base::SysUTF8ToNSString(*it)];
+ }
+
+ NSMutableArray* mime_types = [NSMutableArray array];
+ for (std::set<std::string>::iterator it = info.types.begin();
+ it != info.types.end(); ++it) {
+ [mime_types addObject:base::SysUTF8ToNSString(*it)];
+ }
+
+ [document_types addObject:@{
+ // TODO(jackhou): Add the type name and and icon file once the manifest
tapted 2014/04/17 04:37:50 nit: This.. probably needs more indent because it'
jackhou1 2014/04/22 04:40:19 Done.
+ // supports these.
+ // app_mode::kCFBundleTypeNameKey : ,
+ // app_mode::kCFBundleTypeIconFileKey : ,
+ app_mode::kCFBundleTypeExtensionsKey : file_extensions,
+ app_mode::kCFBundleTypeMIMETypesKey : mime_types,
+ app_mode::kCFBundleTypeRoleKey : app_mode::kBundleTypeRoleViewer,
tapted 2014/04/17 04:37:50 nit: not sure if style guide encourages a trailing
jackhou1 2014/04/22 04:40:19 Checked style guide. It's not explicit, but all ex
+ }];
+ }
+
+ [plist setObject:document_types
+ forKey:app_mode::kCFBundleDocumentTypesKey];
+}
+
bool WebAppShortcutCreator::UpdatePlist(const base::FilePath& app_path) const {
NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id);
NSString* extension_title = base::SysUTF16ToNSString(info_.title);
@@ -678,6 +715,11 @@ bool WebAppShortcutCreator::UpdatePlist(const base::FilePath& app_path) const {
[plist setObject:base::mac::FilePathToNSString(app_name)
forKey:base::mac::CFToNSCast(kCFBundleNameKey)];
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableAppsFileAssociations)) {
+ UpdateFileTypes(plist, file_handlers_info_);
+ }
+
return [plist writeToFile:plist_path
atomically:YES];
}
@@ -795,7 +837,8 @@ void WebAppShortcutCreator::RevealAppShimInFinder() const {
base::FilePath GetAppInstallPath(
const ShellIntegration::ShortcutInfo& shortcut_info) {
- WebAppShortcutCreator shortcut_creator(base::FilePath(), shortcut_info);
+ WebAppShortcutCreator shortcut_creator(
+ base::FilePath(), shortcut_info, extensions::FileHandlersInfo(NULL));
return shortcut_creator.GetApplicationsShortcutPath();
}
@@ -817,7 +860,8 @@ bool CreatePlatformShortcuts(
const ShellIntegration::ShortcutLocations& creation_locations,
ShortcutCreationReason creation_reason) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
- WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info);
+ WebAppShortcutCreator shortcut_creator(
+ app_data_path, shortcut_info, file_handlers_info);
return shortcut_creator.CreateShortcuts(creation_reason, creation_locations);
}
@@ -825,7 +869,8 @@ void DeletePlatformShortcuts(
const base::FilePath& app_data_path,
const ShellIntegration::ShortcutInfo& shortcut_info) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
- WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info);
+ WebAppShortcutCreator shortcut_creator(
+ app_data_path, shortcut_info, extensions::FileHandlersInfo(NULL));
shortcut_creator.DeleteShortcuts();
}
@@ -835,7 +880,8 @@ void UpdatePlatformShortcuts(
const ShellIntegration::ShortcutInfo& shortcut_info,
const extensions::FileHandlersInfo& file_handlers_info) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
- WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info);
+ WebAppShortcutCreator shortcut_creator(
+ app_data_path, shortcut_info, file_handlers_info);
shortcut_creator.UpdateShortcuts();
}
@@ -848,7 +894,8 @@ void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) {
it != bundles.end(); ++it) {
ShellIntegration::ShortcutInfo shortcut_info =
BuildShortcutInfoFromBundle(*it);
- WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info);
+ WebAppShortcutCreator shortcut_creator(
+ it->DirName(), shortcut_info, extensions::FileHandlersInfo(NULL));
shortcut_creator.DeleteShortcuts();
}
}

Powered by Google App Engine
This is Rietveld 408576698