1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { GeckoViewUtils } from "resource://gre/modules/GeckoViewUtils.sys.mjs";
6 import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
10 ChromeUtils.defineESModuleGetters(lazy, {
11 SessionHistory: "resource://gre/modules/sessionstore/SessionHistory.sys.mjs",
14 const { debug, warn } = GeckoViewUtils.initLogging("GeckoViewContentParent");
16 export class GeckoViewContentParent extends GeckoViewActorParent {
17 async collectState() {
18 return this.sendQuery("CollectSessionState");
21 async containsFormData() {
22 return this.sendQuery("ContainsFormData");
25 restoreState({ history, switchId, formdata, scrolldata }) {
26 if (Services.appinfo.sessionHistoryInParent) {
27 const { browsingContext } = this.browser;
28 lazy.SessionHistory.restoreFromParent(
29 browsingContext.sessionHistory,
33 // TODO Bug 1648158 this should include scroll, form history, etc
34 return SessionStoreUtils.initializeRestore(
36 SessionStoreUtils.constructSessionStoreRestoreData()
40 // Restoring is made of two parts. First we need to restore the history
41 // of the tab and navigating to the current page, after the page
42 // navigates to the current page we need to restore the state of the
43 // page (scroll position, form data, etc).
45 // We can't do everything in one step inside the child actor because
46 // the actor is recreated when navigating, so we need to keep the state
47 // on the parent side until we navigate.
48 this.sendAsyncMessage("RestoreHistoryAndNavigate", {
53 if (!formdata && !scrolldata) {
57 const progressFilter = Cc[
58 "@mozilla.org/appshell/component/browser-status-filter;1"
59 ].createInstance(Ci.nsIWebProgress);
61 const { browser } = this;
62 const progressListener = {
63 QueryInterface: ChromeUtils.generateQI(["nsIWebProgressListener"]),
65 onLocationChange(aWebProgress) {
66 if (!aWebProgress.isTopLevel) {
69 // The actor might get recreated between navigations so we need to
70 // query it again for the up-to-date instance.
71 browser.browsingContext.currentWindowGlobal
72 .getActor("GeckoViewContent")
73 .sendAsyncMessage("RestoreSessionState", { formdata, scrolldata });
74 progressFilter.removeProgressListener(this);
75 browser.removeProgressListener(progressFilter);
79 const flags = Ci.nsIWebProgress.NOTIFY_LOCATION;
80 progressFilter.addProgressListener(progressListener, flags);
81 browser.addProgressListener(progressFilter, flags);