Autogenerated with:
cp dom/.clang-format netwerk/ && mach format netwerk/**.{cpp,h,mm}
Manual fixes:
* mozurl/cbindgen.toml (including headers earlier)
* NetlinkService.h (forward-declaring a necessary struct)
* nsIWebSocketChannel.idl (forward-declaring OriginAttributes).
* nsAsyncRedirectVerifyHelper.h (forward-declaring nsIEventTarget)
* CapsuleEncoder.h gets a missing Capsule forward-decl.
* WebSocketConnectionBase.h gets some missing includes.
* HappyEyeballsConnectionAttempt gets some missing includes.
* nsUDPSocket missed nsSocketTransportService2.h for OnSocketThread().
* HttpInfo missed a forward declaration.
* MockHttpAuth missed an nsCOMPtr include.
* nsHttpAuthManager missed a forward declaration for nsIHttpAuthCache.
* WebTransportSessionProxy was using mozilla::Mutex in a member without
including it.
* win32 fixes to keep include order because windows headers suck.
* nsInputStreamPump needs an Atomics.h include.
Differential Revision: https://phabricator.services.mozilla.com/D311696
84 lines
2.7 KiB
C++
84 lines
2.7 KiB
C++
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "MozSrcProtocolHandler.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
#include "mozilla/ModuleUtils.h"
|
|
#include "mozilla/Omnijar.h"
|
|
#include "nsThreadUtils.h"
|
|
|
|
#define MOZSRC_SCHEME "moz-src"
|
|
|
|
namespace mozilla {
|
|
namespace net {
|
|
|
|
NS_IMPL_QUERY_INTERFACE(MozSrcProtocolHandler, nsISubstitutingProtocolHandler,
|
|
nsIProtocolHandler, nsISupportsWeakReference)
|
|
NS_IMPL_ADDREF_INHERITED(MozSrcProtocolHandler, SubstitutingProtocolHandler)
|
|
NS_IMPL_RELEASE_INHERITED(MozSrcProtocolHandler, SubstitutingProtocolHandler)
|
|
|
|
mozilla::StaticMutex MozSrcProtocolHandler::sMutex;
|
|
mozilla::StaticRefPtr<MozSrcProtocolHandler> MozSrcProtocolHandler::sSingleton;
|
|
|
|
already_AddRefed<MozSrcProtocolHandler> MozSrcProtocolHandler::GetSingleton() {
|
|
StaticMutexAutoLock lock(sMutex);
|
|
if (!sSingleton) {
|
|
RefPtr<MozSrcProtocolHandler> handler = new MozSrcProtocolHandler();
|
|
if (NS_WARN_IF(NS_FAILED(handler->Init()))) {
|
|
return nullptr;
|
|
}
|
|
sSingleton = handler;
|
|
auto prevent_shutdown_race = [] {
|
|
StaticMutexAutoLock lock(sMutex);
|
|
sSingleton = nullptr;
|
|
};
|
|
if (NS_IsMainThread()) {
|
|
RunOnShutdown(std::move(prevent_shutdown_race));
|
|
} else {
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
|
"MozSrcProtocolHandler::RunOnShutdown",
|
|
[prevent_shutdown_race = std::move(prevent_shutdown_race)]() mutable {
|
|
RunOnShutdown(std::move(prevent_shutdown_race));
|
|
}));
|
|
}
|
|
}
|
|
return do_AddRef(sSingleton);
|
|
}
|
|
|
|
MozSrcProtocolHandler::MozSrcProtocolHandler()
|
|
: SubstitutingProtocolHandler(MOZSRC_SCHEME) {}
|
|
|
|
nsresult MozSrcProtocolHandler::Init() {
|
|
nsresult rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, mGREURI);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mGREURI.AppendLiteral(MOZSRC_SCHEME);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
bool MozSrcProtocolHandler::ResolveSpecialCases(const nsACString& aHost,
|
|
const nsACString& aPath,
|
|
const nsACString& aPathname,
|
|
nsACString& aResult) {
|
|
aResult = mGREURI;
|
|
aResult.Append(aPathname);
|
|
return true;
|
|
}
|
|
|
|
nsresult MozSrcProtocolHandler::GetSubstitutionInternal(const nsACString& aRoot,
|
|
nsIURI** aResult) {
|
|
nsAutoCString uri;
|
|
|
|
if (!ResolveSpecialCases(aRoot, "/"_ns, "/"_ns, uri)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
|
|
return NS_NewURI(aResult, uri);
|
|
}
|
|
|
|
} // namespace net
|
|
} // namespace mozilla
|