1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=4 sw=2 sts=2 et cin: */
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/. */
9 #include "nsContentUtils.h"
10 #include "nsHttpHandler.h"
11 #include "nsIHttpChannel.h"
12 #include "nsIHttpChannelInternal.h"
13 #include "nsIIOService.h"
14 #include "mozilla/SyncRunnable.h"
15 #include "TRRServiceChannel.h"
16 #include "TRRLoadInfo.h"
21 static void InitHttpHandler() {
23 nsCOMPtr
<nsIIOService
> ios
= do_GetIOService(&rv
);
28 nsCOMPtr
<nsIProtocolHandler
> handler
;
29 rv
= ios
->GetProtocolHandler("http", getter_AddRefs(handler
));
36 nsresult
DNSUtils::CreateChannelHelper(nsIURI
* aUri
, nsIChannel
** aResult
) {
39 if (NS_IsMainThread() && !XRE_IsSocketProcess()) {
41 nsCOMPtr
<nsIIOService
> ios(do_GetIOService(&rv
));
42 NS_ENSURE_SUCCESS(rv
, rv
);
45 aResult
, aUri
, nsContentUtils::GetSystemPrincipal(),
46 nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL
,
47 nsIContentPolicy::TYPE_OTHER
,
48 nullptr, // nsICookieJarSettings
49 nullptr, // PerformanceStorage
50 nullptr, // aLoadGroup
51 nullptr, // aCallbacks
52 nsIRequest::LOAD_NORMAL
, ios
);
55 // Unfortunately, we can only initialize gHttpHandler on main thread.
57 nsCOMPtr
<nsIEventTarget
> main
= GetMainThreadEventTarget();
59 // Forward to the main thread synchronously.
60 SyncRunnable::DispatchToThread(
61 main
, new SyncRunnable(NS_NewRunnableFunction(
62 "InitHttpHandler", []() { InitHttpHandler(); })));
67 return NS_ERROR_UNEXPECTED
;
70 RefPtr
<TRRLoadInfo
> loadInfo
=
71 new TRRLoadInfo(aUri
, nsIContentPolicy::TYPE_OTHER
);
72 return gHttpHandler
->CreateTRRServiceChannel(aUri
,
73 nullptr, // givenProxyInfo
74 0, // proxyResolveFlags
76 loadInfo
, // aLoadInfo
81 } // namespace mozilla