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/. */
6 var EXPORTED_SYMBOLS = ["GeckoViewContentParent"];
8 const { GeckoViewUtils } = ChromeUtils.import(
9 "resource://gre/modules/GeckoViewUtils.jsm"
12 const { GeckoViewActorParent } = ChromeUtils.import(
13 "resource://gre/modules/GeckoViewActorParent.jsm"
16 const { debug, warn } = GeckoViewUtils.initLogging("GeckoViewContentParent");
18 class GeckoViewContentParent extends GeckoViewActorParent {
19 async collectState() {
20 return this.sendQuery("CollectSessionState");
23 restoreState({ history, switchId, formdata, scrolldata }) {
24 // Restoring is made of two parts. First we need to restore the history
25 // of the tab and navigating to the current page, after the page
26 // navigates to the current page we need to restore the state of the
27 // page (scroll position, form data, etc).
29 // We can't do everything in one step inside the child actor because
30 // the actor is recreated when navigating, so we need to keep the state
31 // on the parent side until we navigate.
32 this.sendAsyncMessage("RestoreHistoryAndNavigate", {
37 if (!formdata && !scrolldata) {
41 const progressFilter = Cc[
42 "@mozilla.org/appshell/component/browser-status-filter;1"
43 ].createInstance(Ci.nsIWebProgress);
45 const { browser } = this;
46 const progressListener = {
47 QueryInterface: ChromeUtils.generateQI(["nsIWebProgressListener"]),
49 onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) {
50 if (!aWebProgress.isTopLevel) {
53 // The actor might get recreated between navigations so we need to
54 // query it again for the up-to-date instance.
55 browser.browsingContext.currentWindowGlobal
56 .getActor("GeckoViewContent")
57 .sendAsyncMessage("RestoreSessionState", { formdata, scrolldata });
58 progressFilter.removeProgressListener(this);
59 browser.removeProgressListener(progressFilter);
63 const flags = Ci.nsIWebProgress.NOTIFY_LOCATION;
64 progressFilter.addProgressListener(progressListener, flags);
65 browser.addProgressListener(progressFilter, flags);