Commit a362bf2d authored by jeremya@chromium.org's avatar jeremya@chromium.org

[mac] Delete app shortcuts on app uninstall.

When an app is uninstalled, find the .app bundle it's associated with using
Launch Services, and delete it.

Review URL: https://codereview.chromium.org/12178030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182077 0039d316-1c4b-4281-b951-d872f2087c98
parent 530a19be
...@@ -43,9 +43,9 @@ AppShortcutManager::~AppShortcutManager() {} ...@@ -43,9 +43,9 @@ AppShortcutManager::~AppShortcutManager() {}
void AppShortcutManager::Observe(int type, void AppShortcutManager::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
#if !defined(OS_MACOSX)
switch (type) { switch (type) {
case chrome::NOTIFICATION_EXTENSION_INSTALLED: { case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
#if !defined(OS_MACOSX)
const Extension* extension = content::Details<const Extension>( const Extension* extension = content::Details<const Extension>(
details).ptr(); details).ptr();
if (extension->is_platform_app() && if (extension->is_platform_app() &&
...@@ -63,8 +63,9 @@ void AppShortcutManager::Observe(int type, ...@@ -63,8 +63,9 @@ void AppShortcutManager::Observe(int type,
} }
#else #else
UpdateApplicationShortcuts(extension); UpdateApplicationShortcuts(extension);
#endif #endif // defined(OS_WIN)
} }
#endif // !defined(OS_MACOSX)
break; break;
} }
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
...@@ -76,7 +77,6 @@ void AppShortcutManager::Observe(int type, ...@@ -76,7 +77,6 @@ void AppShortcutManager::Observe(int type,
default: default:
NOTREACHED(); NOTREACHED();
} }
#endif
} }
#if defined(OS_WIN) #if defined(OS_WIN)
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/mac/bundle_locations.h" #include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/mac_logging.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/scoped_nsobject.h" #include "base/memory/scoped_nsobject.h"
#include "base/sys_string_conversions.h" #include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
...@@ -256,6 +258,25 @@ namespace web_app { ...@@ -256,6 +258,25 @@ namespace web_app {
namespace internals { namespace internals {
FilePath GetAppBundleByExtensionId(std::string extension_id) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
// This matches APP_MODE_APP_BUNDLE_ID in chrome/chrome.gyp.
std::string bundle_id =
base::mac::BaseBundleID() + std::string(".app.") + extension_id;
base::mac::ScopedCFTypeRef<CFStringRef> bundle_id_cf(
base::SysUTF8ToCFStringRef(bundle_id));
CFURLRef url_ref = NULL;
OSStatus status = LSFindApplicationForInfo(
kLSUnknownCreator, bundle_id_cf.get(), NULL, NULL, &url_ref);
base::mac::ScopedCFTypeRef<CFURLRef> url(url_ref);
if (status != noErr)
return FilePath();
NSString* path_string = [base::mac::CFToNSCast(url.get()) path];
return FilePath([path_string fileSystemRepresentation]);
}
bool CreatePlatformShortcuts( bool CreatePlatformShortcuts(
const base::FilePath& web_app_path, const base::FilePath& web_app_path,
const ShellIntegration::ShortcutInfo& shortcut_info) { const ShellIntegration::ShortcutInfo& shortcut_info) {
...@@ -268,9 +289,11 @@ bool CreatePlatformShortcuts( ...@@ -268,9 +289,11 @@ bool CreatePlatformShortcuts(
void DeletePlatformShortcuts( void DeletePlatformShortcuts(
const base::FilePath& web_app_path, const base::FilePath& web_app_path,
const ShellIntegration::ShortcutInfo& shortcut_info) { const ShellIntegration::ShortcutInfo& info) {
// TODO(benwells): Implement this when shortcuts / weblings are enabled on DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
// mac.
FilePath bundle_path = GetAppBundleByExtensionId(info.extension_id);
file_util::Delete(bundle_path, true);
} }
void UpdatePlatformShortcuts( void UpdatePlatformShortcuts(
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/mac_logging.h" #include "base/mac/mac_logging.h"
#include "base/sys_string_conversions.h"
#import "chrome/common/cloud_print/cloud_print_class_mac.h" #import "chrome/common/cloud_print/cloud_print_class_mac.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
...@@ -29,21 +30,20 @@ ...@@ -29,21 +30,20 @@
- (void)submitPrint:(NSAppleEventDescriptor*)event { - (void)submitPrint:(NSAppleEventDescriptor*)event {
std::string silent = std::string("--") + switches::kNoStartupWindow; std::string silent = std::string("--") + switches::kNoStartupWindow;
// Set up flag so that it can be passed along with the Apple Event. // Set up flag so that it can be passed along with the Apple Event.
CFStringRef silentLaunchFlag = base::mac::ScopedCFTypeRef<CFStringRef> silentLaunchFlag(
CFStringCreateWithCString(NULL, silent.c_str(), kCFStringEncodingUTF8); base::SysUTF8ToCFStringRef(silent));
CFStringRef flags[] = { silentLaunchFlag }; CFStringRef flags[] = { silentLaunchFlag };
// Argv array that will be passed. // Argv array that will be passed.
CFArrayRef passArgv = base::mac::ScopedCFTypeRef<CFArrayRef> passArgv(
CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks); CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks));
FSRef ref; FSRef ref;
CFURLRef* kDontWantURL = NULL;
// Get Chrome's bundle ID. // Get Chrome's bundle ID.
std::string bundleID = base::mac::BaseBundleID(); std::string bundleID = base::mac::BaseBundleID();
CFStringRef bundleIDCF = base::mac::ScopedCFTypeRef<CFStringRef> bundleIDCF(
CFStringCreateWithCString(NULL, bundleID.c_str(), kCFStringEncodingUTF8); base::SysUTF8ToCFStringRef(bundleID));
// Use Launch Services to locate Chrome using its bundleID. // Use Launch Services to locate Chrome using its bundleID.
OSStatus status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF, OSStatus status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF,
NULL, &ref, kDontWantURL); NULL, &ref, NULL);
if (status != noErr) { if (status != noErr) {
OSSTATUS_LOG(ERROR, status) << "Failed to make path ref"; OSSTATUS_LOG(ERROR, status) << "Failed to make path ref";
...@@ -70,8 +70,8 @@ ...@@ -70,8 +70,8 @@
NULL, NULL,
passArgv, passArgv,
NULL }; NULL };
AEDesc* initialEvent = const_cast<AEDesc*> ([sendEvent aeDesc]); AEDesc* initialEvent = const_cast<AEDesc*>([sendEvent aeDesc]);
params.initialEvent = static_cast<AppleEvent*> (initialEvent); params.initialEvent = static_cast<AppleEvent*>(initialEvent);
// Send the Apple Event Using launch services, launching Chrome if necessary. // Send the Apple Event Using launch services, launching Chrome if necessary.
status = LSOpenApplication(&params, NULL); status = LSOpenApplication(&params, NULL);
if (status != noErr) { if (status != noErr) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment