3
# User Gian-Carlo Pascutto <gcp@mozilla.com>
4
# Date 1504554539 -7200
5
# Node ID 8129c43822454eed4d5db20f78474623be6606f4
6
# Parent 2c2f9dc1f79bae7866c3ae041fcb46bb5dd4a106
7
Bug 1382323 - Remote OSProtocolHandlerExists. r=jld,smaug
9
MozReview-Commit-ID: Gml7cjbgUvK
11
diff --git a/ipc/ipdl/sync-messages.ini b/ipc/ipdl/sync-messages.ini
12
--- a/ipc/ipdl/sync-messages.ini
13
+++ b/ipc/ipdl/sync-messages.ini
14
@@ -1046,14 +1046,16 @@ description =
15
[PHal::LockScreenOrientation]
17
[PCookieService::GetCookieString]
19
[PPrinting::SavePrintSettings]
21
[PHandlerService::FillHandlerInfo]
23
+[PHandlerService::ExistsForProtocol]
24
+description = bug 1382323
25
[PHandlerService::Exists]
27
[PHandlerService::GetTypeFromExtension]
29
[PLayerTransaction::ShutdownSync]
30
description = bug 1363126
31
diff --git a/uriloader/exthandler/ContentHandlerService.cpp b/uriloader/exthandler/ContentHandlerService.cpp
32
--- a/uriloader/exthandler/ContentHandlerService.cpp
33
+++ b/uriloader/exthandler/ContentHandlerService.cpp
34
@@ -149,16 +149,24 @@ NS_IMETHODIMP ContentHandlerService::Exi
38
NS_IMETHODIMP ContentHandlerService::Remove(nsIHandlerInfo *aHandlerInfo)
40
return NS_ERROR_NOT_IMPLEMENTED;
44
+ContentHandlerService::ExistsForProtocol(const nsACString& aProtocolScheme, bool* aRetval)
46
+ if (!mHandlerServiceChild->SendExistsForProtocol(nsCString(aProtocolScheme), aRetval)) {
47
+ return NS_ERROR_FAILURE;
52
NS_IMETHODIMP ContentHandlerService::GetTypeFromExtension(const nsACString & aFileExtension, nsACString & _retval)
54
nsCString* cachedType = nullptr;
55
if (!!mExtToTypeMap.Get(aFileExtension, &cachedType) && !!cachedType) {
56
_retval.Assign(*cachedType);
59
diff --git a/uriloader/exthandler/HandlerServiceParent.cpp b/uriloader/exthandler/HandlerServiceParent.cpp
60
--- a/uriloader/exthandler/HandlerServiceParent.cpp
61
+++ b/uriloader/exthandler/HandlerServiceParent.cpp
63
+#include "mozilla/Logging.h"
64
#include "HandlerServiceParent.h"
65
#include "nsIHandlerService.h"
66
#include "nsIMIMEInfo.h"
67
#include "ContentHandlerService.h"
68
+#ifdef MOZ_WIDGET_GTK
69
+#include "unix/nsGNOMERegistry.h"
72
using mozilla::dom::HandlerInfo;
73
using mozilla::dom::HandlerApp;
74
using mozilla::dom::ContentHandlerService;
75
using mozilla::dom::RemoteHandlerApp;
79
@@ -255,16 +259,29 @@ HandlerServiceParent::RecvExists(const H
81
nsCOMPtr<nsIHandlerInfo> info(WrapHandlerInfo(aHandlerInfo));
82
nsCOMPtr<nsIHandlerService> handlerSvc = do_GetService(NS_HANDLERSERVICE_CONTRACTID);
83
handlerSvc->Exists(info, exists);
87
mozilla::ipc::IPCResult
88
+HandlerServiceParent::RecvExistsForProtocol(const nsCString& aProtocolScheme,
89
+ bool* aHandlerExists)
91
+#ifdef MOZ_WIDGET_GTK
92
+ // Check the GNOME registry for a protocol handler
93
+ *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme.get());
95
+ *aHandlerExists = false;
100
+mozilla::ipc::IPCResult
101
HandlerServiceParent::RecvGetTypeFromExtension(const nsCString& aFileExtension,
104
nsCOMPtr<nsIHandlerService> handlerSvc = do_GetService(NS_HANDLERSERVICE_CONTRACTID);
105
handlerSvc->GetTypeFromExtension(aFileExtension, *type);
109
diff --git a/uriloader/exthandler/HandlerServiceParent.h b/uriloader/exthandler/HandlerServiceParent.h
110
--- a/uriloader/exthandler/HandlerServiceParent.h
111
+++ b/uriloader/exthandler/HandlerServiceParent.h
112
@@ -21,11 +21,14 @@ class HandlerServiceParent final : publi
113
const nsCString& aOverrideType,
114
HandlerInfo* handlerInfoData) override;
115
virtual mozilla::ipc::IPCResult RecvExists(const HandlerInfo& aHandlerInfo,
116
bool* exits) override;
118
virtual mozilla::ipc::IPCResult RecvGetTypeFromExtension(const nsCString& aFileExtension,
119
nsCString* type) override;
121
+ virtual mozilla::ipc::IPCResult RecvExistsForProtocol(const nsCString& aProtocolScheme,
122
+ bool* aHandlerExists) override;
127
diff --git a/uriloader/exthandler/PHandlerService.ipdl b/uriloader/exthandler/PHandlerService.ipdl
128
--- a/uriloader/exthandler/PHandlerService.ipdl
129
+++ b/uriloader/exthandler/PHandlerService.ipdl
130
@@ -25,16 +25,18 @@ struct HandlerInfo {
131
sync protocol PHandlerService
136
sync FillHandlerInfo(HandlerInfo aHandlerInfoData,
137
nsCString aOverrideType)
138
returns (HandlerInfo handlerInfoData);
139
+ sync ExistsForProtocol(nsCString aProtocolScheme)
140
+ returns (bool exists);
141
sync Exists(HandlerInfo aHandlerInfo)
142
returns (bool exists);
143
sync GetTypeFromExtension(nsCString aFileExtension)
144
returns (nsCString type);
149
diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp
150
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
151
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
152
@@ -898,27 +898,27 @@ nsresult nsExternalHelperAppService::Get
153
// begin external protocol service default implementation...
154
//////////////////////////////////////////////////////////////////////////////////////////////////////
155
NS_IMETHODIMP nsExternalHelperAppService::ExternalProtocolHandlerExists(const char * aProtocolScheme,
156
bool * aHandlerExists)
158
nsCOMPtr<nsIHandlerInfo> handlerInfo;
159
nsresult rv = GetProtocolHandlerInfo(nsDependentCString(aProtocolScheme),
160
getter_AddRefs(handlerInfo));
161
- NS_ENSURE_SUCCESS(rv, rv);
163
- // See if we have any known possible handler apps for this
164
- nsCOMPtr<nsIMutableArray> possibleHandlers;
165
- handlerInfo->GetPossibleApplicationHandlers(getter_AddRefs(possibleHandlers));
168
- possibleHandlers->GetLength(&length);
170
- *aHandlerExists = true;
172
+ if (NS_SUCCEEDED(rv)) {
173
+ // See if we have any known possible handler apps for this
174
+ nsCOMPtr<nsIMutableArray> possibleHandlers;
175
+ handlerInfo->GetPossibleApplicationHandlers(getter_AddRefs(possibleHandlers));
178
+ possibleHandlers->GetLength(&length);
180
+ *aHandlerExists = true;
185
// if not, fall back on an os-based handler
186
return OSProtocolHandlerExists(aProtocolScheme, aHandlerExists);
189
NS_IMETHODIMP nsExternalHelperAppService::IsExposedProtocol(const char * aProtocolScheme, bool * aResult)
191
diff --git a/uriloader/exthandler/nsIHandlerService.idl b/uriloader/exthandler/nsIHandlerService.idl
192
--- a/uriloader/exthandler/nsIHandlerService.idl
193
+++ b/uriloader/exthandler/nsIHandlerService.idl
194
@@ -115,9 +115,19 @@ interface nsIHandlerService : nsISupport
195
* of other sources besides just the datastore. Use this only when you want
196
* to specifically get only the mapping available in the datastore.
198
* @param aFileExtension the file extension
200
* @returns the MIME type, if any; otherwise returns an empty string ("").
202
ACString getTypeFromExtension(in ACString aFileExtension);
205
+ * Whether or not there is a handler known to the OS for the
206
+ * specified protocol type.
208
+ * @param aProtocolScheme scheme to check for support
210
+ * @returns whether or not a handler exists
212
+ boolean existsForProtocol(in ACString aProtocolScheme);
214
diff --git a/uriloader/exthandler/unix/nsOSHelperAppService.cpp b/uriloader/exthandler/unix/nsOSHelperAppService.cpp
215
--- a/uriloader/exthandler/unix/nsOSHelperAppService.cpp
216
+++ b/uriloader/exthandler/unix/nsOSHelperAppService.cpp
219
* This Source Code Form is subject to the terms of the Mozilla Public
220
* License, v. 2.0. If a copy of the MPL was not distributed with this
221
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
223
#include <sys/types.h>
224
#include <sys/stat.h>
226
-#if defined(MOZ_ENABLE_CONTENTACTION)
227
-#include <contentaction/contentaction.h>
231
#include "nsOSHelperAppService.h"
232
#include "nsMIMEInfoUnix.h"
233
#ifdef MOZ_WIDGET_GTK
234
#include "nsGNOMERegistry.h"
236
#include "nsISupports.h"
237
#include "nsString.h"
238
#include "nsReadableUtils.h"
241
#include "nsIProcess.h"
242
#include "nsNetCID.h"
244
#include "nsISupportsPrimitives.h"
246
#include "nsDirectoryServiceDefs.h"
247
#include "nsDirectoryServiceUtils.h"
248
+#include "ContentHandlerService.h"
249
#include "prenv.h" // for PR_GetEnv()
250
#include "nsAutoPtr.h"
251
#include "mozilla/Preferences.h"
253
using namespace mozilla;
255
#define LOG(args) MOZ_LOG(mLog, mozilla::LogLevel::Debug, args)
256
#define LOG_ENABLED() MOZ_LOG_TEST(mLog, mozilla::LogLevel::Debug)
257
@@ -1127,35 +1123,34 @@ nsOSHelperAppService::GetHandlerAndDescr
258
rv = mailcap->ReadLine(cBuffer, &more);
259
} while (NS_SUCCEEDED(rv));
260
mailcapFile->Close();
264
nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, bool * aHandlerExists)
266
- LOG(("-- nsOSHelperAppService::OSProtocolHandlerExists for '%s'\n",
268
- *aHandlerExists = false;
270
-#if defined(MOZ_ENABLE_CONTENTACTION)
271
- // libcontentaction requires character ':' after scheme
272
- ContentAction::Action action =
273
- ContentAction::Action::defaultActionForScheme(QString(aProtocolScheme) + ':');
274
+ nsresult rv = NS_OK;
276
- if (action.isValid())
277
- *aHandlerExists = true;
280
+ if (!XRE_IsContentProcess()) {
281
#ifdef MOZ_WIDGET_GTK
282
- // Check the GNOME registry for a protocol handler
283
- *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme);
284
+ // Check the GNOME registry for a protocol handler
285
+ *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme);
287
+ *aHandlerExists = false;
290
+ *aHandlerExists = false;
291
+ nsCOMPtr<nsIHandlerService> handlerSvc = do_GetService(NS_HANDLERSERVICE_CONTRACTID, &rv);
292
+ if (NS_SUCCEEDED(rv) && handlerSvc) {
293
+ rv = handlerSvc->ExistsForProtocol(nsCString(aProtocolScheme), aHandlerExists);
301
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval)
303
#ifdef MOZ_WIDGET_GTK
304
nsGNOMERegistry::GetAppDescForScheme(aScheme, _retval);
305
return _retval.IsEmpty() ? NS_ERROR_NOT_AVAILABLE : NS_OK;