Bug 1890689 apply drift correction to input rate instead of output rate r=pehrsons
[gecko.git] / uriloader / exthandler / mac / nsLocalHandlerAppMac.mm
blob07f0276666b59575bad78e2b9fa61ecd3113a930
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"
11 #include "nsIURI.h"
13 // We override this to make sure app bundles display their pretty name (without
14 // .app suffix)
15 NS_IMETHODIMP nsLocalHandlerAppMac::GetName(nsAString& aName) {
16   if (mExecutable) {
17     nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(mExecutable);
18     if (macFile) {
19       bool isPackage;
20       (void)macFile->IsPackage(&isPackage);
21       if (isPackage) return macFile->GetBundleDisplayName(aName);
22     }
23   }
25   return nsLocalHandlerApp::GetName(aName);
28 /**
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).
32  */
33 NS_IMETHODIMP
34 nsLocalHandlerAppMac::LaunchWithURI(
35     nsIURI* aURI, mozilla::dom::BrowsingContext* aBrowsingContext) {
36   NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
38   nsresult rv;
39   nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(mExecutable, &rv));
40   NS_ENSURE_SUCCESS(rv, rv);
42   CFURLRef appURL;
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);
52   if (!uri) {
53     ::CFRelease(appURL);
54     return NS_ERROR_OUT_OF_MEMORY;
55   }
57   CFArrayRef uris =
58       ::CFArrayCreate(NULL, reinterpret_cast<const void**>(&uri), 1, NULL);
59   if (!uris) {
60     ::CFRelease(uri);
61     ::CFRelease(appURL);
62     return NS_ERROR_OUT_OF_MEMORY;
63   }
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);
74   ::CFRelease(uris);
75   ::CFRelease(uri);
76   ::CFRelease(appURL);
78   return err != noErr ? NS_ERROR_FAILURE : NS_OK;
80   NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);