OLD | NEW |
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" |
11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 13 #include "base/mac/mac_logging.h" |
13 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
| 15 #include "base/mac/scoped_cftyperef.h" |
14 #include "base/memory/scoped_nsobject.h" | 16 #include "base/memory/scoped_nsobject.h" |
15 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
16 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/web_applications/web_app.h" | 19 #include "chrome/browser/web_applications/web_app.h" |
18 #include "chrome/common/chrome_paths_internal.h" | 20 #include "chrome/common/chrome_paths_internal.h" |
19 #include "chrome/common/mac/app_mode_common.h" | 21 #include "chrome/common/mac/app_mode_common.h" |
20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
21 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
22 #include "skia/ext/skia_utils_mac.h" | 24 #include "skia/ext/skia_utils_mac.h" |
23 #include "third_party/icon_family/IconFamily.h" | 25 #include "third_party/icon_family/IconFamily.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 selectFile:base::mac::FilePathToNSString(generated_bundle) | 251 selectFile:base::mac::FilePathToNSString(generated_bundle) |
250 inFileViewerRootedAtPath:nil]; | 252 inFileViewerRootedAtPath:nil]; |
251 } | 253 } |
252 | 254 |
253 } // namespace | 255 } // namespace |
254 | 256 |
255 namespace web_app { | 257 namespace web_app { |
256 | 258 |
257 namespace internals { | 259 namespace internals { |
258 | 260 |
| 261 FilePath GetAppBundleByExtensionId(std::string extension_id) { |
| 262 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 263 // This matches APP_MODE_APP_BUNDLE_ID in chrome/chrome.gyp. |
| 264 std::string bundle_id = |
| 265 base::mac::BaseBundleID() + std::string(".app.") + extension_id; |
| 266 base::mac::ScopedCFTypeRef<CFStringRef> bundle_id_cf( |
| 267 base::SysUTF8ToCFStringRef(bundle_id)); |
| 268 CFURLRef url_ref = NULL; |
| 269 OSStatus status = LSFindApplicationForInfo( |
| 270 kLSUnknownCreator, bundle_id_cf.get(), NULL, NULL, &url_ref); |
| 271 base::mac::ScopedCFTypeRef<CFURLRef> url(url_ref); |
| 272 |
| 273 if (status != noErr) |
| 274 return FilePath(); |
| 275 |
| 276 NSString* path_string = [base::mac::CFToNSCast(url.get()) path]; |
| 277 return FilePath([path_string fileSystemRepresentation]); |
| 278 } |
| 279 |
259 bool CreatePlatformShortcuts( | 280 bool CreatePlatformShortcuts( |
260 const base::FilePath& web_app_path, | 281 const base::FilePath& web_app_path, |
261 const ShellIntegration::ShortcutInfo& shortcut_info) { | 282 const ShellIntegration::ShortcutInfo& shortcut_info) { |
262 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 283 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
263 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID()); | 284 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID()); |
264 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info, | 285 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info, |
265 bundle_id); | 286 bundle_id); |
266 return shortcut_creator.CreateShortcut(); | 287 return shortcut_creator.CreateShortcut(); |
267 } | 288 } |
268 | 289 |
269 void DeletePlatformShortcuts( | 290 void DeletePlatformShortcuts( |
270 const base::FilePath& web_app_path, | 291 const base::FilePath& web_app_path, |
271 const ShellIntegration::ShortcutInfo& shortcut_info) { | 292 const ShellIntegration::ShortcutInfo& info) { |
272 // TODO(benwells): Implement this when shortcuts / weblings are enabled on | 293 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
273 // mac. | 294 |
| 295 FilePath bundle_path = GetAppBundleByExtensionId(info.extension_id); |
| 296 file_util::Delete(bundle_path, true); |
274 } | 297 } |
275 | 298 |
276 void UpdatePlatformShortcuts( | 299 void UpdatePlatformShortcuts( |
277 const base::FilePath& web_app_path, | 300 const base::FilePath& web_app_path, |
278 const ShellIntegration::ShortcutInfo& shortcut_info) { | 301 const ShellIntegration::ShortcutInfo& shortcut_info) { |
279 // TODO(benwells): Implement this when shortcuts / weblings are enabled on | 302 // TODO(benwells): Implement this when shortcuts / weblings are enabled on |
280 // mac. | 303 // mac. |
281 } | 304 } |
282 | 305 |
283 } // namespace internals | 306 } // namespace internals |
284 | 307 |
285 } // namespace web_app | 308 } // namespace web_app |
OLD | NEW |