tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit ad59af6512c1fdbc7a6c26ff993ed4ffaa03b05e
parent 6b617efd7ed250f0071d956fc999f642e0316b09
Author: Tom Schuster <tschuster@mozilla.com>
Date:   Mon, 17 Nov 2025 11:19:42 +0000

Bug 1985987 - Parse the moz-remote-image URL. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D264381

Diffstat:
Mimage/remote/RemoteImageProtocolHandler.cpp | 62+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mimage/remote/RemoteImageProtocolHandler.h | 2++
Mimage/remote/moz.build | 2++
3 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/image/remote/RemoteImageProtocolHandler.cpp b/image/remote/RemoteImageProtocolHandler.cpp @@ -5,8 +5,15 @@ #include "RemoteImageProtocolHandler.h" +#include "nsIURI.h" +#include "nsNetUtil.h" +#include "nsURLHelper.h" +#include "mozilla/dom/ipc/IdType.h" + namespace mozilla::image { +using mozilla::dom::ContentParentId; + StaticRefPtr<RemoteImageProtocolHandler> RemoteImageProtocolHandler::sSingleton; NS_IMPL_ISUPPORTS(RemoteImageProtocolHandler, nsIProtocolHandler, @@ -23,10 +30,63 @@ NS_IMETHODIMP RemoteImageProtocolHandler::AllowPort(int32_t, const char*, return NS_OK; } +// Parse out the relevant parts of the moz-remote-image URL +static nsresult ParseURI(nsIURI* aURI, nsIURI** aRemoteURI, ImageIntSize* aSize, + Maybe<ContentParentId>& aContentParentId) { + MOZ_ASSERT(aURI->SchemeIs("moz-remote-image")); + + nsAutoCString query; + MOZ_TRY(aURI->GetQuery(query)); + + bool hasURL; + int32_t width = 0; + int32_t height = 0; + + bool ok = URLParams::Parse( + query, true, [&](const nsACString& aName, const nsACString& aValue) { + nsresult rv; + if (aName.EqualsLiteral("url")) { + hasURL = true; + rv = NS_NewURI(aRemoteURI, aValue); + if (NS_FAILED(rv)) { + return false; + } + } else if (aName.EqualsLiteral("width")) { + width = aValue.ToInteger(&rv); + if (NS_FAILED(rv) || width < 0) { + return false; + } + } else if (aName.EqualsLiteral("height")) { + height = aValue.ToInteger(&rv); + if (NS_FAILED(rv) || height < 0) { + return false; + } + } else if (aName.EqualsLiteral("contentParentId")) { + int64_t id = aValue.ToInteger(&rv); + if (NS_FAILED(rv) || id < 0) { + return false; + } + aContentParentId = Some(ContentParentId(uint64_t(id))); + } + return true; + }); + if (NS_WARN_IF(!ok || !hasURL)) { + return NS_ERROR_DOM_MALFORMED_URI; + } + + *aSize = ImageIntSize(width, height); + return NS_OK; +} + NS_IMETHODIMP RemoteImageProtocolHandler::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, nsIChannel** aOutChannel) { + nsCOMPtr<nsIURI> remoteURI; + ImageIntSize size; + Maybe<ContentParentId> contentParentId; + MOZ_TRY(ParseURI(aURI, getter_AddRefs(remoteURI), &size, contentParentId)); + return NS_ERROR_NOT_IMPLEMENTED; } -} // namespace mozilla::image +} // namespace mozilla::image diff --git a/image/remote/RemoteImageProtocolHandler.h b/image/remote/RemoteImageProtocolHandler.h @@ -9,6 +9,8 @@ #include "mozilla/AlreadyAddRefed.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/StaticPtr.h" +#include "mozilla/dom/ContentParent.h" +#include "mozilla/MozPromise.h" #include "nsIProtocolHandler.h" #include "nsThreadUtils.h" #include "nsWeakReference.h" diff --git a/image/remote/moz.build b/image/remote/moz.build @@ -16,4 +16,6 @@ UNIFIED_SOURCES += [ "RemoteImageProtocolHandler.cpp", ] +include("/ipc/chromium/chromium-config.mozbuild") + FINAL_LIBRARY = "xul"