/src/mozilla-central/uriloader/exthandler/HandlerServiceParent.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include "mozilla/Logging.h" |
2 | | #include "HandlerServiceParent.h" |
3 | | #include "nsIHandlerService.h" |
4 | | #include "nsIMIMEInfo.h" |
5 | | #include "ContentHandlerService.h" |
6 | | #include "nsStringEnumerator.h" |
7 | | #ifdef MOZ_WIDGET_GTK |
8 | | #include "unix/nsGNOMERegistry.h" |
9 | | #endif |
10 | | |
11 | | using mozilla::dom::HandlerInfo; |
12 | | using mozilla::dom::HandlerApp; |
13 | | using mozilla::dom::ContentHandlerService; |
14 | | using mozilla::dom::RemoteHandlerApp; |
15 | | |
16 | | namespace { |
17 | | |
18 | | class ProxyHandlerInfo final : public nsIHandlerInfo { |
19 | | public: |
20 | | explicit ProxyHandlerInfo(const HandlerInfo& aHandlerInfo); |
21 | | NS_DECL_ISUPPORTS; |
22 | | NS_DECL_NSIHANDLERINFO; |
23 | | |
24 | 0 | nsTArray<nsCString>& Extensions() { |
25 | 0 | return mHandlerInfo.extensions(); |
26 | 0 | } |
27 | | |
28 | | protected: |
29 | 0 | ~ProxyHandlerInfo() {} |
30 | | HandlerInfo mHandlerInfo; |
31 | | nsHandlerInfoAction mPrefAction; |
32 | | nsCOMPtr<nsIMutableArray> mPossibleApps; |
33 | | }; |
34 | | |
35 | | NS_IMPL_ISUPPORTS(ProxyHandlerInfo, nsIHandlerInfo) |
36 | | |
37 | | ProxyHandlerInfo::ProxyHandlerInfo(const HandlerInfo& aHandlerInfo) |
38 | | : mHandlerInfo(aHandlerInfo), |
39 | | mPrefAction(nsIHandlerInfo::alwaysAsk), |
40 | | mPossibleApps(do_CreateInstance(NS_ARRAY_CONTRACTID)) |
41 | 0 | { |
42 | 0 | for (auto& happ : aHandlerInfo.possibleApplicationHandlers()) { |
43 | 0 | mPossibleApps->AppendElement(new RemoteHandlerApp(happ)); |
44 | 0 | } |
45 | 0 | } |
46 | | |
47 | | /* readonly attribute ACString type; */ |
48 | | NS_IMETHODIMP ProxyHandlerInfo::GetType(nsACString & aType) |
49 | 0 | { |
50 | 0 | aType.Assign(mHandlerInfo.type()); |
51 | 0 | return NS_OK; |
52 | 0 | } |
53 | | |
54 | | /* attribute AString description; */ |
55 | | NS_IMETHODIMP ProxyHandlerInfo::GetDescription(nsAString & aDescription) |
56 | 0 | { |
57 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
58 | 0 | } |
59 | | NS_IMETHODIMP ProxyHandlerInfo::SetDescription(const nsAString & aDescription) |
60 | 0 | { |
61 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
62 | 0 | } |
63 | | |
64 | | /* attribute nsIHandlerApp preferredApplicationHandler; */ |
65 | | NS_IMETHODIMP ProxyHandlerInfo::GetPreferredApplicationHandler(nsIHandlerApp * *aPreferredApplicationHandler) |
66 | 0 | { |
67 | 0 | *aPreferredApplicationHandler = new RemoteHandlerApp(mHandlerInfo.preferredApplicationHandler()); |
68 | 0 | NS_IF_ADDREF(*aPreferredApplicationHandler); |
69 | 0 | return NS_OK; |
70 | 0 | } |
71 | | |
72 | | NS_IMETHODIMP ProxyHandlerInfo::SetPreferredApplicationHandler(nsIHandlerApp *aApp) |
73 | 0 | { |
74 | 0 | nsString name; |
75 | 0 | nsString detailedDescription; |
76 | 0 | if (aApp) { |
77 | 0 | aApp->GetName(name); |
78 | 0 | aApp->GetDetailedDescription(detailedDescription); |
79 | 0 | } |
80 | 0 |
|
81 | 0 | mHandlerInfo.preferredApplicationHandler() = HandlerApp(name, detailedDescription); |
82 | 0 | return NS_OK; |
83 | 0 | } |
84 | | |
85 | | /* readonly attribute nsIMutableArray possibleApplicationHandlers; */ |
86 | | NS_IMETHODIMP ProxyHandlerInfo::GetPossibleApplicationHandlers(nsIMutableArray * *aPossibleApplicationHandlers) |
87 | 0 | { |
88 | 0 | *aPossibleApplicationHandlers = mPossibleApps; |
89 | 0 | NS_IF_ADDREF(*aPossibleApplicationHandlers); |
90 | 0 | return NS_OK; |
91 | 0 | } |
92 | | |
93 | | /* readonly attribute boolean hasDefaultHandler; */ |
94 | | NS_IMETHODIMP ProxyHandlerInfo::GetHasDefaultHandler(bool *aHasDefaultHandler) |
95 | 0 | { |
96 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
97 | 0 | } |
98 | | |
99 | | /* readonly attribute AString defaultDescription; */ |
100 | | NS_IMETHODIMP ProxyHandlerInfo::GetDefaultDescription(nsAString & aDefaultDescription) |
101 | 0 | { |
102 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
103 | 0 | } |
104 | | |
105 | | /* void launchWithURI (in nsIURI aURI, [optional] in nsIInterfaceRequestor aWindowContext); */ |
106 | | NS_IMETHODIMP ProxyHandlerInfo::LaunchWithURI(nsIURI *aURI, nsIInterfaceRequestor *aWindowContext) |
107 | 0 | { |
108 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
109 | 0 | } |
110 | | |
111 | | /* attribute ProxyHandlerInfoAction preferredAction; */ |
112 | | NS_IMETHODIMP ProxyHandlerInfo::GetPreferredAction(nsHandlerInfoAction *aPreferredAction) |
113 | 0 | { |
114 | 0 | *aPreferredAction = mPrefAction; |
115 | 0 | return NS_OK; |
116 | 0 | } |
117 | | NS_IMETHODIMP ProxyHandlerInfo::SetPreferredAction(nsHandlerInfoAction aPreferredAction) |
118 | 0 | { |
119 | 0 | mHandlerInfo.preferredAction() = aPreferredAction; |
120 | 0 | mPrefAction = aPreferredAction; |
121 | 0 | return NS_OK; |
122 | 0 | } |
123 | | |
124 | | /* attribute boolean alwaysAskBeforeHandling; */ |
125 | | NS_IMETHODIMP ProxyHandlerInfo::GetAlwaysAskBeforeHandling(bool *aAlwaysAskBeforeHandling) |
126 | 0 | { |
127 | 0 | *aAlwaysAskBeforeHandling = mHandlerInfo.alwaysAskBeforeHandling(); |
128 | 0 | return NS_OK; |
129 | 0 | } |
130 | | NS_IMETHODIMP ProxyHandlerInfo::SetAlwaysAskBeforeHandling(bool aAlwaysAskBeforeHandling) |
131 | 0 | { |
132 | 0 | mHandlerInfo.alwaysAskBeforeHandling() = aAlwaysAskBeforeHandling; |
133 | 0 | return NS_OK; |
134 | 0 | } |
135 | | |
136 | | |
137 | | class ProxyMIMEInfo : public nsIMIMEInfo |
138 | | { |
139 | | public: |
140 | | NS_DECL_ISUPPORTS |
141 | | NS_DECL_NSIMIMEINFO |
142 | | NS_FORWARD_NSIHANDLERINFO(mProxyHandlerInfo->); |
143 | | |
144 | | explicit ProxyMIMEInfo(const HandlerInfo &aHandlerInfo) |
145 | | : mProxyHandlerInfo(new ProxyHandlerInfo(aHandlerInfo)) |
146 | 0 | { |
147 | 0 | } |
148 | | |
149 | | private: |
150 | 0 | virtual ~ProxyMIMEInfo() {} |
151 | | RefPtr<ProxyHandlerInfo> mProxyHandlerInfo; |
152 | | |
153 | | protected: |
154 | | /* additional members */ |
155 | | }; |
156 | | |
157 | | NS_IMPL_ISUPPORTS(ProxyMIMEInfo, nsIMIMEInfo, nsIHandlerInfo) |
158 | | |
159 | | /* nsIUTF8StringEnumerator getFileExtensions (); */ |
160 | | NS_IMETHODIMP ProxyMIMEInfo::GetFileExtensions(nsIUTF8StringEnumerator * *_retval) |
161 | 0 | { |
162 | 0 | return NS_NewUTF8StringEnumerator(_retval, &mProxyHandlerInfo->Extensions(), this); |
163 | 0 | } |
164 | | |
165 | | /* void setFileExtensions (in AUTF8String aExtensions); */ |
166 | | NS_IMETHODIMP ProxyMIMEInfo::SetFileExtensions(const nsACString & aExtensions) |
167 | 0 | { |
168 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
169 | 0 | } |
170 | | |
171 | | /* boolean extensionExists (in AUTF8String aExtension); */ |
172 | | NS_IMETHODIMP ProxyMIMEInfo::ExtensionExists(const nsACString & aExtension, bool *_retval) |
173 | 0 | { |
174 | 0 | *_retval = mProxyHandlerInfo->Extensions().Contains(aExtension); |
175 | 0 | return NS_OK; |
176 | 0 | } |
177 | | |
178 | | /* void appendExtension (in AUTF8String aExtension); */ |
179 | | NS_IMETHODIMP ProxyMIMEInfo::AppendExtension(const nsACString & aExtension) |
180 | 0 | { |
181 | 0 | mProxyHandlerInfo->Extensions().AppendElement(aExtension); |
182 | 0 | return NS_OK; |
183 | 0 | } |
184 | | |
185 | | /* attribute AUTF8String primaryExtension; */ |
186 | | NS_IMETHODIMP ProxyMIMEInfo::GetPrimaryExtension(nsACString & aPrimaryExtension) |
187 | 0 | { |
188 | 0 | const auto& extensions = mProxyHandlerInfo->Extensions(); |
189 | 0 | if (extensions.IsEmpty()) { |
190 | 0 | return NS_ERROR_FAILURE; |
191 | 0 | } |
192 | 0 | aPrimaryExtension = extensions[0]; |
193 | 0 | return NS_OK; |
194 | 0 | } |
195 | | |
196 | | NS_IMETHODIMP ProxyMIMEInfo::SetPrimaryExtension(const nsACString & aPrimaryExtension) |
197 | 0 | { |
198 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
199 | 0 | } |
200 | | |
201 | | /* readonly attribute ACString MIMEType; */ |
202 | | NS_IMETHODIMP ProxyMIMEInfo::GetMIMEType(nsACString & aMIMEType) |
203 | 0 | { |
204 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
205 | 0 | } |
206 | | |
207 | | /* boolean equals (in nsIMIMEInfo aMIMEInfo); */ |
208 | | NS_IMETHODIMP ProxyMIMEInfo::Equals(nsIMIMEInfo *aMIMEInfo, bool *_retval) |
209 | 0 | { |
210 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
211 | 0 | } |
212 | | |
213 | | /* readonly attribute nsIArray possibleLocalHandlers; */ |
214 | | NS_IMETHODIMP ProxyMIMEInfo::GetPossibleLocalHandlers(nsIArray * *aPossibleLocalHandlers) |
215 | 0 | { |
216 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
217 | 0 | } |
218 | | |
219 | | /* void launchWithFile (in nsIFile aFile); */ |
220 | | NS_IMETHODIMP ProxyMIMEInfo::LaunchWithFile(nsIFile *aFile) |
221 | 0 | { |
222 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
223 | 0 | } |
224 | | |
225 | 0 | static already_AddRefed<nsIHandlerInfo> WrapHandlerInfo(const HandlerInfo& aHandlerInfo) { |
226 | 0 | nsCOMPtr<nsIHandlerInfo> info; |
227 | 0 | if (aHandlerInfo.isMIMEInfo()) { |
228 | 0 | info = new ProxyMIMEInfo(aHandlerInfo); |
229 | 0 | } else { |
230 | 0 | info = new ProxyHandlerInfo(aHandlerInfo); |
231 | 0 | } |
232 | 0 | return info.forget(); |
233 | 0 | } |
234 | | |
235 | | } // anonymous namespace |
236 | | |
237 | | HandlerServiceParent::HandlerServiceParent() |
238 | 0 | { |
239 | 0 | } |
240 | | |
241 | | HandlerServiceParent::~HandlerServiceParent() |
242 | 0 | { |
243 | 0 | } |
244 | | |
245 | | mozilla::ipc::IPCResult |
246 | | HandlerServiceParent::RecvFillHandlerInfo(const HandlerInfo& aHandlerInfoData, |
247 | | const nsCString& aOverrideType, |
248 | | HandlerInfo* handlerInfoData) |
249 | 0 | { |
250 | 0 | nsCOMPtr<nsIHandlerInfo> info(WrapHandlerInfo(aHandlerInfoData)); |
251 | 0 | nsCOMPtr<nsIHandlerService> handlerSvc = do_GetService(NS_HANDLERSERVICE_CONTRACTID); |
252 | 0 | handlerSvc->FillHandlerInfo(info, aOverrideType); |
253 | 0 | ContentHandlerService::nsIHandlerInfoToHandlerInfo(info, handlerInfoData); |
254 | 0 | return IPC_OK(); |
255 | 0 | } |
256 | | |
257 | | mozilla::ipc::IPCResult |
258 | | HandlerServiceParent::RecvExists(const HandlerInfo& aHandlerInfo, |
259 | | bool* exists) |
260 | 0 | { |
261 | 0 | nsCOMPtr<nsIHandlerInfo> info(WrapHandlerInfo(aHandlerInfo)); |
262 | 0 | nsCOMPtr<nsIHandlerService> handlerSvc = do_GetService(NS_HANDLERSERVICE_CONTRACTID); |
263 | 0 | handlerSvc->Exists(info, exists); |
264 | 0 | return IPC_OK(); |
265 | 0 | } |
266 | | |
267 | | mozilla::ipc::IPCResult |
268 | | HandlerServiceParent::RecvExistsForProtocol(const nsCString& aProtocolScheme, |
269 | | bool* aHandlerExists) |
270 | 0 | { |
271 | 0 | #ifdef MOZ_WIDGET_GTK |
272 | 0 | // Check the GNOME registry for a protocol handler |
273 | 0 | *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme.get()); |
274 | | #else |
275 | | *aHandlerExists = false; |
276 | | #endif |
277 | 0 | return IPC_OK(); |
278 | 0 | } |
279 | | |
280 | | mozilla::ipc::IPCResult |
281 | | HandlerServiceParent::RecvGetTypeFromExtension(const nsCString& aFileExtension, |
282 | | nsCString* type) |
283 | 0 | { |
284 | 0 | nsCOMPtr<nsIHandlerService> handlerSvc = do_GetService(NS_HANDLERSERVICE_CONTRACTID); |
285 | 0 | handlerSvc->GetTypeFromExtension(aFileExtension, *type); |
286 | 0 | return IPC_OK(); |
287 | 0 | } |
288 | | |
289 | | void HandlerServiceParent::ActorDestroy(ActorDestroyReason aWhy) |
290 | 0 | { |
291 | 0 | } |