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

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

Issue 12912003: [mac] Create app shortcuts in a subfolder of /Applications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fail if dirname of chrome apps dir doesn't exist or isn't a directory. Created 7 years, 9 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 <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 fromBitmapImageRep:image_rep] && 73 fromBitmapImageRep:image_rep] &&
74 [icon_family setIconFamilyElement:kSmall8BitMask 74 [icon_family setIconFamilyElement:kSmall8BitMask
75 fromBitmapImageRep:image_rep] && 75 fromBitmapImageRep:image_rep] &&
76 [icon_family setIconFamilyElement:kSmall1BitMask 76 [icon_family setIconFamilyElement:kSmall1BitMask
77 fromBitmapImageRep:image_rep]; 77 fromBitmapImageRep:image_rep];
78 default: 78 default:
79 return false; 79 return false;
80 } 80 }
81 } 81 }
82 82
83 base::FilePath GetWritableApplicationsDirectory() {
84 base::FilePath path;
85 if (base::mac::GetLocalDirectory(NSApplicationDirectory, &path) &&
86 file_util::PathIsWritable(path)) {
87 return path;
88 }
89 if (base::mac::GetUserDirectory(NSApplicationDirectory, &path))
90 return path;
91 return base::FilePath();
92 }
93
83 } // namespace 94 } // namespace
84 95
85 96
86 namespace web_app { 97 namespace web_app {
87 98
99 const char kChromeAppDirName[] = "Chrome Apps.localized";
100
88 WebAppShortcutCreator::WebAppShortcutCreator( 101 WebAppShortcutCreator::WebAppShortcutCreator(
89 const base::FilePath& user_data_dir, 102 const base::FilePath& user_data_dir,
90 const ShellIntegration::ShortcutInfo& shortcut_info, 103 const ShellIntegration::ShortcutInfo& shortcut_info,
91 const string16& chrome_bundle_id) 104 const string16& chrome_bundle_id)
92 : user_data_dir_(user_data_dir), 105 : user_data_dir_(user_data_dir),
93 info_(shortcut_info), 106 info_(shortcut_info),
94 chrome_bundle_id_(chrome_bundle_id) { 107 chrome_bundle_id_(chrome_bundle_id) {
95 } 108 }
96 109
97 WebAppShortcutCreator::~WebAppShortcutCreator() { 110 WebAppShortcutCreator::~WebAppShortcutCreator() {
(...skipping 14 matching lines...) Expand all
112 << " failed"; 125 << " failed";
113 return false; 126 return false;
114 } 127 }
115 128
116 if (!UpdatePlist(staging_path)) 129 if (!UpdatePlist(staging_path))
117 return false; 130 return false;
118 131
119 if (!UpdateIcon(staging_path)) 132 if (!UpdateIcon(staging_path))
120 return false; 133 return false;
121 134
122 base::FilePath dst_path = GetDestinationPath(app_file_name); 135 base::FilePath dst_path = GetDestinationPath();
136 if (dst_path.empty() || !file_util::DirectoryExists(dst_path.DirName())) {
137 LOG(ERROR) << "Couldn't find an Applications directory to copy app to.";
138 return false;
139 }
140 if (!file_util::CreateDirectory(dst_path)) {
141 LOG(ERROR) << "Creating directory " << dst_path.value() << " failed.";
142 return false;
143 }
123 if (!file_util::CopyDirectory(staging_path, dst_path, true)) { 144 if (!file_util::CopyDirectory(staging_path, dst_path, true)) {
124 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() << " failed"; 145 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() << " failed";
125 return false; 146 return false;
126 } 147 }
127 148
128 dst_path = dst_path.Append(app_file_name); 149 dst_path = dst_path.Append(app_file_name);
129 base::mac::RemoveQuarantineAttribute(dst_path); 150 base::mac::RemoveQuarantineAttribute(dst_path);
130 RevealGeneratedBundleInFinder(dst_path); 151 RevealGeneratedBundleInFinder(dst_path);
131 152
132 return true; 153 return true;
133 } 154 }
134 155
135 base::FilePath WebAppShortcutCreator::GetAppLoaderPath() const { 156 base::FilePath WebAppShortcutCreator::GetAppLoaderPath() const {
136 return base::mac::PathForFrameworkBundleResource( 157 return base::mac::PathForFrameworkBundleResource(
137 base::mac::NSToCFCast(@"app_mode_loader.app")); 158 base::mac::NSToCFCast(@"app_mode_loader.app"));
138 } 159 }
139 160
140 base::FilePath WebAppShortcutCreator::GetDestinationPath( 161 base::FilePath WebAppShortcutCreator::GetDestinationPath() const {
141 const base::FilePath& app_file_name) const { 162 base::FilePath path = GetWritableApplicationsDirectory();
142 base::FilePath path; 163 if (path.empty())
143 if (base::mac::GetLocalDirectory(NSApplicationDirectory, &path) &&
144 file_util::PathIsWritable(path)) {
145 return path; 164 return path;
146 } 165 return path.Append(kChromeAppDirName);
147
148 if (base::mac::GetUserDirectory(NSApplicationDirectory, &path))
149 return path;
150
151 return base::FilePath();
152 } 166 }
153 167
154 bool WebAppShortcutCreator::UpdatePlist(const base::FilePath& app_path) const { 168 bool WebAppShortcutCreator::UpdatePlist(const base::FilePath& app_path) const {
155 NSString* plist_path = base::mac::FilePathToNSString( 169 NSString* plist_path = base::mac::FilePathToNSString(
156 app_path.Append("Contents").Append("Info.plist")); 170 app_path.Append("Contents").Append("Info.plist"));
157 171
158 NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id); 172 NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id);
159 NSString* extension_title = base::SysUTF16ToNSString(info_.title); 173 NSString* extension_title = base::SysUTF16ToNSString(info_.title);
160 NSString* extension_url = base::SysUTF8ToNSString(info_.url.spec()); 174 NSString* extension_url = base::SysUTF8ToNSString(info_.url.spec());
161 NSString* chrome_bundle_id = base::SysUTF16ToNSString(chrome_bundle_id_); 175 NSString* chrome_bundle_id = base::SysUTF16ToNSString(chrome_bundle_id_);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 void UpdatePlatformShortcuts( 314 void UpdatePlatformShortcuts(
301 const base::FilePath& web_app_path, 315 const base::FilePath& web_app_path,
302 const ShellIntegration::ShortcutInfo& shortcut_info) { 316 const ShellIntegration::ShortcutInfo& shortcut_info) {
303 // TODO(benwells): Implement this when shortcuts / weblings are enabled on 317 // TODO(benwells): Implement this when shortcuts / weblings are enabled on
304 // mac. 318 // mac.
305 } 319 }
306 320
307 } // namespace internals 321 } // namespace internals
308 322
309 } // namespace web_app 323 } // 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