diff --git a/toolkit/webapps/WebappOSUtils.jsm b/toolkit/webapps/WebappOSUtils.jsm index 2c7c09e9d9cd..56ca9c5ee68c 100644 --- a/toolkit/webapps/WebappOSUtils.jsm +++ b/toolkit/webapps/WebappOSUtils.jsm @@ -2,10 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -const Cc = Components.classes; -const Ci = Components.interfaces; -const CC = Components.Constructor; -const Cu = Components.utils; +const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu, Constructor: CC } = Components; Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/FileUtils.jsm"); @@ -119,8 +116,8 @@ this.WebappOSUtils = { #elifdef XP_MACOSX let uniqueName = this.getUniqueName(aApp); - let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"] - .createInstance(Ci.nsIMacWebAppUtils); + let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"]. + createInstance(Ci.nsIMacWebAppUtils); try { let path; @@ -265,8 +262,8 @@ this.WebappOSUtils = { return false; } - let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"] - .createInstance(Ci.nsIMacWebAppUtils); + let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"]. + createInstance(Ci.nsIMacWebAppUtils); try { mwaUtils.launchAppWithIdentifier(launchIdentifier); @@ -331,7 +328,25 @@ this.WebappOSUtils = { return deferred.promise; #elifdef XP_MACOSX - return Promise.reject("Uninstallation not yet implemented"); + let [ , path ] = this.getLaunchTarget(aApp); + if (!path) { + return Promise.reject("App not found"); + } + + let deferred = Promise.defer(); + + let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"]. + createInstance(Ci.nsIMacWebAppUtils); + + mwaUtils.trashApp(path, (aResult) => { + if (aResult == Cr.NS_OK) { + deferred.resolve(true); + } else { + deferred.resolve("Error moving the app to the Trash: " + aResult); + } + }); + + return deferred.promise; #elifdef XP_UNIX let exeFile = this.getLaunchTarget(aApp); if (!exeFile) { diff --git a/widget/cocoa/nsMacWebAppUtils.mm b/widget/cocoa/nsMacWebAppUtils.mm index f37cde8215f5..cc96abf8ed70 100644 --- a/widget/cocoa/nsMacWebAppUtils.mm +++ b/widget/cocoa/nsMacWebAppUtils.mm @@ -57,3 +57,26 @@ NS_IMETHODIMP nsMacWebAppUtils::LaunchAppWithIdentifier(const nsAString& bundleI NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; } + +NS_IMETHODIMP nsMacWebAppUtils::TrashApp(const nsAString& path, nsITrashAppCallback* aCallback) { + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; + + if (NS_WARN_IF(!aCallback)) { + return NS_ERROR_INVALID_ARG; + } + + nsCOMPtr callback = aCallback; + + NSString* tempString = [NSString stringWithCharacters:reinterpret_cast(((nsString)path).get()) + length:path.Length()]; + + [[NSWorkspace sharedWorkspace] recycleURLs: [NSArray arrayWithObject:[NSURL fileURLWithPath:tempString]] + completionHandler: ^(NSDictionary *newURLs, NSError *error) { + nsresult rv = (error == nil) ? NS_OK : NS_ERROR_FAILURE; + callback->TrashAppFinished(rv); + }]; + + return NS_OK; + + NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; +} diff --git a/widget/nsIMacWebAppUtils.idl b/widget/nsIMacWebAppUtils.idl index 12a42ea17c10..4d570a8bf0eb 100644 --- a/widget/nsIMacWebAppUtils.idl +++ b/widget/nsIMacWebAppUtils.idl @@ -6,11 +6,17 @@ interface nsIMacWebAppUtils; +[scriptable, function, uuid(8c899c4f-58c1-4b74-9034-3bb64e484b68)] +interface nsITrashAppCallback : nsISupports +{ + void trashAppFinished(in nsresult rv); +}; + /** * Allow MozApps API to locate and manipulate natively installed apps */ -[scriptable, uuid(e9096367-ddd9-45e4-b762-49c0c18b7119)] +[scriptable, uuid(c69cf343-ea41-428b-b161-4655fd54d8e7)] interface nsIMacWebAppUtils : nsISupports { /** * Find the path for an app with the given signature. @@ -22,4 +28,8 @@ interface nsIMacWebAppUtils : nsISupports { */ void launchAppWithIdentifier(in AString bundleIdentifier); + /** + * Move the app from the given directory to the Trash. + */ + void trashApp(in AString path, in nsITrashAppCallback callback); };