@@ -392,46 +392,28 @@ nsOSHelperAppService::GetDefaultAppInfo(const nsAString& aAppInfo,
392
392
393
393
already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension (const nsAFlatString& aFileExt, const char *aTypeHint)
394
394
{
395
- if (aFileExt .IsEmpty ())
395
+ if (aExtension .IsEmpty ())
396
396
return nullptr ;
397
397
398
- // windows registry assumes your file extension is going to include the '.'.
399
- // so make sure it's there...
400
- nsAutoString fileExtToUse;
401
- if (aFileExt.First () != char16_t (' .' ))
402
- fileExtToUse = char16_t (' .' );
403
-
404
- fileExtToUse.Append (aFileExt);
405
-
406
- // Try to get an entry from the windows registry.
407
- nsCOMPtr<nsIWindowsRegKey> regKey =
408
- do_CreateInstance (" @mozilla.org/windows-registry-key;1" );
409
- if (!regKey)
410
- return nullptr ;
411
-
412
- nsresult rv = regKey->Open (nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
413
- fileExtToUse,
414
- nsIWindowsRegKey::ACCESS_QUERY_VALUE);
415
- if (NS_FAILED(rv))
416
- return nullptr ;
417
-
398
+ // Determine the mime type.
418
399
nsAutoCString typeToUse;
419
400
if (aTypeHint && *aTypeHint) {
420
401
typeToUse.Assign (aTypeHint);
421
- }
422
- else {
423
- nsAutoString temp;
424
- if (NS_FAILED(regKey->ReadStringValue (NS_LITERAL_STRING(" Content Type" ),
425
- temp)) || temp.IsEmpty ()) {
426
- return nullptr ;
427
- }
428
- // Content-Type is always in ASCII
429
- LossyAppendUTF16toASCII (temp, typeToUse);
402
+ } else if (!GetMIMETypeFromOSForExtension (NS_ConvertUTF16toUTF8(aFileExt), typeToUse)) {
403
+ return nullptr ;
430
404
}
431
405
432
406
RefPtr<nsMIMEInfoWin> mimeInfo = new nsMIMEInfoWin (typeToUse);
433
407
434
- // don't append the '.'
408
+ // windows registry assumes your file extension is going to include the '.',
409
+ // but our APIs expect it to not be there, so make sure we normalize that bit.
410
+ nsAutoString fileExtToUse;
411
+ if (aFileExt.First () != char16_t (' .' ))
412
+ fileExtToUse = char16_t (' .' );
413
+
414
+ fileExtToUse.Append (aFileExt);
415
+
416
+ // don't append the '.' for our APIs.
435
417
mimeInfo->AppendExtension (NS_ConvertUTF16toUTF8(Substring (fileExtToUse, 1 )));
436
418
mimeInfo->SetPreferredAction (nsIMIMEInfo::useSystemDefault);
437
419
@@ -458,8 +440,17 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const nsAFl
458
440
}
459
441
else
460
442
{
461
- found = NS_SUCCEEDED(regKey->ReadStringValue (EmptyString (),
462
- appInfo));
443
+ nsCOMPtr<nsIWindowsRegKey> regKey =
444
+ do_CreateInstance (" @mozilla.org/windows-registry-key;1" );
445
+ if (!regKey)
446
+ return nullptr ;
447
+ nsresult rv = regKey->Open (nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
448
+ fileExtToUse,
449
+ nsIWindowsRegKey::ACCESS_QUERY_VALUE);
450
+ if (NS_SUCCEEDED(rv)) {
451
+ found = NS_SUCCEEDED(regKey->ReadStringValue (EmptyString (),
452
+ appInfo));
453
+ }
463
454
}
464
455
465
456
// Bug 358297 - ignore the default handler, force the user to choose app
@@ -597,3 +588,40 @@ nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
597
588
return NS_OK;
598
589
}
599
590
591
+ bool
592
+ nsOSHelperAppService::GetMIMETypeFromOSForExtension (const nsACString& aExtension,
593
+ nsACString& aMIMEType)
594
+ {
595
+ if (aExtension.IsEmpty ())
596
+ return false ;
597
+
598
+ // windows registry assumes your file extension is going to include the '.'.
599
+ // so make sure it's there...
600
+ nsAutoString fileExtToUse;
601
+ if (aExtension.First () != ' .' )
602
+ fileExtToUse = char16_t (' .' );
603
+
604
+ AppendUTF8toUTF16 (aExtension, fileExtToUse);
605
+
606
+ // Try to get an entry from the windows registry.
607
+ nsCOMPtr<nsIWindowsRegKey> regKey =
608
+ do_CreateInstance (" @mozilla.org/windows-registry-key;1" );
609
+ if (!regKey)
610
+ return false ;
611
+
612
+ nsresult rv = regKey->Open (nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
613
+ fileExtToUse,
614
+ nsIWindowsRegKey::ACCESS_QUERY_VALUE);
615
+ if (NS_FAILED(rv))
616
+ return false ;
617
+
618
+ nsAutoString mimeType;
619
+ if (NS_FAILED(regKey->ReadStringValue (NS_LITERAL_STRING(" Content Type" ),
620
+ mimeType)) || mimeType.IsEmpty ()) {
621
+ return false ;
622
+ }
623
+ // Content-Type is always in ASCII
624
+ aMIMEType.Truncate ();
625
+ LossyAppendUTF16toASCII (mimeType, aMIMEType);
626
+ return true ;
627
+ }
0 commit comments