summaryrefslogtreecommitdiffstats
path: root/mobile/android/components/geckoview/GeckoViewExternalAppService.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /mobile/android/components/geckoview/GeckoViewExternalAppService.cpp
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/components/geckoview/GeckoViewExternalAppService.cpp')
-rw-r--r--mobile/android/components/geckoview/GeckoViewExternalAppService.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/mobile/android/components/geckoview/GeckoViewExternalAppService.cpp b/mobile/android/components/geckoview/GeckoViewExternalAppService.cpp
new file mode 100644
index 0000000000..30dedc9251
--- /dev/null
+++ b/mobile/android/components/geckoview/GeckoViewExternalAppService.cpp
@@ -0,0 +1,100 @@
+/* -*- 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 "GeckoViewExternalAppService.h"
+
+#include "mozilla/dom/BrowsingContext.h"
+#include "mozilla/dom/CanonicalBrowsingContext.h"
+#include "mozilla/dom/WindowGlobalParent.h"
+#include "nsIChannel.h"
+
+#include "mozilla/widget/EventDispatcher.h"
+#include "mozilla/widget/nsWindow.h"
+#include "GeckoViewStreamListener.h"
+
+#include "JavaBuiltins.h"
+
+class StreamListener final : public mozilla::GeckoViewStreamListener {
+ public:
+ explicit StreamListener(nsWindow* aWindow)
+ : GeckoViewStreamListener(), mWindow(aWindow) {}
+
+ void SendWebResponse(mozilla::java::WebResponse::Param aResponse) {
+ mWindow->PassExternalResponse(aResponse);
+ }
+
+ void CompleteWithError(nsresult aStatus, nsIChannel* aChannel) {
+ // Currently we don't do anything about errors here
+ }
+
+ virtual ~StreamListener() {}
+
+ private:
+ RefPtr<nsWindow> mWindow;
+};
+
+mozilla::StaticRefPtr<GeckoViewExternalAppService>
+ GeckoViewExternalAppService::sService;
+
+/* static */
+already_AddRefed<GeckoViewExternalAppService>
+GeckoViewExternalAppService::GetSingleton() {
+ if (!sService) {
+ sService = new GeckoViewExternalAppService();
+ }
+ RefPtr<GeckoViewExternalAppService> service = sService;
+ return service.forget();
+}
+
+GeckoViewExternalAppService::GeckoViewExternalAppService() {}
+
+NS_IMPL_ISUPPORTS(GeckoViewExternalAppService, nsIExternalHelperAppService);
+
+NS_IMETHODIMP GeckoViewExternalAppService::DoContent(
+ const nsACString& aMimeContentType, nsIRequest* aRequest,
+ nsIInterfaceRequestor* aContentContext, bool aForceSave,
+ nsIInterfaceRequestor* aWindowContext,
+ nsIStreamListener** aStreamListener) {
+ return NS_ERROR_FAILURE;
+}
+
+NS_IMETHODIMP GeckoViewExternalAppService::CreateListener(
+ const nsACString& aMimeContentType, nsIRequest* aRequest,
+ mozilla::dom::BrowsingContext* aContentContext, bool aForceSave,
+ nsIInterfaceRequestor* aWindowContext,
+ nsIStreamListener** aStreamListener) {
+ using namespace mozilla;
+ using namespace mozilla::dom;
+ MOZ_ASSERT(XRE_IsParentProcess());
+
+ nsresult rv;
+ nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest, &rv));
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ nsCOMPtr<nsIWidget> widget =
+ aContentContext->Canonical()->GetParentProcessWidgetContaining();
+ if (!widget) {
+ return NS_ERROR_ABORT;
+ }
+
+ RefPtr<nsWindow> window = nsWindow::From(widget);
+ MOZ_ASSERT(window);
+
+ RefPtr<StreamListener> listener = new StreamListener(window);
+
+ rv = channel->SetNotificationCallbacks(listener);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ listener.forget(aStreamListener);
+ return NS_OK;
+}
+
+NS_IMETHODIMP GeckoViewExternalAppService::ApplyDecodingForExtension(
+ const nsACString& aExtension, const nsACString& aEncodingType,
+ bool* aApplyDecoding) {
+ // This currently doesn't matter, because we never read the stream.
+ *aApplyDecoding = true;
+ return NS_OK;
+}