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

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: Address comments. Change FileHandlersInfo to hold a copy. 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..3645d32c23659676fa002bc3dfd244892e9680ad 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -417,6 +417,49 @@ ShellIntegration::ShortcutInfo BuildShortcutInfoFromBundle(
return shortcut_info;
}
+void UpdateFileTypes(NSMutableDictionary* plist,
+ const extensions::FileHandlersInfo& file_handlers_info) {
+ const std::vector<extensions::FileHandlerInfo>& handlers =
+ file_handlers_info.handlers;
+ NSMutableArray* document_types =
+ [NSMutableArray arrayWithCapacity:handlers.size()];
+
+ for (std::vector<extensions::FileHandlerInfo>::const_iterator info_it =
+ handlers.begin();
+ info_it != handlers.end();
+ ++info_it) {
+ const extensions::FileHandlerInfo& info = *info_it;
+
+ NSMutableArray* file_extensions =
+ [NSMutableArray arrayWithCapacity:info.extensions.size()];
+ 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 arrayWithCapacity:info.types.size()];
+ for (std::set<std::string>::iterator it = info.types.begin();
+ it != info.types.end(); ++it) {
+ [mime_types addObject:base::SysUTF8ToNSString(*it)];
+ }
+
+ NSDictionary* type_dictionary = @{
+ // TODO(jackhou): Add the type name and and icon file once the manifest
+ // supports these.
+ // app_mode::kCFBundleTypeNameKey : ,
+ // app_mode::kCFBundleTypeIconFileKey : ,
+ app_mode::kCFBundleTypeExtensionsKey : file_extensions,
+ app_mode::kCFBundleTypeMIMETypesKey : mime_types,
+ app_mode::kCFBundleTypeRoleKey : app_mode::kBundleTypeRoleViewer
+ };
+ [document_types addObject:type_dictionary];
+ }
+
+ [plist setObject:document_types
+ forKey:app_mode::kCFBundleDocumentTypesKey];
+}
+
} // namespace
namespace chrome {
@@ -441,9 +484,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() {}
@@ -678,6 +723,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 +845,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 +868,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 +877,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 +888,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 +902,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