1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #import <CoreFoundation/CoreFoundation.h>
6 #import <ApplicationServices/ApplicationServices.h>
8 #include "nsObjCExceptions.h"
9 #include "nsLocalHandlerAppMac.h"
10 #include "nsILocalFileMac.h"
13 // We override this to make sure app bundles display their pretty name (without
15 NS_IMETHODIMP nsLocalHandlerAppMac::GetName(nsAString& aName) {
17 nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(mExecutable);
20 (void)macFile->IsPackage(&isPackage);
21 if (isPackage) return macFile->GetBundleDisplayName(aName);
25 return nsLocalHandlerApp::GetName(aName);
29 * mostly copy/pasted from nsMacShellService.cpp (which is in browser/,
30 * so we can't depend on it here). This code probably really wants to live
31 * somewhere more central (see bug 389922).
34 nsLocalHandlerAppMac::LaunchWithURI(
35 nsIURI* aURI, mozilla::dom::BrowsingContext* aBrowsingContext) {
36 NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
39 nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(mExecutable, &rv));
40 NS_ENSURE_SUCCESS(rv, rv);
43 rv = lfm->GetCFURL(&appURL);
44 if (NS_FAILED(rv)) return rv;
46 nsAutoCString uriSpec;
47 aURI->GetAsciiSpec(uriSpec);
49 const UInt8* uriString = reinterpret_cast<const UInt8*>(uriSpec.get());
50 CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, uriSpec.Length(),
51 kCFStringEncodingUTF8, NULL);
54 return NS_ERROR_OUT_OF_MEMORY;
58 ::CFArrayCreate(NULL, reinterpret_cast<const void**>(&uri), 1, NULL);
62 return NS_ERROR_OUT_OF_MEMORY;
65 LSLaunchURLSpec launchSpec;
66 launchSpec.appURL = appURL;
67 launchSpec.itemURLs = uris;
68 launchSpec.passThruParams = NULL;
69 launchSpec.launchFlags = kLSLaunchDefaults;
70 launchSpec.asyncRefCon = NULL;
72 OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL);
78 return err != noErr ? NS_ERROR_FAILURE : NS_OK;
80 NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);