Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #import <CoreFoundation/CoreFoundation.h> |
michael@0 | 6 | #import <ApplicationServices/ApplicationServices.h> |
michael@0 | 7 | |
michael@0 | 8 | #include "nsObjCExceptions.h" |
michael@0 | 9 | #include "nsLocalHandlerAppMac.h" |
michael@0 | 10 | #include "nsILocalFileMac.h" |
michael@0 | 11 | #include "nsIURI.h" |
michael@0 | 12 | |
michael@0 | 13 | // We override this to make sure app bundles display their pretty name (without .app suffix) |
michael@0 | 14 | NS_IMETHODIMP nsLocalHandlerAppMac::GetName(nsAString& aName) |
michael@0 | 15 | { |
michael@0 | 16 | if (mExecutable) { |
michael@0 | 17 | nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(mExecutable); |
michael@0 | 18 | if (macFile) { |
michael@0 | 19 | bool isPackage; |
michael@0 | 20 | (void)macFile->IsPackage(&isPackage); |
michael@0 | 21 | if (isPackage) |
michael@0 | 22 | return macFile->GetBundleDisplayName(aName); |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | return nsLocalHandlerApp::GetName(aName); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * mostly copy/pasted from nsMacShellService.cpp (which is in browser/, |
michael@0 | 31 | * so we can't depend on it here). This code probably really wants to live |
michael@0 | 32 | * somewhere more central (see bug 389922). |
michael@0 | 33 | */ |
michael@0 | 34 | NS_IMETHODIMP |
michael@0 | 35 | nsLocalHandlerAppMac::LaunchWithURI(nsIURI *aURI, |
michael@0 | 36 | nsIInterfaceRequestor *aWindowContext) |
michael@0 | 37 | { |
michael@0 | 38 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; |
michael@0 | 39 | |
michael@0 | 40 | nsresult rv; |
michael@0 | 41 | nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(mExecutable, &rv)); |
michael@0 | 42 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 43 | |
michael@0 | 44 | CFURLRef appURL; |
michael@0 | 45 | rv = lfm->GetCFURL(&appURL); |
michael@0 | 46 | if (NS_FAILED(rv)) |
michael@0 | 47 | return rv; |
michael@0 | 48 | |
michael@0 | 49 | nsAutoCString uriSpec; |
michael@0 | 50 | aURI->GetAsciiSpec(uriSpec); |
michael@0 | 51 | |
michael@0 | 52 | const UInt8* uriString = reinterpret_cast<const UInt8*>(uriSpec.get()); |
michael@0 | 53 | CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, uriSpec.Length(), |
michael@0 | 54 | kCFStringEncodingUTF8, NULL); |
michael@0 | 55 | if (!uri) { |
michael@0 | 56 | ::CFRelease(appURL); |
michael@0 | 57 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | CFArrayRef uris = ::CFArrayCreate(NULL, reinterpret_cast<const void**>(&uri), |
michael@0 | 61 | 1, NULL); |
michael@0 | 62 | if (!uris) { |
michael@0 | 63 | ::CFRelease(uri); |
michael@0 | 64 | ::CFRelease(appURL); |
michael@0 | 65 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | LSLaunchURLSpec launchSpec; |
michael@0 | 69 | launchSpec.appURL = appURL; |
michael@0 | 70 | launchSpec.itemURLs = uris; |
michael@0 | 71 | launchSpec.passThruParams = NULL; |
michael@0 | 72 | launchSpec.launchFlags = kLSLaunchDefaults; |
michael@0 | 73 | launchSpec.asyncRefCon = NULL; |
michael@0 | 74 | |
michael@0 | 75 | OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL); |
michael@0 | 76 | |
michael@0 | 77 | ::CFRelease(uris); |
michael@0 | 78 | ::CFRelease(uri); |
michael@0 | 79 | ::CFRelease(appURL); |
michael@0 | 80 | |
michael@0 | 81 | return err != noErr ? NS_ERROR_FAILURE : NS_OK; |
michael@0 | 82 | |
michael@0 | 83 | NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; |
michael@0 | 84 | } |