Bug 1825212 [wpt PR 39266] - [@scope] Propagate proximity from SubResult, a=testonly
[gecko.git] / uriloader / exthandler / nsOSHelperAppServiceChild.cpp
blob8ba3a2edc98267c98299ad25af6322cb53ea1236
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 "nsISupports.h"
13 #include "nsString.h"
14 #include "nsTArray.h"
15 #include "nsIFile.h"
16 #include "nsIHandlerService.h"
17 #include "nsMimeTypes.h"
18 #include "nsMIMEInfoImpl.h"
19 #include "nsCExternalHandlerService.h"
20 #include "nsCRT.h"
21 #include "nsEmbedCID.h"
23 #undef LOG
24 #define LOG(...) \
25 MOZ_LOG(nsExternalHelperAppService::sLog, mozilla::LogLevel::Info, \
26 (__VA_ARGS__))
27 #undef LOG_ERR
28 #define LOG_ERR(...) \
29 MOZ_LOG(nsExternalHelperAppService::sLog, mozilla::LogLevel::Error, \
30 (__VA_ARGS__))
31 #undef LOG_ENABLED
32 #define LOG_ENABLED() \
33 MOZ_LOG_TEST(nsExternalHelperAppService::sLog, mozilla::LogLevel::Info)
35 nsresult nsOSHelperAppServiceChild::ExternalProtocolHandlerExists(
36 const char* aProtocolScheme, bool* aHandlerExists) {
37 nsresult rv;
38 nsCOMPtr<nsIHandlerService> handlerSvc =
39 do_GetService(NS_HANDLERSERVICE_CONTRACTID, &rv);
40 if (NS_WARN_IF(NS_FAILED(rv))) {
41 LOG_ERR("nsOSHelperAppServiceChild error: no handler service");
42 return rv;
45 nsAutoCString scheme(aProtocolScheme);
46 *aHandlerExists = false;
47 rv = handlerSvc->ExistsForProtocol(scheme, aHandlerExists);
48 LOG("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("nsOSHelperAppServiceChild::GetApplicationDescription(): "
75 "scheme: %s, result: %" PRId32 ", description: %s",
76 PromiseFlatCString(aScheme).get(), static_cast<uint32_t>(rv),
77 NS_ConvertUTF16toUTF8(aRetVal).get());
78 mozilla::Unused << NS_WARN_IF(NS_FAILED(rv));
79 return rv;
82 NS_IMETHODIMP
83 nsOSHelperAppServiceChild::GetMIMEInfoFromOS(const nsACString& aMIMEType,
84 const nsACString& aFileExt,
85 bool* aFound,
86 nsIMIMEInfo** aMIMEInfo) {
87 nsresult rv;
88 nsCOMPtr<nsIHandlerService> handlerSvc =
89 do_GetService(NS_HANDLERSERVICE_CONTRACTID, &rv);
90 if (NS_WARN_IF(NS_FAILED(rv))) {
91 LOG_ERR("nsOSHelperAppServiceChild error: no handler service");
92 return rv;
95 rv = handlerSvc->GetMIMEInfoFromOS(aMIMEType, aFileExt, aFound, aMIMEInfo);
96 LOG("nsOSHelperAppServiceChild::GetMIMEInfoFromOS(): "
97 "MIME type: %s, extension: %s, result: %" PRId32,
98 PromiseFlatCString(aMIMEType).get(), PromiseFlatCString(aFileExt).get(),
99 static_cast<uint32_t>(rv));
100 mozilla::Unused << NS_WARN_IF(NS_FAILED(rv));
101 return rv;
104 NS_IMETHODIMP
105 nsOSHelperAppServiceChild::GetProtocolHandlerInfoFromOS(
106 const nsACString& aScheme, bool* aFound, nsIHandlerInfo** aRetVal) {
107 return NS_ERROR_NOT_IMPLEMENTED;
110 NS_IMETHODIMP
111 nsOSHelperAppServiceChild::IsCurrentAppOSDefaultForProtocol(
112 const nsACString& aScheme, bool* aRetVal) {
113 return NS_ERROR_NOT_IMPLEMENTED;
116 nsresult nsOSHelperAppServiceChild::GetFileTokenForPath(
117 const char16_t* platformAppPath, nsIFile** aFile) {
118 return NS_ERROR_NOT_IMPLEMENTED;