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

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

Issue 15724019: Recreate shortcuts on app update. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Apps folder is app_path.DirName(), not BaseName() Created 7 years, 6 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 <Carbon/Carbon.h> 7 #import <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 221
222 if (!UpdateIcon(staging_path)) 222 if (!UpdateIcon(staging_path))
223 return false; 223 return false;
224 224
225 if (!file_util::CopyDirectory(staging_path, dst_path, true)) { 225 if (!file_util::CopyDirectory(staging_path, dst_path, true)) {
226 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() << " failed"; 226 LOG(ERROR) << "Copying app to dst path: " << dst_path.value() << " failed";
227 return false; 227 return false;
228 } 228 }
229 229
230 base::mac::RemoveQuarantineAttribute(app_path); 230 base::mac::RemoveQuarantineAttribute(app_path);
231 RevealGeneratedBundleInFinder(app_path);
232 231
233 return true; 232 return true;
234 } 233 }
235 234
236 base::FilePath WebAppShortcutCreator::GetAppLoaderPath() const { 235 base::FilePath WebAppShortcutCreator::GetAppLoaderPath() const {
237 return base::mac::PathForFrameworkBundleResource( 236 return base::mac::PathForFrameworkBundleResource(
238 base::mac::NSToCFCast(@"app_mode_loader.app")); 237 base::mac::NSToCFCast(@"app_mode_loader.app"));
239 } 238 }
240 239
241 base::FilePath WebAppShortcutCreator::GetDestinationPath() const { 240 base::FilePath WebAppShortcutCreator::GetDestinationPath() const {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id); 363 NSString* extension_id = base::SysUTF8ToNSString(info_.extension_id);
365 NSString* placeholder = 364 NSString* placeholder =
366 [NSString stringWithFormat:@"@%@@", app_mode::kShortcutIdPlaceholder]; 365 [NSString stringWithFormat:@"@%@@", app_mode::kShortcutIdPlaceholder];
367 NSString* bundle_id = 366 NSString* bundle_id =
368 [bundle_id_template 367 [bundle_id_template
369 stringByReplacingOccurrencesOfString:placeholder 368 stringByReplacingOccurrencesOfString:placeholder
370 withString:extension_id]; 369 withString:extension_id];
371 return bundle_id; 370 return bundle_id;
372 } 371 }
373 372
374 void WebAppShortcutCreator::RevealGeneratedBundleInFinder( 373 void WebAppShortcutCreator::RevealAppShimInFinder() const {
375 const base::FilePath& generated_bundle) const {
376 [[NSWorkspace sharedWorkspace] 374 [[NSWorkspace sharedWorkspace]
377 selectFile:base::mac::FilePathToNSString(generated_bundle) 375 selectFile:base::mac::FilePathToNSString(GetShortcutPath())
benwells 2013/06/13 00:09:07 GetShortcutPath can fail, so this should check it'
jackhou1 2013/06/13 01:47:42 Done.
378 inFileViewerRootedAtPath:nil]; 376 inFileViewerRootedAtPath:nil];
379 } 377 }
380 378
381 void LaunchShimOnFileThread( 379 void LaunchShimOnFileThread(
382 const ShellIntegration::ShortcutInfo& shortcut_info) { 380 const ShellIntegration::ShortcutInfo& shortcut_info) {
383 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 381 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
384 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info); 382 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info);
385 if (shim_path.empty()) 383 if (shim_path.empty())
386 return; 384 return;
387 385
(...skipping 18 matching lines...) Expand all
406 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppShims)) 404 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppShims))
407 return; 405 return;
408 406
409 content::BrowserThread::PostTask( 407 content::BrowserThread::PostTask(
410 content::BrowserThread::FILE, FROM_HERE, 408 content::BrowserThread::FILE, FROM_HERE,
411 base::Bind(&LaunchShimOnFileThread, shortcut_info)); 409 base::Bind(&LaunchShimOnFileThread, shortcut_info));
412 } 410 }
413 411
414 namespace internals { 412 namespace internals {
415 413
416 base::FilePath GetAppBundleByExtensionId(std::string extension_id) { 414 base::FilePath GetAppBundleByExtensionId(std::string extension_id) {
benwells 2013/06/13 00:09:07 This function doesn't appear to be used anymore.
jackhou1 2013/06/13 01:47:42 Removed.
417 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 415 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
418 // This matches APP_MODE_APP_BUNDLE_ID in chrome/chrome.gyp. 416 // This matches APP_MODE_APP_BUNDLE_ID in chrome/chrome.gyp.
419 std::string bundle_id = 417 std::string bundle_id =
420 base::mac::BaseBundleID() + std::string(".app.") + extension_id; 418 base::mac::BaseBundleID() + std::string(".app.") + extension_id;
421 base::mac::ScopedCFTypeRef<CFStringRef> bundle_id_cf( 419 base::mac::ScopedCFTypeRef<CFStringRef> bundle_id_cf(
422 base::SysUTF8ToCFStringRef(bundle_id)); 420 base::SysUTF8ToCFStringRef(bundle_id));
423 CFURLRef url_ref = NULL; 421 CFURLRef url_ref = NULL;
424 OSStatus status = LSFindApplicationForInfo( 422 OSStatus status = LSFindApplicationForInfo(
425 kLSUnknownCreator, bundle_id_cf.get(), NULL, NULL, &url_ref); 423 kLSUnknownCreator, bundle_id_cf.get(), NULL, NULL, &url_ref);
426 base::mac::ScopedCFTypeRef<CFURLRef> url(url_ref); 424 base::mac::ScopedCFTypeRef<CFURLRef> url(url_ref);
427 425
428 if (status != noErr) 426 if (status != noErr)
429 return base::FilePath(); 427 return base::FilePath();
430 428
431 NSString* path_string = [base::mac::CFToNSCast(url.get()) path]; 429 NSString* path_string = [base::mac::CFToNSCast(url.get()) path];
432 return base::FilePath([path_string fileSystemRepresentation]); 430 return base::FilePath([path_string fileSystemRepresentation]);
433 } 431 }
434 432
435 bool CreatePlatformShortcuts( 433 bool CreatePlatformShortcuts(
436 const base::FilePath& web_app_path, 434 const base::FilePath& web_app_path,
437 const ShellIntegration::ShortcutInfo& shortcut_info, 435 const ShellIntegration::ShortcutInfo& shortcut_info,
438 const ShellIntegration::ShortcutLocations& /*creation_locations*/) { 436 const ShellIntegration::ShortcutLocations& /*creation_locations*/) {
439 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 437 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
440 string16 bundle_id = UTF8ToUTF16(base::mac::BaseBundleID()); 438 WebAppShortcutCreator shortcut_creator(
441 WebAppShortcutCreator shortcut_creator(web_app_path, shortcut_info, 439 web_app_path, shortcut_info, UTF8ToUTF16(base::mac::BaseBundleID()));
442 bundle_id); 440 bool success = shortcut_creator.CreateShortcut();
443 return shortcut_creator.CreateShortcut(); 441 if (success)
442 shortcut_creator.RevealAppShimInFinder();
443
444 return success;
444 } 445 }
445 446
446 void DeletePlatformShortcuts( 447 void DeletePlatformShortcuts(
447 const base::FilePath& web_app_path, 448 const base::FilePath& web_app_path,
448 const ShellIntegration::ShortcutInfo& info) { 449 const ShellIntegration::ShortcutInfo& shortcut_info) {
449 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 450 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
451 WebAppShortcutCreator shortcut_creator(
452 web_app_path, shortcut_info, UTF8ToUTF16(base::mac::BaseBundleID()));
453 base::FilePath app_path = shortcut_creator.GetShortcutPath();
454 if (app_path.empty())
455 return;
450 456
451 base::FilePath bundle_path = GetAppBundleByExtensionId(info.extension_id); 457 file_util::Delete(app_path, true);
benwells 2013/06/13 00:09:07 What is the effect of replacing GetAppBundleByExte
jackhou1 2013/06/13 01:47:42 LSFindApplicationForInfo finds one app bundle that
benwells 2013/06/13 02:19:31 Your alternative sounds pretty good. Any reason no
452 file_util::Delete(bundle_path, true); 458 base::FilePath apps_folder = app_path.DirName();
459 if (file_util::IsDirectoryEmpty(apps_folder))
460 file_util::Delete(apps_folder, false);
453 } 461 }
454 462
455 void UpdatePlatformShortcuts( 463 void UpdatePlatformShortcuts(
456 const base::FilePath& web_app_path, 464 const base::FilePath& web_app_path,
457 const string16& old_app_title, 465 const string16& old_app_title,
458 const ShellIntegration::ShortcutInfo& shortcut_info) { 466 const ShellIntegration::ShortcutInfo& shortcut_info) {
459 // TODO(benwells): Implement this when shortcuts / weblings are enabled on 467 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
benwells 2013/06/13 00:09:07 Make sure you handle the shim created in the web_a
jackhou1 2013/06/13 01:47:42 I'll merge the two CLs since they touch the same f
460 // mac. 468 WebAppShortcutCreator shortcut_creator(
469 web_app_path, shortcut_info, UTF8ToUTF16(base::mac::BaseBundleID()));
470 base::FilePath app_path = shortcut_creator.GetShortcutPath();
471 if (app_path.empty())
472 return;
473
474 file_util::Delete(app_path, true);
475 shortcut_creator.CreateShortcut();
461 } 476 }
462 477
463 } // namespace internals 478 } // namespace internals
464 479
465 } // namespace web_app 480 } // 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