summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/PageIconProtocolHandler.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/places/PageIconProtocolHandler.h
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/places/PageIconProtocolHandler.h')
-rw-r--r--toolkit/components/places/PageIconProtocolHandler.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/toolkit/components/places/PageIconProtocolHandler.h b/toolkit/components/places/PageIconProtocolHandler.h
new file mode 100644
index 0000000000..7cfeeae99b
--- /dev/null
+++ b/toolkit/components/places/PageIconProtocolHandler.h
@@ -0,0 +1,94 @@
+/* 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_places_PageIconProtocolHandler_h
+#define mozilla_places_PageIconProtocolHandler_h
+
+#include "mozilla/AlreadyAddRefed.h"
+#include "mozilla/ClearOnShutdown.h"
+#include "mozilla/MozPromise.h"
+#include "mozilla/StaticPtr.h"
+#include "mozilla/net/RemoteStreamGetter.h"
+#include "nsIProtocolHandler.h"
+#include "nsThreadUtils.h"
+#include "nsWeakReference.h"
+
+namespace mozilla::places {
+
+struct FaviconMetadata;
+using FaviconMetadataPromise =
+ mozilla::MozPromise<FaviconMetadata, nsresult, false>;
+
+using net::RemoteStreamPromise;
+
+class PageIconProtocolHandler final : public nsIProtocolHandler,
+ public nsSupportsWeakReference {
+ public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIPROTOCOLHANDLER
+
+ static already_AddRefed<PageIconProtocolHandler> GetSingleton() {
+ MOZ_ASSERT(NS_IsMainThread());
+ if (MOZ_UNLIKELY(!sSingleton)) {
+ sSingleton = new PageIconProtocolHandler();
+ ClearOnShutdown(&sSingleton);
+ }
+ return do_AddRef(sSingleton);
+ }
+
+ /**
+ * To be called in the parent process to obtain an input stream for the
+ * given icon.
+ *
+ * @param aChildURI a page-icon URI sent from the child.
+ * @param aLoadInfo the nsILoadInfo for the load attempt from the child.
+ * @param aTerminateSender out param set to true when the params are invalid
+ * and indicate the child should be terminated. If |aChildURI| is
+ * not a page-icon URI, the child is in an invalid state and
+ * should be terminated. This outparam will be set synchronously.
+ *
+ * @return RemoteStreamPromise
+ * The RemoteStreamPromise will resolve with an RemoteStreamInfo on
+ * success, and reject with an nsresult on failure.
+ */
+ RefPtr<RemoteStreamPromise> NewStream(nsIURI* aChildURI,
+ nsILoadInfo* aLoadInfo,
+ bool* aTerminateSender);
+
+ private:
+ ~PageIconProtocolHandler() = default;
+
+ /**
+ * This replaces the provided channel with a channel that will proxy the load
+ * to the parent process.
+ *
+ * @param aURI the page-icon: URI.
+ * @param aLoadInfo the loadinfo for the request.
+ * @param aRetVal in/out channel param referring to the channel that
+ * might need to be substituted with a remote channel.
+ * @return NS_OK if the replacement channel was created successfully.
+ * Otherwise, returns an error.
+ */
+ Result<Ok, nsresult> SubstituteRemoteChannel(nsIURI* aURI,
+ nsILoadInfo* aLoadInfo,
+ nsIChannel** aRetVal);
+
+ RefPtr<FaviconMetadataPromise> GetFaviconData(nsIURI* aPageIconURI,
+ nsILoadInfo* aLoadInfo);
+
+ nsresult NewChannelInternal(nsIURI*, nsILoadInfo*, nsIChannel**);
+
+ void GetStreams(nsIAsyncInputStream** inStream,
+ nsIAsyncOutputStream** outStream);
+
+ // Gets a SimpleChannel that wraps the provided channel.
+ static void NewSimpleChannel(nsIURI* aURI, nsILoadInfo* aLoadinfo,
+ mozilla::net::RemoteStreamGetter* aStreamGetter,
+ nsIChannel** aRetVal);
+ static StaticRefPtr<PageIconProtocolHandler> sSingleton;
+};
+
+} // namespace mozilla::places
+
+#endif