/src/mozilla-central/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
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/. */ |
6 | | |
7 | | #include "nsMIMEInfoUnix.h" |
8 | | #include "nsGNOMERegistry.h" |
9 | | #include "nsIGIOService.h" |
10 | | #include "nsNetCID.h" |
11 | | #include "nsIIOService.h" |
12 | | #include "nsAutoPtr.h" |
13 | | #ifdef MOZ_ENABLE_DBUS |
14 | | #include "nsDBusHandlerApp.h" |
15 | | #endif |
16 | | |
17 | | nsresult |
18 | | nsMIMEInfoUnix::LoadUriInternal(nsIURI * aURI) |
19 | 0 | { |
20 | 0 | return nsGNOMERegistry::LoadURL(aURI); |
21 | 0 | } |
22 | | |
23 | | NS_IMETHODIMP |
24 | | nsMIMEInfoUnix::GetHasDefaultHandler(bool *_retval) |
25 | 0 | { |
26 | 0 | // if mDefaultApplication is set, it means the application has been set from |
27 | 0 | // either /etc/mailcap or ${HOME}/.mailcap, in which case we don't want to |
28 | 0 | // give the GNOME answer. |
29 | 0 | if (mDefaultApplication) |
30 | 0 | return nsMIMEInfoImpl::GetHasDefaultHandler(_retval); |
31 | 0 | |
32 | 0 | *_retval = false; |
33 | 0 |
|
34 | 0 | if (mClass == eProtocolInfo) { |
35 | 0 | *_retval = nsGNOMERegistry::HandlerExists(mSchemeOrType.get()); |
36 | 0 | } else { |
37 | 0 | RefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromType(mSchemeOrType); |
38 | 0 | if (!mimeInfo) { |
39 | 0 | nsAutoCString ext; |
40 | 0 | nsresult rv = GetPrimaryExtension(ext); |
41 | 0 | if (NS_SUCCEEDED(rv)) { |
42 | 0 | mimeInfo = nsGNOMERegistry::GetFromExtension(ext); |
43 | 0 | } |
44 | 0 | } |
45 | 0 | if (mimeInfo) |
46 | 0 | *_retval = true; |
47 | 0 | } |
48 | 0 |
|
49 | 0 | if (*_retval) |
50 | 0 | return NS_OK; |
51 | 0 | |
52 | 0 | return NS_OK; |
53 | 0 | } |
54 | | |
55 | | nsresult |
56 | | nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile *aFile) |
57 | 0 | { |
58 | 0 | // if mDefaultApplication is set, it means the application has been set from |
59 | 0 | // either /etc/mailcap or ${HOME}/.mailcap, in which case we don't want to |
60 | 0 | // give the GNOME answer. |
61 | 0 | if (mDefaultApplication) |
62 | 0 | return nsMIMEInfoImpl::LaunchDefaultWithFile(aFile); |
63 | 0 | |
64 | 0 | nsAutoCString nativePath; |
65 | 0 | aFile->GetNativePath(nativePath); |
66 | 0 |
|
67 | 0 | nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); |
68 | 0 | if (!giovfs) { |
69 | 0 | return NS_ERROR_FAILURE; |
70 | 0 | } |
71 | 0 | |
72 | 0 | // nsGIOMimeApp->Launch wants a URI string instead of local file |
73 | 0 | nsresult rv; |
74 | 0 | nsCOMPtr<nsIIOService> ioservice = do_GetService(NS_IOSERVICE_CONTRACTID, &rv); |
75 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
76 | 0 | nsCOMPtr<nsIURI> uri; |
77 | 0 | rv = ioservice->NewFileURI(aFile, getter_AddRefs(uri)); |
78 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
79 | 0 |
|
80 | 0 | nsCOMPtr<nsIHandlerApp> app; |
81 | 0 | if (NS_FAILED(giovfs->GetAppForMimeType(mSchemeOrType, getter_AddRefs(app))) || !app) { |
82 | 0 | return NS_ERROR_FILE_NOT_FOUND; |
83 | 0 | } |
84 | 0 | |
85 | 0 | return app->LaunchWithURI(uri, nullptr); |
86 | 0 | } |
87 | | |