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

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: Address comments 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())
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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));
450 451 WebAppShortcutCreator shortcut_creator(
451 base::FilePath bundle_path = GetAppBundleByExtensionId(info.extension_id); 452 web_app_path, shortcut_info, UTF8ToUTF16(base::mac::BaseBundleID()));
452 file_util::Delete(bundle_path, true); 453 base::FilePath app_path = shortcut_creator.GetShortcutPath();
tapted 2013/06/12 08:17:52 We should check if this is empty. (say... both App
jackhou1 2013/06/12 08:30:40 Done.
454 file_util::Delete(app_path, true);
455 base::FilePath apps_folder = app_path.BaseName();
tapted 2013/06/12 08:17:52 ... this would become "." ...
jackhou1 2013/06/12 08:30:40 Done.
456 if (file_util::IsDirectoryEmpty(apps_folder))
457 file_util::Delete(apps_folder, false);
tapted 2013/06/12 08:17:52 ... and this could try to delete some random folde
jackhou1 2013/06/12 08:30:40 There's not much we can do if it did not succeed.
453 } 458 }
454 459
455 void UpdatePlatformShortcuts( 460 void UpdatePlatformShortcuts(
456 const base::FilePath& web_app_path, 461 const base::FilePath& web_app_path,
457 const string16& old_app_title, 462 const string16& /*old_app_title*/,
tapted 2013/06/12 08:17:52 nit: I like it better without this commented out ;
jackhou1 2013/06/12 08:30:40 Done.
458 const ShellIntegration::ShortcutInfo& shortcut_info) { 463 const ShellIntegration::ShortcutInfo& shortcut_info) {
459 // TODO(benwells): Implement this when shortcuts / weblings are enabled on 464 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
460 // mac. 465 WebAppShortcutCreator shortcut_creator(
466 web_app_path, shortcut_info, UTF8ToUTF16(base::mac::BaseBundleID()));
467 file_util::Delete(shortcut_creator.GetShortcutPath(), true);
tapted 2013/06/12 08:17:52 Check for empty here too -- passing empty strings
jackhou1 2013/06/12 08:30:40 Done.
468 shortcut_creator.CreateShortcut();
461 } 469 }
462 470
463 } // namespace internals 471 } // namespace internals
464 472
465 } // namespace web_app 473 } // 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