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

Unified Diff: chrome/browser/web_applications/web_app_mac.mm

Issue 9426030: Mac: Enable WebAppShortcutCreatorTest.CreateShortcut unit test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for landing Created 8 years, 10 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 33adce3ce5b7d9426374cc5eef6d0621a8211262..004f8d4ec7b7aa02e72603944eda5c60b30f6ad2 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -80,9 +80,8 @@ bool WebAppShortcutCreator::CreateShortcut() {
return false;
}
- [[NSWorkspace sharedWorkspace]
- selectFile:base::mac::FilePathToNSString(dst_path)
- inFileViewerRootedAtPath:nil];
+ RevealGeneratedBundleInFinder(dst_path);
+
return true;
}
@@ -108,24 +107,46 @@ FilePath WebAppShortcutCreator::GetDestinationPath(
bool WebAppShortcutCreator::UpdatePlist(const FilePath& app_path) const {
NSString* plist_path = base::mac::FilePathToNSString(
app_path.Append("Contents").Append("Info.plist"));
- NSMutableDictionary* dict =
+
+ NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id);
+ NSString* extension_title = base::SysUTF16ToNSString(info_.title);
+ NSString* extension_url = base::SysUTF8ToNSString(info_.url.spec());
+ NSString* chrome_bundle_id = base::SysUTF16ToNSString(chrome_bundle_id_);
+ NSDictionary* replacement_dict =
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ extension_id, app_mode::kShortcutIdPlaceholder,
+ extension_title, app_mode::kShortcutNamePlaceholder,
+ extension_url, app_mode::kShortcutURLPlaceholder,
+ chrome_bundle_id, app_mode::kShortcutBrowserBundleIDPlaceholder,
+ nil];
+
+ NSMutableDictionary* plist =
[NSMutableDictionary dictionaryWithContentsOfFile:plist_path];
+ NSArray* keys = [plist allKeys];
+
+ // 1. Fill in variables.
+ for (id key in keys) {
+ NSString* value = [plist valueForKey:key];
+ if (![value isKindOfClass:[NSString class]] || [value length] < 2)
+ continue;
+
+ // Remove leading and trailing '@'s.
+ NSString* variable =
+ [value substringWithRange:NSMakeRange(1, [value length] - 2)];
- [dict setObject:GetBundleIdentifier(dict)
- forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)];
- [dict setObject:base::SysUTF8ToNSString(info_.extension_id)
- forKey:app_mode::kCrAppModeShortcutIDKey];
- [dict setObject:base::SysUTF16ToNSString(info_.title)
- forKey:app_mode::kCrAppModeShortcutNameKey];
- [dict setObject:base::SysUTF8ToNSString(info_.url.spec())
- forKey:app_mode::kCrAppModeShortcutURLKey];
- [dict setObject:base::mac::FilePathToNSString(user_data_dir_)
- forKey:app_mode::kCrAppModeUserDataDirKey];
- [dict setObject:base::mac::FilePathToNSString(info_.extension_path)
- forKey:app_mode::kCrAppModeExtensionPathKey];
- [dict setObject:base::SysUTF16ToNSString(chrome_bundle_id_)
- forKey:app_mode::kBrowserBundleIDKey];
- return [dict writeToFile:plist_path atomically:YES];
+ NSString* substitution = [replacement_dict valueForKey:variable];
+ if (substitution)
+ [plist setObject:substitution forKey:key];
+ }
+
+ // 2. Fill in other values.
+ [plist setObject:GetBundleIdentifier(plist)
+ forKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)];
+ [plist setObject:base::mac::FilePathToNSString(user_data_dir_)
+ forKey:app_mode::kCrAppModeUserDataDirKey];
+ [plist setObject:base::mac::FilePathToNSString(info_.extension_path)
+ forKey:app_mode::kCrAppModeExtensionPathKey];
+ return [plist writeToFile:plist_path atomically:YES];
}
bool WebAppShortcutCreator::UpdateIcon(const FilePath& app_path) const {
@@ -173,6 +194,13 @@ NSString* WebAppShortcutCreator::GetBundleIdentifier(NSDictionary* plist) const
return bundle_id;
}
+void WebAppShortcutCreator::RevealGeneratedBundleInFinder(
+ const FilePath& generated_bundle) const {
+ [[NSWorkspace sharedWorkspace]
+ selectFile:base::mac::FilePathToNSString(generated_bundle)
+ inFileViewerRootedAtPath:nil];
+}
+
} // namespace
namespace web_app {
« 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