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

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

Issue 9346013: Publish app shortcuts on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <Cocoa/Cocoa.h>
6
7 #include "chrome/browser/web_applications/web_app.h"
8
9 #include "base/file_util.h"
10 #include "base/mac/bundle_locations.h"
11 #include "base/mac/foundation_util.h"
12 #include "base/scoped_temp_dir.h"
13 #include "base/sys_string_conversions.h"
14 #include "chrome/common/mac/app_mode_common.h"
15 #include "grit/chromium_strings.h"
16 #include "ui/base/l10n/l10n_util_mac.h"
17
18 namespace {
19
20 FilePath GetAppLoaderPath() {
21 NSString* app_loader = [l10n_util::GetNSString(IDS_PRODUCT_NAME)
22 stringByAppendingString:@" App Mode Loader.app"];
Robert Sesek 2012/02/08 00:59:38 Localization?
sail 2012/02/08 01:47:20 This is the hardcoded app name. It's not visible t
23 return base::mac::PathForFrameworkBundleResource((CFStringRef)app_loader);
Robert Sesek 2012/02/08 00:59:38 base::mac::NSToCFCast
sail 2012/02/08 01:47:20 Done.
24 }
25
26 bool IsWritable(const FilePath& path) {
27 return [[NSFileManager defaultManager] isWritableFileAtPath:
28 base::mac::FilePathToNSString(path)];
29 }
30
31 FilePath GetDstPath() {
Robert Sesek 2012/02/08 00:59:38 What does daylight saving time has to do with this
sail 2012/02/08 01:47:20 Done.
32 FilePath path;
33 if (base::mac::GetLocalDirectory(NSApplicationDirectory, &path) &&
34 IsWritable(path)) {
35 return path;
36 }
37
38 if (base::mac::GetUserDirectory(NSApplicationDirectory, &path))
39 return path;
40
41 return FilePath();
42 }
43
44 bool UpdatePlist(const FilePath& app_path,
45 const ShellIntegration::ShortcutInfo& info) {
46 NSString* plist_path = base::mac::FilePathToNSString(
47 app_path.Append("Contents").Append("Info.plist"));
48 NSMutableDictionary* dict =
49 [NSMutableDictionary dictionaryWithContentsOfFile:plist_path];
50
51 [dict setObject:base::SysUTF8ToNSString(info.extension_id)
52 forKey:app_mode::kCrAppModeShortcutIDKey];
53 [dict setObject:base::SysUTF16ToNSString(info.title)
54 forKey:app_mode::kCrAppModeShortcutNameKey];
55 [dict setObject:base::SysUTF8ToNSString(info.url.spec())
56 forKey:app_mode::kCrAppModeShortcutURLKey];
57 return [dict writeToFile:plist_path atomically:NO];
58 }
59
60 bool UpdateIcon() {
61 // TODO:(sail) Need to implement this.
62 return true;
63 }
64
65 } // namespace
66
67 namespace web_app {
68
69 namespace internals {
70
71 void CreateShortcutTask(const FilePath& web_app_path,
72 const FilePath& profile_path,
73 const ShellIntegration::ShortcutInfo& shortcut_info) {
74 FilePath app_name = GetSanitizedFileName(shortcut_info.title);
75 FilePath app_file_name = app_name.ReplaceExtension("app");
76 ScopedTempDir scoped_temp_dir;
77 if (!scoped_temp_dir.CreateUniqueTempDir())
78 return;
79 FilePath staging_path = scoped_temp_dir.path().Append(app_file_name);
80
81 // Update the app's plist and icon in a temp directory. This works around
82 // a Finder bug where the app's icon doesn't properly update.
83 if (!file_util::CopyDirectory(GetAppLoaderPath(), staging_path, true)) {
84 LOG(ERROR) << "Copying app to staging path: " << staging_path.value()
85 << " failed";
86 return;
87 }
88
89 if (!UpdatePlist(staging_path, shortcut_info))
90 return;
91
92 if (!UpdateIcon())
93 return;
94
95 FilePath dst_path = GetDstPath().Append(app_file_name);
96 if (!file_util::CopyDirectory(staging_path, dst_path, true)) {
97 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() << " failed";
98 return;
99 }
100
101 [[NSWorkspace sharedWorkspace]
102 selectFile:base::mac::FilePathToNSString(dst_path)
Robert Sesek 2012/02/08 00:59:38 nit: just indent 4
sail 2012/02/08 01:47:20 Done.
103 inFileViewerRootedAtPath:nil];
104 }
105
106 } // namespace internals
107
108 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698