tor-browser

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

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

Bug 1985987 - Define the moz-remote-image protocol. r=necko-reviewers,valentin

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

Diffstat:
Mimage/moz.build | 2+-
Aimage/remote/RemoteImageProtocolHandler.cpp | 32++++++++++++++++++++++++++++++++
Aimage/remote/RemoteImageProtocolHandler.h | 41+++++++++++++++++++++++++++++++++++++++++
Aimage/remote/components.conf | 24++++++++++++++++++++++++
Aimage/remote/moz.build | 19+++++++++++++++++++
5 files changed, 117 insertions(+), 1 deletion(-)

diff --git a/image/moz.build b/image/moz.build @@ -4,7 +4,7 @@ # 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/. -DIRS += ["build", "decoders", "encoders"] +DIRS += ["build", "decoders", "encoders", "remote"] TEST_DIRS += ["test/gtest"] if CONFIG["FUZZING_INTERFACES"]: diff --git a/image/remote/RemoteImageProtocolHandler.cpp b/image/remote/RemoteImageProtocolHandler.cpp @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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 "RemoteImageProtocolHandler.h" + +namespace mozilla::image { + +StaticRefPtr<RemoteImageProtocolHandler> RemoteImageProtocolHandler::sSingleton; + +NS_IMPL_ISUPPORTS(RemoteImageProtocolHandler, nsIProtocolHandler, + nsISupportsWeakReference); + +NS_IMETHODIMP RemoteImageProtocolHandler::GetScheme(nsACString& aScheme) { + aScheme.AssignLiteral("moz-remote-image"); + return NS_OK; +} + +NS_IMETHODIMP RemoteImageProtocolHandler::AllowPort(int32_t, const char*, + bool* aAllow) { + *aAllow = false; + return NS_OK; +} + +NS_IMETHODIMP RemoteImageProtocolHandler::NewChannel(nsIURI* aURI, + nsILoadInfo* aLoadInfo, + nsIChannel** aOutChannel) { + return NS_ERROR_NOT_IMPLEMENTED; +} + +} // namespace mozilla::image diff --git a/image/remote/RemoteImageProtocolHandler.h b/image/remote/RemoteImageProtocolHandler.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#ifndef mozilla_image_remote_RemoteImageProtocolHandler_h +#define mozilla_image_remote_RemoteImageProtocolHandler_h + +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/ClearOnShutdown.h" +#include "mozilla/StaticPtr.h" +#include "nsIProtocolHandler.h" +#include "nsThreadUtils.h" +#include "nsWeakReference.h" + +namespace mozilla::image { + +class RemoteImageProtocolHandler : public nsIProtocolHandler, + public nsSupportsWeakReference { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIPROTOCOLHANDLER + + static already_AddRefed<RemoteImageProtocolHandler> GetSingleton() { + MOZ_ASSERT(NS_IsMainThread()); + if (MOZ_UNLIKELY(!sSingleton)) { + sSingleton = new RemoteImageProtocolHandler(); + ClearOnShutdown(&sSingleton); + } + return do_AddRef(sSingleton); + } + + private: + virtual ~RemoteImageProtocolHandler() = default; + + static StaticRefPtr<RemoteImageProtocolHandler> sSingleton; +}; + +} // namespace mozilla::image + +#endif // mozilla_image_remote_RemoteImageProtocolHandler_h diff --git a/image/remote/components.conf b/image/remote/components.conf @@ -0,0 +1,24 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +Classes = [ + { + 'cid': '{4c733bd7-0bea-435a-ae1e-e65f3269d519}', + 'contract_ids': ['@mozilla.org/network/protocol;1?name=moz-remote-image'], + 'singleton': True, + 'type': 'mozilla::image::RemoteImageProtocolHandler', + 'headers': ['mozilla/image/RemoteImageProtocolHandler.h'], + 'constructor': 'mozilla::image::RemoteImageProtocolHandler::GetSingleton', + 'protocol_config': { + 'scheme': 'moz-remote-image', + 'flags': [ + 'URI_NORELATIVE', + 'URI_NOAUTH', + 'URI_DANGEROUS_TO_LOAD', + ], + }, + }, +] diff --git a/image/remote/moz.build b/image/remote/moz.build @@ -0,0 +1,19 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +XPCOM_MANIFESTS += [ + "components.conf", +] + +EXPORTS.mozilla.image += [ + "RemoteImageProtocolHandler.h", +] + +UNIFIED_SOURCES += [ + "RemoteImageProtocolHandler.cpp", +] + +FINAL_LIBRARY = "xul"