summaryrefslogtreecommitdiffstats
path: root/mobile/android/modules/geckoview/LoadURIDelegate.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /mobile/android/modules/geckoview/LoadURIDelegate.jsm
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/modules/geckoview/LoadURIDelegate.jsm')
-rw-r--r--mobile/android/modules/geckoview/LoadURIDelegate.jsm109
1 files changed, 109 insertions, 0 deletions
diff --git a/mobile/android/modules/geckoview/LoadURIDelegate.jsm b/mobile/android/modules/geckoview/LoadURIDelegate.jsm
new file mode 100644
index 0000000000..cfbe03846d
--- /dev/null
+++ b/mobile/android/modules/geckoview/LoadURIDelegate.jsm
@@ -0,0 +1,109 @@
+// -*- indent-tabs-mode: nil; js-indent-level: 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/. */
+"use strict";
+
+var EXPORTED_SYMBOLS = ["LoadURIDelegate"];
+
+const { XPCOMUtils } = ChromeUtils.import(
+ "resource://gre/modules/XPCOMUtils.jsm"
+);
+const { GeckoViewUtils } = ChromeUtils.import(
+ "resource://gre/modules/GeckoViewUtils.jsm"
+);
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+ Services: "resource://gre/modules/Services.jsm",
+});
+
+const { debug, warn } = GeckoViewUtils.initLogging("LoadURIDelegate");
+
+const LoadURIDelegate = {
+ // Delegate URI loading to the app.
+ // Return whether the loading has been handled.
+ load(aWindow, aEventDispatcher, aUri, aWhere, aFlags, aTriggeringPrincipal) {
+ if (!aWindow) {
+ return false;
+ }
+
+ const triggerUri =
+ aTriggeringPrincipal &&
+ (aTriggeringPrincipal.isNullPrincipal ? null : aTriggeringPrincipal.URI);
+
+ const message = {
+ type: "GeckoView:OnLoadRequest",
+ uri: aUri ? aUri.displaySpec : "",
+ where: aWhere,
+ flags: aFlags,
+ triggerUri: triggerUri && triggerUri.displaySpec,
+ hasUserGesture: aWindow.document.hasValidTransientUserGestureActivation,
+ };
+
+ let handled = undefined;
+ aEventDispatcher.sendRequestForResult(message).then(
+ response => {
+ handled = response;
+ },
+ () => {
+ // There was an error or listener was not registered in GeckoSession,
+ // treat as unhandled.
+ handled = false;
+ }
+ );
+ Services.tm.spinEventLoopUntil(
+ () => aWindow.closed || handled !== undefined
+ );
+
+ return handled || false;
+ },
+
+ handleLoadError(aWindow, aEventDispatcher, aUri, aError, aErrorModule) {
+ let errorClass = 0;
+ try {
+ const nssErrorsService = Cc[
+ "@mozilla.org/nss_errors_service;1"
+ ].getService(Ci.nsINSSErrorsService);
+ errorClass = nssErrorsService.getErrorClass(aError);
+ } catch (e) {}
+
+ const msg = {
+ type: "GeckoView:OnLoadError",
+ uri: aUri && aUri.spec,
+ error: aError,
+ errorModule: aErrorModule,
+ errorClass,
+ };
+
+ let errorPageURI = undefined;
+ aEventDispatcher.sendRequestForResult(msg).then(
+ response => {
+ try {
+ errorPageURI = response ? Services.io.newURI(response) : null;
+ } catch (e) {
+ warn`Failed to parse URI '${response}`;
+ errorPageURI = null;
+ Components.returnCode = Cr.NS_ERROR_ABORT;
+ }
+ },
+ e => {
+ errorPageURI = null;
+ Components.returnCode = Cr.NS_ERROR_ABORT;
+ }
+ );
+ Services.tm.spinEventLoopUntil(
+ () => aWindow.closed || errorPageURI !== undefined
+ );
+
+ return errorPageURI;
+ },
+
+ isSafeBrowsingError(aError) {
+ return (
+ aError === Cr.NS_ERROR_PHISHING_URI ||
+ aError === Cr.NS_ERROR_MALWARE_URI ||
+ aError === Cr.NS_ERROR_HARMFUL_URI ||
+ aError === Cr.NS_ERROR_UNWANTED_URI
+ );
+ },
+};