michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #import michael@0: #import michael@0: michael@0: #include "nsObjCExceptions.h" michael@0: #include "nsLocalHandlerAppMac.h" michael@0: #include "nsILocalFileMac.h" michael@0: #include "nsIURI.h" michael@0: michael@0: // We override this to make sure app bundles display their pretty name (without .app suffix) michael@0: NS_IMETHODIMP nsLocalHandlerAppMac::GetName(nsAString& aName) michael@0: { michael@0: if (mExecutable) { michael@0: nsCOMPtr macFile = do_QueryInterface(mExecutable); michael@0: if (macFile) { michael@0: bool isPackage; michael@0: (void)macFile->IsPackage(&isPackage); michael@0: if (isPackage) michael@0: return macFile->GetBundleDisplayName(aName); michael@0: } michael@0: } michael@0: michael@0: return nsLocalHandlerApp::GetName(aName); michael@0: } michael@0: michael@0: /** michael@0: * mostly copy/pasted from nsMacShellService.cpp (which is in browser/, michael@0: * so we can't depend on it here). This code probably really wants to live michael@0: * somewhere more central (see bug 389922). michael@0: */ michael@0: NS_IMETHODIMP michael@0: nsLocalHandlerAppMac::LaunchWithURI(nsIURI *aURI, michael@0: nsIInterfaceRequestor *aWindowContext) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: nsresult rv; michael@0: nsCOMPtr lfm(do_QueryInterface(mExecutable, &rv)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: CFURLRef appURL; michael@0: rv = lfm->GetCFURL(&appURL); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: nsAutoCString uriSpec; michael@0: aURI->GetAsciiSpec(uriSpec); michael@0: michael@0: const UInt8* uriString = reinterpret_cast(uriSpec.get()); michael@0: CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, uriSpec.Length(), michael@0: kCFStringEncodingUTF8, NULL); michael@0: if (!uri) { michael@0: ::CFRelease(appURL); michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: michael@0: CFArrayRef uris = ::CFArrayCreate(NULL, reinterpret_cast(&uri), michael@0: 1, NULL); michael@0: if (!uris) { michael@0: ::CFRelease(uri); michael@0: ::CFRelease(appURL); michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: michael@0: LSLaunchURLSpec launchSpec; michael@0: launchSpec.appURL = appURL; michael@0: launchSpec.itemURLs = uris; michael@0: launchSpec.passThruParams = NULL; michael@0: launchSpec.launchFlags = kLSLaunchDefaults; michael@0: launchSpec.asyncRefCon = NULL; michael@0: michael@0: OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL); michael@0: michael@0: ::CFRelease(uris); michael@0: ::CFRelease(uri); michael@0: ::CFRelease(appURL); michael@0: michael@0: return err != noErr ? NS_ERROR_FAILURE : NS_OK; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: }