1 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsMIMEInfoUnix.h"
8 #include "nsGNOMERegistry.h"
9 #include "nsIGIOService.h"
11 #include "nsIIOService.h"
12 #include "nsLocalFile.h"
14 #ifdef MOZ_ENABLE_DBUS
15 # include "nsDBusHandlerApp.h"
18 nsresult
nsMIMEInfoUnix::LoadUriInternal(nsIURI
* aURI
) {
19 return nsGNOMERegistry::LoadURL(aURI
);
22 NS_IMETHODIMP
nsMIMEInfoUnix::GetDefaultExecutable(nsIFile
** aExecutable
) {
23 // This needs to be implemented before FirefoxBridge will work on Linux.
24 // To implement this and be consistent, GetHasDefaultHandler and
25 // LaunchDefaultWithFile should probably be made to be consistent.
26 // Right now, they aren't. GetHasDefaultHandler reports true in cases
27 // where calling LaunchDefaultWithFile will fail due to not finding the
30 return NS_ERROR_NOT_IMPLEMENTED
;
34 nsMIMEInfoUnix::GetHasDefaultHandler(bool* _retval
) {
35 // if a default app is set, it means the application has been set from
36 // either /etc/mailcap or ${HOME}/.mailcap, in which case we don't want to
37 // give the GNOME answer.
38 if (GetDefaultApplication()) {
39 return nsMIMEInfoImpl::GetHasDefaultHandler(_retval
);
44 if (mClass
== eProtocolInfo
) {
45 *_retval
= nsGNOMERegistry::HandlerExists(mSchemeOrType
.get());
47 RefPtr
<nsMIMEInfoBase
> mimeInfo
=
48 nsGNOMERegistry::GetFromType(mSchemeOrType
);
51 nsresult rv
= GetPrimaryExtension(ext
);
52 if (NS_SUCCEEDED(rv
)) {
53 mimeInfo
= nsGNOMERegistry::GetFromExtension(ext
);
56 if (mimeInfo
) *_retval
= true;
59 if (*_retval
) return NS_OK
;
64 nsresult
nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile
* aFile
) {
65 // if a default app is set, it means the application has been set from
66 // either /etc/mailcap or ${HOME}/.mailcap, in which case we don't want to
67 // give the GNOME answer.
68 if (GetDefaultApplication()) {
69 return nsMIMEInfoImpl::LaunchDefaultWithFile(aFile
);
72 nsAutoCString nativePath
;
73 aFile
->GetNativePath(nativePath
);
75 nsCOMPtr
<nsIGIOService
> giovfs
= do_GetService(NS_GIOSERVICE_CONTRACTID
);
77 return NS_ERROR_FAILURE
;
80 // nsGIOMimeApp->Launch wants a URI string instead of local file
82 nsCOMPtr
<nsIIOService
> ioservice
=
83 do_GetService(NS_IOSERVICE_CONTRACTID
, &rv
);
84 NS_ENSURE_SUCCESS(rv
, rv
);
86 rv
= ioservice
->NewFileURI(aFile
, getter_AddRefs(uri
));
87 NS_ENSURE_SUCCESS(rv
, rv
);
89 nsCOMPtr
<nsIHandlerApp
> app
;
91 giovfs
->GetAppForMimeType(mSchemeOrType
, getter_AddRefs(app
))) ||
93 return NS_ERROR_FILE_NOT_FOUND
;
96 return app
->LaunchWithURI(uri
, nullptr);