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() {}
void AppShortcutManager::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
#if !defined(OS_MACOSX)
switch (type) {
case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
#if !defined(OS_MACOSX)
const Extension* extension = content::Details<const Extension>(
details).ptr();
if (extension->is_platform_app() &&
......@@ -63,8 +63,9 @@ void AppShortcutManager::Observe(int type,
}
#else
UpdateApplicationShortcuts(extension);
#endif
#endif // defined(OS_WIN)
}
#endif // !defined(OS_MACOSX)
break;
}
case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
......@@ -76,7 +77,6 @@ void AppShortcutManager::Observe(int type,
default:
NOTREACHED();
}
#endif
}
#if defined(OS_WIN)
......
......@@ -10,7 +10,9 @@
#include "base/files/scoped_temp_dir.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/mac/mac_logging.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/scoped_nsobject.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
......@@ -256,6 +258,25 @@ namespace web_app {
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(
const base::FilePath& web_app_path,
const ShellIntegration::ShortcutInfo& shortcut_info) {
......@@ -268,9 +289,11 @@ bool CreatePlatformShortcuts(
void DeletePlatformShortcuts(
const base::FilePath& web_app_path,
const ShellIntegration::ShortcutInfo& shortcut_info) {
// TODO(benwells): Implement this when shortcuts / weblings are enabled on
// mac.
const ShellIntegration::ShortcutInfo& info) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
FilePath bundle_path = GetAppBundleByExtensionId(info.extension_id);
file_util::Delete(bundle_path, true);
}
void UpdatePlatformShortcuts(
......
......@@ -6,6 +6,7 @@
#include "base/mac/foundation_util.h"
#include "base/mac/mac_logging.h"
#include "base/sys_string_conversions.h"
#import "chrome/common/cloud_print/cloud_print_class_mac.h"
#include "chrome/common/chrome_switches.h"
......@@ -29,21 +30,20 @@
- (void)submitPrint:(NSAppleEventDescriptor*)event {
std::string silent = std::string("--") + switches::kNoStartupWindow;
// Set up flag so that it can be passed along with the Apple Event.
CFStringRef silentLaunchFlag =
CFStringCreateWithCString(NULL, silent.c_str(), kCFStringEncodingUTF8);
base::mac::ScopedCFTypeRef<CFStringRef> silentLaunchFlag(
base::SysUTF8ToCFStringRef(silent));
CFStringRef flags[] = { silentLaunchFlag };
// Argv array that will be passed.
CFArrayRef passArgv =
CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks);
base::mac::ScopedCFTypeRef<CFArrayRef> passArgv(
CFArrayCreate(NULL, (const void**) flags, 1, &kCFTypeArrayCallBacks));
FSRef ref;
CFURLRef* kDontWantURL = NULL;
// Get Chrome's bundle ID.
std::string bundleID = base::mac::BaseBundleID();
CFStringRef bundleIDCF =
CFStringCreateWithCString(NULL, bundleID.c_str(), kCFStringEncodingUTF8);
std::string bundleID = base::mac::BaseBundleID();
base::mac::ScopedCFTypeRef<CFStringRef> bundleIDCF(
base::SysUTF8ToCFStringRef(bundleID));
// Use Launch Services to locate Chrome using its bundleID.
OSStatus status = LSFindApplicationForInfo(kLSUnknownCreator, bundleIDCF,
NULL, &ref, kDontWantURL);
NULL, &ref, NULL);
if (status != noErr) {
OSSTATUS_LOG(ERROR, status) << "Failed to make path ref";
......@@ -70,8 +70,8 @@
NULL,
passArgv,
NULL };
AEDesc* initialEvent = const_cast<AEDesc*> ([sendEvent aeDesc]);
params.initialEvent = static_cast<AppleEvent*> (initialEvent);
AEDesc* initialEvent = const_cast<AEDesc*>([sendEvent aeDesc]);
params.initialEvent = static_cast<AppleEvent*>(initialEvent);
// Send the Apple Event Using launch services, launching Chrome if necessary.
status = LSOpenApplication(&params, NULL);
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