summaryrefslogtreecommitdiffstats
path: root/mobile/android/actors/GeckoViewContentParent.sys.mjs
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/actors/GeckoViewContentParent.sys.mjs
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/actors/GeckoViewContentParent.sys.mjs')
-rw-r--r--mobile/android/actors/GeckoViewContentParent.sys.mjs84
1 files changed, 84 insertions, 0 deletions
diff --git a/mobile/android/actors/GeckoViewContentParent.sys.mjs b/mobile/android/actors/GeckoViewContentParent.sys.mjs
new file mode 100644
index 0000000000..354489054a
--- /dev/null
+++ b/mobile/android/actors/GeckoViewContentParent.sys.mjs
@@ -0,0 +1,84 @@
+/* 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/. */
+
+import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
+import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ SessionHistory: "resource://gre/modules/sessionstore/SessionHistory.sys.mjs",
+});
+
+const { debug, warn } = GeckoViewUtils.initLogging("GeckoViewContentParent");
+
+export class GeckoViewContentParent extends GeckoViewActorParent {
+ async collectState() {
+ return this.sendQuery("CollectSessionState");
+ }
+
+ async containsFormData() {
+ return this.sendQuery("ContainsFormData");
+ }
+
+ restoreState({ history, switchId, formdata, scrolldata }) {
+ if (Services.appinfo.sessionHistoryInParent) {
+ const { browsingContext } = this.browser;
+ lazy.SessionHistory.restoreFromParent(
+ browsingContext.sessionHistory,
+ history
+ );
+
+ // TODO Bug 1648158 this should include scroll, form history, etc
+ return SessionStoreUtils.initializeRestore(
+ browsingContext,
+ SessionStoreUtils.constructSessionStoreRestoreData()
+ );
+ }
+
+ // Restoring is made of two parts. First we need to restore the history
+ // of the tab and navigating to the current page, after the page
+ // navigates to the current page we need to restore the state of the
+ // page (scroll position, form data, etc).
+ //
+ // We can't do everything in one step inside the child actor because
+ // the actor is recreated when navigating, so we need to keep the state
+ // on the parent side until we navigate.
+ this.sendAsyncMessage("RestoreHistoryAndNavigate", {
+ history,
+ switchId,
+ });
+
+ if (!formdata && !scrolldata) {
+ return null;
+ }
+
+ const progressFilter = Cc[
+ "@mozilla.org/appshell/component/browser-status-filter;1"
+ ].createInstance(Ci.nsIWebProgress);
+
+ const { browser } = this;
+ const progressListener = {
+ QueryInterface: ChromeUtils.generateQI(["nsIWebProgressListener"]),
+
+ onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) {
+ if (!aWebProgress.isTopLevel) {
+ return;
+ }
+ // The actor might get recreated between navigations so we need to
+ // query it again for the up-to-date instance.
+ browser.browsingContext.currentWindowGlobal
+ .getActor("GeckoViewContent")
+ .sendAsyncMessage("RestoreSessionState", { formdata, scrolldata });
+ progressFilter.removeProgressListener(this);
+ browser.removeProgressListener(progressFilter);
+ },
+ };
+
+ const flags = Ci.nsIWebProgress.NOTIFY_LOCATION;
+ progressFilter.addProgressListener(progressListener, flags);
+ browser.addProgressListener(progressFilter, flags);
+ return null;
+ }
+}