@@ -277,3 +277,70 @@ nsMacShellService::ShowSecurityPreferences(const nsACString& aPaneID) {
277
277
}
278
278
return rv;
279
279
}
280
+
281
+ nsString ConvertCFStringToNSString (CFStringRef aSrc) {
282
+ nsString aDest;
283
+ auto len = ::CFStringGetLength (aSrc);
284
+ aDest.SetLength (len);
285
+ ::CFStringGetCharacters (aSrc, ::CFRangeMake(0 , len),
286
+ (UniChar *)aDest.BeginWriting());
287
+ return aDest;
288
+ }
289
+
290
+ NS_IMETHODIMP
291
+ nsMacShellService::GetAvailableApplicationsForProtocol (
292
+ const nsACString& protocol, nsTArray<nsTArray<nsString>>& aHandlerPaths) {
293
+ class CFTypeRefAutoDeleter {
294
+ public:
295
+ CFTypeRefAutoDeleter (CFTypeRef ref) : mRef (ref) {}
296
+ ~CFTypeRefAutoDeleter () {
297
+ if (mRef != NULL ) ::CFRelease (mRef );
298
+ }
299
+
300
+ private:
301
+ CFTypeRef mRef ;
302
+ };
303
+
304
+ aHandlerPaths.Clear ();
305
+ nsCString protocolSep = protocol + " ://" _ns;
306
+ CFStringRef cfProtocol = ::CFStringCreateWithBytes (
307
+ kCFAllocatorDefault , (const UInt8 *)protocolSep.BeginReading (),
308
+ protocolSep.Length (), kCFStringEncodingUTF8 , false );
309
+ CFTypeRefAutoDeleter cfProtocolAuto (cfProtocol);
310
+ if (cfProtocol == NULL ) {
311
+ return NS_ERROR_ILLEGAL_VALUE;
312
+ }
313
+ CFURLRef protocolURL =
314
+ ::CFURLCreateWithString (kCFAllocatorDefault , cfProtocol, NULL );
315
+ CFTypeRefAutoDeleter cfProtocolURLAuto (protocolURL);
316
+ if (protocolURL == NULL ) {
317
+ return NS_ERROR_MALFORMED_URI;
318
+ }
319
+ CFArrayRef appURLs = ::LSCopyApplicationURLsForURL (protocolURL, kLSRolesAll );
320
+ CFTypeRefAutoDeleter cfAppURLsAuto (appURLs);
321
+ if (appURLs == NULL ) {
322
+ return NS_ERROR_NOT_AVAILABLE;
323
+ }
324
+ for (CFIndex i = 0 ; i < ::CFArrayGetCount (appURLs); i++) {
325
+ CFURLRef appURL = (CFURLRef )::CFArrayGetValueAtIndex (appURLs, i);
326
+ CFBundleRef appBundle = ::CFBundleCreate (kCFAllocatorDefault , appURL);
327
+ CFTypeRefAutoDeleter cfAppBundleAuto (appBundle);
328
+ if (appBundle == NULL ) {
329
+ continue ;
330
+ }
331
+ CFDictionaryRef appInfo = ::CFBundleGetInfoDictionary (appBundle);
332
+ if (appInfo == NULL ) {
333
+ continue ;
334
+ }
335
+ CFStringRef displayName =
336
+ (CFStringRef )::CFDictionaryGetValue (appInfo, kCFBundleNameKey );
337
+ if (displayName == NULL ) {
338
+ continue ;
339
+ }
340
+ CFStringRef appPath = ::CFURLGetString (appURL);
341
+ nsTArray<nsString> handlerPath = {ConvertCFStringToNSString (displayName),
342
+ ConvertCFStringToNSString (appPath)};
343
+ aHandlerPaths.AppendElement (handlerPath.Clone ());
344
+ }
345
+ return NS_OK;
346
+ }
0 commit comments