1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Mozilla code.
16 * The Initial Developer of the Original Code is
17 * the Mozilla Foundation.
18 * Portions created by the Initial Developer are Copyright (C) 2007
19 * the Initial Developer. All Rights Reserved.
22 * Dan Mosedale <dmose@mozilla.org>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #import <CoreFoundation/CoreFoundation.h>
39 #import <ApplicationServices/ApplicationServices.h>
41 #include "nsObjCExceptions.h"
42 #include "nsLocalHandlerAppMac.h"
43 #include "nsILocalFileMac.h"
46 // We override this to make sure app bundles display their pretty name (without .app suffix)
47 NS_IMETHODIMP nsLocalHandlerAppMac::GetName(nsAString& aName)
50 nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(mExecutable);
53 (void)macFile->IsPackage(&isPackage);
55 return macFile->GetBundleDisplayName(aName);
59 return nsLocalHandlerApp::GetName(aName);
63 * mostly copy/pasted from nsMacShellService.cpp (which is in browser/,
64 * so we can't depend on it here). This code probably really wants to live
65 * somewhere more central (see bug 389922).
68 nsLocalHandlerAppMac::LaunchWithURI(nsIURI *aURI,
69 nsIInterfaceRequestor *aWindowContext)
71 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
74 nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(mExecutable, &rv));
75 NS_ENSURE_SUCCESS(rv, rv);
78 rv = lfm->GetCFURL(&appURL);
82 nsCAutoString uriSpec;
83 aURI->GetAsciiSpec(uriSpec);
85 const UInt8* uriString = reinterpret_cast<const UInt8*>(uriSpec.get());
86 CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, uriSpec.Length(),
87 kCFStringEncodingUTF8, NULL);
90 return NS_ERROR_OUT_OF_MEMORY;
93 CFArrayRef uris = ::CFArrayCreate(NULL, reinterpret_cast<const void**>(&uri),
98 return NS_ERROR_OUT_OF_MEMORY;
101 LSLaunchURLSpec launchSpec;
102 launchSpec.appURL = appURL;
103 launchSpec.itemURLs = uris;
104 launchSpec.passThruParams = NULL;
105 launchSpec.launchFlags = kLSLaunchDefaults;
106 launchSpec.asyncRefCon = NULL;
108 OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL);
114 return err != noErr ? NS_ERROR_FAILURE : NS_OK;
116 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;