1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsGNOMERegistry.h"
8 #include "nsMIMEInfoUnix.h"
9 #include "nsIGIOService.h"
12 bool nsGNOMERegistry::HandlerExists(const char* aProtocolScheme
) {
13 nsCOMPtr
<nsIGIOService
> giovfs
= do_GetService(NS_GIOSERVICE_CONTRACTID
);
18 nsCOMPtr
<nsIHandlerApp
> app
;
19 return NS_SUCCEEDED(giovfs
->GetAppForURIScheme(
20 nsDependentCString(aProtocolScheme
), getter_AddRefs(app
)));
23 // XXX Check HandlerExists() before calling LoadURL.
26 nsresult
nsGNOMERegistry::LoadURL(nsIURI
* aURL
) {
27 nsCOMPtr
<nsIGIOService
> giovfs
= do_GetService(NS_GIOSERVICE_CONTRACTID
);
29 return NS_ERROR_FAILURE
;
32 return giovfs
->ShowURI(aURL
);
36 void nsGNOMERegistry::GetAppDescForScheme(const nsACString
& aScheme
,
38 nsCOMPtr
<nsIGIOService
> giovfs
= do_GetService(NS_GIOSERVICE_CONTRACTID
);
41 nsCOMPtr
<nsIHandlerApp
> app
;
42 if (NS_FAILED(giovfs
->GetAppForURIScheme(aScheme
, getter_AddRefs(app
))))
49 already_AddRefed
<nsMIMEInfoBase
> nsGNOMERegistry::GetFromExtension(
50 const nsACString
& aFileExt
) {
51 nsAutoCString mimeType
;
52 nsCOMPtr
<nsIGIOService
> giovfs
= do_GetService(NS_GIOSERVICE_CONTRACTID
);
57 // Get the MIME type from the extension, then call GetFromType to
58 // fill in the MIMEInfo.
59 if (NS_FAILED(giovfs
->GetMimeTypeFromExtension(aFileExt
, mimeType
)) ||
60 mimeType
.EqualsLiteral("application/octet-stream")) {
64 RefPtr
<nsMIMEInfoBase
> mi
= GetFromType(mimeType
);
66 mi
->AppendExtension(aFileExt
);
73 already_AddRefed
<nsMIMEInfoBase
> nsGNOMERegistry::GetFromType(
74 const nsACString
& aMIMEType
) {
75 RefPtr
<nsMIMEInfoUnix
> mimeInfo
= new nsMIMEInfoUnix(aMIMEType
);
76 NS_ENSURE_TRUE(mimeInfo
, nullptr);
79 nsAutoCString description
;
81 nsCOMPtr
<nsIGIOService
> giovfs
= do_GetService(NS_GIOSERVICE_CONTRACTID
);
86 nsCOMPtr
<nsIHandlerApp
> handlerApp
;
88 giovfs
->GetAppForMimeType(aMIMEType
, getter_AddRefs(handlerApp
))) ||
92 handlerApp
->GetName(name
);
93 giovfs
->GetDescriptionForMimeType(aMIMEType
, description
);
95 mimeInfo
->SetDefaultDescription(name
);
97 mimeInfo
->SetPreferredAction(nsIMIMEInfo::saveToDisk
);
98 mimeInfo
->SetDescription(NS_ConvertUTF8toUTF16(description
));
100 return mimeInfo
.forget();