Bug 1728955: part 8) Refactor `DisplayErrCode` in Windows' `nsClipboard`. r=masayuki
[gecko.git] / uriloader / exthandler / nsOSHelperAppServiceChild.cpp
blob1e1442fac6a3d3a51ef8b3ef30fd657e12c2fade
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 <sys/types.h>
8 #include <sys/stat.h>
9 #include "mozilla/Logging.h"
10 #include "mozilla/net/NeckoCommon.h"
11 #include "nsOSHelperAppServiceChild.h"
12 #include "nsMIMEInfoChild.h"
13 #include "nsISupports.h"
14 #include "nsString.h"
15 #include "nsTArray.h"
16 #include "nsIFile.h"
17 #include "nsIHandlerService.h"
18 #include "nsMimeTypes.h"
19 #include "nsMIMEInfoImpl.h"
20 #include "nsMemory.h"
21 #include "nsCRT.h"
22 #include "nsEmbedCID.h"
24 #undef LOG
25 #define LOG(args) \
26 MOZ_LOG(nsExternalHelperAppService::mLog, mozilla::LogLevel::Info, args)
27 #undef LOG_ERR
28 #define LOG_ERR(args) \
29 MOZ_LOG(nsExternalHelperAppService::mLog, mozilla::LogLevel::Error, args)
30 #undef LOG_ENABLED
31 #define LOG_ENABLED() \
32 MOZ_LOG_TEST(nsExternalHelperAppService::mLog, mozilla::LogLevel::Info)
34 nsresult nsOSHelperAppServiceChild::ExternalProtocolHandlerExists(
35 const char* aProtocolScheme, bool* aHandlerExists) {
36 nsresult rv;
37 nsCOMPtr<nsIHandlerService> handlerSvc =
38 do_GetService(NS_HANDLERSERVICE_CONTRACTID, &rv);
39 if (NS_WARN_IF(NS_FAILED(rv))) {
40 LOG_ERR(("nsOSHelperAppServiceChild error: no handler service"));
41 return rv;
44 nsAutoCString scheme(aProtocolScheme);
45 *aHandlerExists = false;
46 rv = handlerSvc->ExistsForProtocol(scheme, aHandlerExists);
47 LOG(
48 ("nsOSHelperAppServiceChild::ExternalProtocolHandlerExists(): "
49 "protocol: %s, result: %" PRId32,
50 aProtocolScheme, static_cast<uint32_t>(rv)));
51 mozilla::Unused << NS_WARN_IF(NS_FAILED(rv));
52 return rv;
55 nsresult nsOSHelperAppServiceChild::OSProtocolHandlerExists(const char* aScheme,
56 bool* aExists) {
57 // Use ExternalProtocolHandlerExists() which includes the
58 // OS-level check and remotes the call to the parent process.
59 return NS_ERROR_NOT_IMPLEMENTED;
62 NS_IMETHODIMP
63 nsOSHelperAppServiceChild::GetApplicationDescription(const nsACString& aScheme,
64 nsAString& aRetVal) {
65 nsresult rv;
66 nsCOMPtr<nsIHandlerService> handlerSvc =
67 do_GetService(NS_HANDLERSERVICE_CONTRACTID, &rv);
68 if (NS_WARN_IF(NS_FAILED(rv))) {
69 LOG_ERR(("nsOSHelperAppServiceChild error: no handler service"));
70 return rv;
73 rv = handlerSvc->GetApplicationDescription(aScheme, aRetVal);
74 LOG(
75 ("nsOSHelperAppServiceChild::GetApplicationDescription(): "
76 "scheme: %s, result: %" PRId32 ", description: %s",
77 PromiseFlatCString(aScheme).get(), static_cast<uint32_t>(rv),
78 NS_ConvertUTF16toUTF8(aRetVal).get()));
79 mozilla::Unused << NS_WARN_IF(NS_FAILED(rv));
80 return rv;
83 NS_IMETHODIMP
84 nsOSHelperAppServiceChild::GetMIMEInfoFromOS(const nsACString& aMIMEType,
85 const nsACString& aFileExt,
86 bool* aFound,
87 nsIMIMEInfo** aMIMEInfo) {
88 RefPtr<nsChildProcessMIMEInfo> mimeInfo =
89 new nsChildProcessMIMEInfo(aMIMEType);
91 nsCOMPtr<nsIHandlerService> handlerSvc =
92 do_GetService(NS_HANDLERSERVICE_CONTRACTID);
93 if (handlerSvc) {
94 nsresult rv =
95 handlerSvc->GetMIMEInfoFromOS(mimeInfo, aMIMEType, aFileExt, aFound);
96 LOG(
97 ("nsOSHelperAppServiceChild::GetMIMEInfoFromOS(): "
98 "MIME type: %s, extension: %s, result: %" PRId32,
99 PromiseFlatCString(aMIMEType).get(),
100 PromiseFlatCString(aFileExt).get(), static_cast<uint32_t>(rv)));
101 mozilla::Unused << NS_WARN_IF(NS_FAILED(rv));
102 if (NS_FAILED(rv)) {
103 return rv;
105 } else {
106 LOG_ERR(("nsOSHelperAppServiceChild error: no handler service"));
107 *aFound = false;
110 mimeInfo.forget(aMIMEInfo);
111 return NS_OK;
114 NS_IMETHODIMP
115 nsOSHelperAppServiceChild::GetProtocolHandlerInfoFromOS(
116 const nsACString& aScheme, bool* aFound, nsIHandlerInfo** aRetVal) {
117 return NS_ERROR_NOT_IMPLEMENTED;
120 NS_IMETHODIMP
121 nsOSHelperAppServiceChild::IsCurrentAppOSDefaultForProtocol(
122 const nsACString& aScheme, bool* aRetVal) {
123 return NS_ERROR_NOT_IMPLEMENTED;
126 nsresult nsOSHelperAppServiceChild::GetFileTokenForPath(
127 const char16_t* platformAppPath, nsIFile** aFile) {
128 return NS_ERROR_NOT_IMPLEMENTED;