/* 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/. */
using IPC::SerializedLoadContext; using mozilla::dom::BrowserParent; using mozilla::dom::ContentParent; using mozilla::dom::TCPServerSocketParent; using mozilla::dom::TCPSocketParent; using mozilla::dom::UDPSocketParent; using mozilla::ipc::LoadInfoArgsToLoadInfo; using mozilla::ipc::PrincipalInfo; #ifdef MOZ_PLACES using mozilla::places::PageIconProtocolHandler; #endif
namespace mozilla { namespace net {
// C++ file contents
NeckoParent::NeckoParent() : mSocketProcessBridgeInited(false) { // Init HTTP protocol handler now since we need atomTable up and running very // early (IPDL argument handling for PHttpChannel constructor needs it) so // normal init (during 1st Http channel request) isn't early enough.
nsCOMPtr<nsIProtocolHandler> proto =
do_GetService("@mozilla.org/network/protocol;1?name=http");
}
void NeckoParent::GetValidatedOriginAttributes( const SerializedLoadContext& aSerialized, PContentParent* aContent,
nsIPrincipal* aRequestingPrincipal, OriginAttributes& aAttrs) { if (!aSerialized.IsNotNull()) { // If serialized is null, we cannot validate anything. We have to assume // that this requests comes from a SystemPrincipal.
aAttrs = OriginAttributes();
} else {
aAttrs = aSerialized.mOriginAttributes;
}
}
void NeckoParent::ActorDestroy(ActorDestroyReason aWhy) { // Nothing needed here. Called right before destructor since this is a // non-refcounted class.
}
PAltDataOutputStreamParent* NeckoParent::AllocPAltDataOutputStreamParent( const nsACString& type, const int64_t& predictedSize,
PHttpChannelParent* channel) {
HttpChannelParent* chan = static_cast<HttpChannelParent*>(channel);
nsCOMPtr<nsIAsyncOutputStream> stream;
nsresult rv = chan->OpenAlternativeOutputStream(type, predictedSize,
getter_AddRefs(stream));
AltDataOutputStreamParent* parent = new AltDataOutputStreamParent(stream);
parent->AddRef(); // If the return value was not NS_OK, the error code will be sent // asynchronously to the child, after receiving the first message.
parent->SetError(rv); return parent;
}
PTCPSocketParent* NeckoParent::AllocPTCPSocketParent( const nsAString& /* host */, const uint16_t& /* port */) { // We actually don't need host/port to construct a TCPSocketParent since // TCPSocketParent will maintain an internal nsIDOMTCPSocket instance which // can be delegated to get the host/port.
TCPSocketParent* p = new TCPSocketParent();
p->AddIPDLReference(); return p;
}
mozilla::ipc::IPCResult NeckoParent::RecvGetExtensionStream(
nsIURI* aURI, GetExtensionStreamResolver&& aResolve) { if (!aURI) { return IPC_FAIL(this, "aURI must not be null");
}
// Ask the ExtensionProtocolHandler to give us a new input stream for // this URI. The request comes from an ExtensionProtocolHandler in the // child process, but is not guaranteed to be a valid moz-extension URI, // and not guaranteed to represent a resource that the child should be // allowed to access. The ExtensionProtocolHandler is responsible for // validating the request. Specifically, only URI's for local files that // an extension is allowed to access via moz-extension URI's should be // accepted.
nsCOMPtr<nsIInputStream> inputStream; bool terminateSender = true; auto inputStreamOrReason = ph->NewStream(aURI, &terminateSender); if (inputStreamOrReason.isOk()) {
inputStream = inputStreamOrReason.unwrap();
}
// If NewStream failed, we send back an invalid stream to the child so // it can handle the error. MozPromise rejection is reserved for channel // errors/disconnects.
aResolve(inputStream);
if (terminateSender) { return IPC_FAIL_NO_REASON(this);
} return IPC_OK();
}
mozilla::ipc::IPCResult NeckoParent::RecvGetExtensionFD(
nsIURI* aURI, GetExtensionFDResolver&& aResolve) { if (!aURI) { return IPC_FAIL(this, "aURI must not be null");
}
// Ask the ExtensionProtocolHandler to give us a new input stream for // this URI. The request comes from an ExtensionProtocolHandler in the // child process, but is not guaranteed to be a valid moz-extension URI, // and not guaranteed to represent a resource that the child should be // allowed to access. The ExtensionProtocolHandler is responsible for // validating the request. Specifically, only URI's for local files that // an extension is allowed to access via moz-extension URI's should be // accepted. bool terminateSender = true; auto result = ph->NewFD(aURI, &terminateSender, aResolve);
if (result.isErr() && terminateSender) { return IPC_FAIL_NO_REASON(this);
}
if (result.isErr()) {
FileDescriptor invalidFD;
aResolve(invalidFD);
}
// Initing the socket process bridge must be async here in order to // wait for the socket process launch before executing. auto task = [self = RefPtr{this}, resolver = std::move(aResolver)]() { // The content process might be already destroyed. if (!self->CanSend()) { return;
}
Endpoint<PSocketProcessBridgeChild> invalidEndpoint; if (NS_WARN_IF(self->mSocketProcessBridgeInited)) {
resolver(std::move(invalidEndpoint)); return;
}
RefPtr<SocketProcessParent> parent = SocketProcessParent::GetSingleton(); if (NS_WARN_IF(!parent)) {
resolver(std::move(invalidEndpoint)); return;
}
mozilla::ipc::IPCResult NeckoParent::RecvResetSocketProcessBridge() { // SendResetSocketProcessBridge is called from // SocketProcessBridgeChild::ActorDestroy if the socket process // crashes. This is necessary in order to properly initialize the // restarted socket process.
mSocketProcessBridgeInited = false; return IPC_OK();
}
mozilla::ipc::IPCResult NeckoParent::RecvGetPageThumbStream(
nsIURI* aURI, const LoadInfoArgs& aLoadInfoArgs,
GetPageThumbStreamResolver&& aResolver) { // Only the privileged about content process is allowed to access // things over the moz-page-thumb protocol. Any other content process // that tries to send this should have been blocked via the // ScriptSecurityManager, but if somehow the process has been tricked into // sending this message, we send IPC_FAIL in order to crash that // likely-compromised content process. if (static_cast<ContentParent*>(Manager())->GetRemoteType() !=
PRIVILEGEDABOUT_REMOTE_TYPE) { return IPC_FAIL(this, "Wrong process type");
}
// Ask the PageThumbProtocolHandler to give us a new input stream for // this URI. The request comes from a PageThumbProtocolHandler in the // child process, but is not guaranteed to be a valid moz-page-thumb URI, // and not guaranteed to represent a resource that the child should be // allowed to access. The PageThumbProtocolHandler is responsible for // validating the request.
nsCOMPtr<nsIInputStream> inputStream; bool terminateSender = true; auto inputStreamPromise = ph->NewStream(aURI, &terminateSender);
if (terminateSender) { return IPC_FAIL(this, "Malformed moz-page-thumb request");
}
inputStreamPromise->Then(
GetMainThreadSerialEventTarget(), __func__,
[aResolver](const RemoteStreamInfo& aInfo) { aResolver(Some(aInfo)); },
[aResolver](nsresult aRv) { // If NewStream failed, we send back an invalid stream to the child so // it can handle the error. MozPromise rejection is reserved for channel // errors/disconnects.
Unused << NS_WARN_IF(NS_FAILED(aRv));
aResolver(Nothing());
});
// Only the privileged about content process is allowed to access // things over the page-icon protocol. Any other content process // that tries to send this should have been blocked via the // ScriptSecurityManager, but if somehow the process has been tricked into // sending this message, we send IPC_FAIL in order to crash that // likely-compromised content process. if (remoteType != PRIVILEGEDABOUT_REMOTE_TYPE) { return IPC_FAIL(this, "Wrong process type");
}
nsCOMPtr<nsILoadInfo> loadInfo;
nsresult rv = mozilla::ipc::LoadInfoArgsToLoadInfo(aLoadInfoArgs, remoteType,
getter_AddRefs(loadInfo)); if (NS_FAILED(rv)) { return IPC_FAIL(this, "Page-icon request must include loadInfo");
}
if (terminateSender) { return IPC_FAIL(this, "Malformed page-icon request");
}
inputStreamPromise->Then(
GetMainThreadSerialEventTarget(), __func__,
[aResolver](const RemoteStreamInfo& aInfo) { aResolver(Some(aInfo)); },
[aResolver](nsresult aRv) { // If NewStream failed, we send back an invalid stream to the child so // it can handle the error. MozPromise rejection is reserved for channel // errors/disconnects.
Unused << NS_WARN_IF(NS_FAILED(aRv));
aResolver(Nothing());
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.