Backed out 2 changesets (bug 1463878) for ESlint and checkstyle failure on a CLOSED TREE
authorCoroiu Cristina <ccoroiu@mozilla.com>
Fri, 22 Mar 2019 00:18:04 +0200
changeset 465499 0da1eacffbea5669c6acf2531650da4fd89bdcdd
parent 465498 11ef93d1b795e14bdd1206d97786e9e967e1a7d8
child 465500 368e04fcad499ec8ea1d625269e20fe590e25f0e
push id35741
push userapavel@mozilla.com
push dateFri, 22 Mar 2019 09:56:25 +0000
treeherdermozilla-central@6332e136b825 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1463878
milestone68.0a1
backs out2cc833baea24171ad0d196894eda77cacb8c8981
11415a3e72f68f06b935bc5962e486947baec71a
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out 2 changesets (bug 1463878) for ESlint and checkstyle failure on a CLOSED TREE Backed out changeset 2cc833baea24 (bug 1463878) Backed out changeset 11415a3e72f6 (bug 1463878)
mobile/android/chrome/geckoview/GeckoViewContentChild.js
mobile/android/chrome/geckoview/GeckoViewProgressChild.js
mobile/android/chrome/geckoview/SessionStateAggregator.js
mobile/android/chrome/geckoview/geckoview.js
mobile/android/chrome/geckoview/jar.mn
mobile/android/geckoview/api.txt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md
mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
mobile/android/modules/geckoview/GeckoViewContent.jsm
--- a/mobile/android/chrome/geckoview/GeckoViewContentChild.js
+++ b/mobile/android/chrome/geckoview/GeckoViewContentChild.js
@@ -36,16 +36,17 @@ class GeckoViewContentChild extends Geck
       Utils: "resource://gre/modules/sessionstore/Utils.jsm",
     });
 
     this.messageManager.addMessageListener("GeckoView:DOMFullscreenEntered",
                                            this);
     this.messageManager.addMessageListener("GeckoView:DOMFullscreenExited",
                                            this);
     this.messageManager.addMessageListener("GeckoView:RestoreState", this);
+    this.messageManager.addMessageListener("GeckoView:SaveState", this);
     this.messageManager.addMessageListener("GeckoView:SetActive", this);
     this.messageManager.addMessageListener("GeckoView:UpdateInitData", this);
     this.messageManager.addMessageListener("GeckoView:ZoomToInput", this);
     this.messageManager.addMessageListener("GeckoView:ScrollBy", this);
     this.messageManager.addMessageListener("GeckoView:ScrollTo", this);
 
     const options = {
         mozSystemGroup: true,
@@ -203,18 +204,38 @@ class GeckoViewContentChild extends Geck
           removeEventListener("resize", onResize, { capture: true });
           if (!gotResize) {
             onResize();
           }
         }, 500);
         break;
       }
 
+      case "GeckoView:SaveState":
+        if (this._savedState) {
+          // Short circuit and return the pending state if we're in the process of restoring
+          sendAsyncMessage("GeckoView:SaveStateFinish", {state: JSON.stringify(this._savedState), id: aMsg.data.id});
+        } else {
+          try {
+            let state = this.collectSessionState();
+            sendAsyncMessage("GeckoView:SaveStateFinish", {
+              state: state ? JSON.stringify(state) : null,
+              id: aMsg.data.id,
+            });
+          } catch (e) {
+            sendAsyncMessage("GeckoView:SaveStateFinish", {
+              error: e.message,
+              id: aMsg.data.id,
+            });
+          }
+        }
+        break;
+
       case "GeckoView:RestoreState":
-        this._savedState = aMsg.data;
+        this._savedState = JSON.parse(aMsg.data.state);
 
         if (this._savedState.history) {
           let restoredHistory = SessionHistory.restore(docShell, this._savedState.history);
 
           addEventListener("load", _ => {
             const formdata = this._savedState.formdata;
             if (formdata) {
               this.Utils.restoreFrameTreeData(content, formdata, (frame, data) => {
--- a/mobile/android/chrome/geckoview/GeckoViewProgressChild.js
+++ b/mobile/android/chrome/geckoview/GeckoViewProgressChild.js
@@ -253,10 +253,11 @@ const ProgressTracker = {
     data.prev = progress;
 
     if (progress >= 100) {
       PAGE_LOAD_PROGRESS_PROBE.finish();
     }
   },
 };
 
+
 const {debug, warn} = GeckoViewProgressChild.initLogging("GeckoViewProgress"); // eslint-disable-line no-unused-vars
 const module = GeckoViewProgressChild.create(this);
deleted file mode 100644
--- a/mobile/android/chrome/geckoview/SessionStateAggregator.js
+++ /dev/null
@@ -1,595 +0,0 @@
-/* -*- 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";
-
-const {GeckoViewChildModule} = ChromeUtils.import("resource://gre/modules/GeckoViewChildModule.jsm");
-ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);
-ChromeUtils.import("resource://gre/modules/Timer.jsm", this);
-const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm", this);
-
-ChromeUtils.defineModuleGetter(this, "SessionHistory",
-  "resource://gre/modules/sessionstore/SessionHistory.jsm");
-
-const NO_INDEX = Number.MAX_SAFE_INTEGER;
-const LAST_INDEX = Number.MAX_SAFE_INTEGER - 1;
-const DEFAULT_INTERVAL_MS = 1500;
-
-// This pref controls whether or not we send updates to the parent on a timeout
-// or not, and should only be used for tests or debugging.
-const TIMEOUT_DISABLED_PREF = "browser.sessionstore.debug.no_auto_updates";
-
-const PREF_INTERVAL = "browser.sessionstore.interval";
-
-class Handler {
-  constructor(store) {
-    this.store = store;
-  }
-
-  get mm() {
-    return this.store.mm;
-  }
-
-  get eventDispatcher() {
-    return this.store.eventDispatcher;
-  }
-
-  get messageQueue() {
-    return this.store.messageQueue;
-  }
-
-  get stateChangeNotifier() {
-    return this.store.stateChangeNotifier;
-  }
-}
-
-/**
- * Listens for state change notifcations from webProgress and notifies each
- * registered observer for either the start of a page load, or its completion.
- */
-class StateChangeNotifier extends Handler {
-  constructor(store) {
-    super(store);
-
-    this._observers = new Set();
-    const ifreq = this.mm.docShell.QueryInterface(Ci.nsIInterfaceRequestor);
-    const webProgress = ifreq.getInterface(Ci.nsIWebProgress);
-    webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
-  }
-
-  /**
-   * Adds a given observer |obs| to the set of observers that will be notified
-   * when when a new document starts or finishes loading.
-   *
-   * @param obs (object)
-   */
-  addObserver(obs) {
-    this._observers.add(obs);
-  }
-
-  /**
-   * Notifies all observers that implement the given |method|.
-   *
-   * @param method (string)
-   */
-  notifyObservers(method) {
-    for (let obs of this._observers) {
-      if (typeof obs[method] == "function") {
-        obs[method]();
-      }
-    }
-  }
-
-  /**
-   * @see nsIWebProgressListener.onStateChange
-   */
-  onStateChange(webProgress, request, stateFlags, status) {
-    // Ignore state changes for subframes because we're only interested in the
-    // top-document starting or stopping its load.
-    if (!webProgress.isTopLevel || webProgress.DOMWindow != this.mm.content) {
-      return;
-    }
-
-    // onStateChange will be fired when loading the initial about:blank URI for
-    // a browser, which we don't actually care about. This is particularly for
-    // the case of unrestored background tabs, where the content has not yet
-    // been restored: we don't want to accidentally send any updates to the
-    // parent when the about:blank placeholder page has loaded.
-    if (!this.mm.docShell.hasLoadedNonBlankURI) {
-      return;
-    }
-
-    if (stateFlags & Ci.nsIWebProgressListener.STATE_START) {
-      this.notifyObservers("onPageLoadStarted");
-    } else if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
-      this.notifyObservers("onPageLoadCompleted");
-    }
-  }
-}
-StateChangeNotifier.prototype.QueryInterface =
-  ChromeUtils.generateQI([Ci.nsIWebProgressListener,
-                          Ci.nsISupportsWeakReference]);
-
-/**
- * Listens for changes to the session history. Whenever the user navigates
- * we will collect URLs and everything belonging to session history.
- *
- * Causes a SessionStore:update message to be sent that contains the current
- * session history.
- *
- * Example:
- *   {entries: [{url: "about:mozilla", ...}, ...], index: 1}
- */
-class SessionHistoryListener extends Handler {
-  constructor(store) {
-    super(store);
-
-    this._fromIdx = NO_INDEX;
-
-
-    // The state change observer is needed to handle initial subframe loads.
-    // It will redundantly invalidate with the SHistoryListener in some cases
-    // but these invalidations are very cheap.
-    this.stateChangeNotifier.addObserver(this);
-
-    // By adding the SHistoryListener immediately, we will unfortunately be
-    // notified of every history entry as the tab is restored. We don't bother
-    // waiting to add the listener later because these notifications are cheap.
-    // We will likely only collect once since we are batching collection on
-    // a delay.
-    this.mm.docShell.QueryInterface(Ci.nsIWebNavigation)
-      .sessionHistory.legacySHistory.addSHistoryListener(this);
-
-    // Listen for page title changes.
-    this.mm.addEventListener("DOMTitleChanged", this);
-  }
-
-  uninit() {
-    const sessionHistory = this.mm.docShell.QueryInterface(Ci.nsIWebNavigation).sessionHistory;
-    if (sessionHistory) {
-      sessionHistory.legacySHistory.removeSHistoryListener(this);
-    }
-  }
-
-  collect() {
-    // We want to send down a historychange even for full collects in case our
-    // session history is a partial session history, in which case we don't have
-    // enough information for a full update. collectFrom(-1) tells the collect
-    // function to collect all data avaliable in this process.
-    if (this.mm.docShell) {
-      this.collectFrom(-1);
-    }
-  }
-
-  // History can grow relatively big with the nested elements, so if we don't have to, we
-  // don't want to send the entire history all the time. For a simple optimization
-  // we keep track of the smallest index from after any change has occured and we just send
-  // the elements from that index. If something more complicated happens we just clear it
-  // and send the entire history. We always send the additional info like the current selected
-  // index (so for going back and forth between history entries we set the index to LAST_INDEX
-  // if nothing else changed send an empty array and the additonal info like the selected index)
-  collectFrom(idx) {
-    if (this._fromIdx <= idx) {
-      // If we already know that we need to update history fromn index N we can ignore any changes
-      // tha happened with an element with index larger than N.
-      // Note: initially we use NO_INDEX which is MAX_SAFE_INTEGER which means we don't ignore anything
-      // here, and in case of navigation in the history back and forth we use LAST_INDEX which ignores
-      // only the subsequent navigations, but not any new elements added.
-      return;
-    }
-
-    this._fromIdx = idx;
-    this.messageQueue.push("historychange", () => {
-      if (this._fromIdx === NO_INDEX) {
-        return null;
-      }
-
-      let history = SessionHistory.collect(this.mm.docShell, this._fromIdx);
-      this._fromIdx = NO_INDEX;
-      return history;
-    });
-  }
-
-  handleEvent(event) {
-    this.collect();
-  }
-
-  onPageLoadCompleted() {
-    this.collect();
-  }
-
-  onPageLoadStarted() {
-    this.collect();
-  }
-
-  OnHistoryNewEntry(newURI, oldIndex) {
-    // We ought to collect the previously current entry as well, see bug 1350567.
-    // TODO: Reenable partial history collection for performance
-    // this.collectFrom(oldIndex);
-    this.collect();
-  }
-
-  OnHistoryGotoIndex(index, gotoURI) {
-    // We ought to collect the previously current entry as well, see bug 1350567.
-    // TODO: Reenable partial history collection for performance
-    // this.collectFrom(LAST_INDEX);
-    this.collect();
-  }
-
-  OnHistoryPurge(numEntries) {
-    this.collect();
-  }
-
-  OnHistoryReload(reloadURI, reloadFlags) {
-    this.collect();
-    return true;
-  }
-
-  OnHistoryReplaceEntry(index) {
-    this.collect();
-  }
-}
-SessionHistoryListener.prototype.QueryInterface =
-  ChromeUtils.generateQI([Ci.nsISHistoryListener,
-                          Ci.nsISupportsWeakReference]);
-
-/**
- * Listens for scroll position changes. Whenever the user scrolls the top-most
- * frame we update the scroll position and will restore it when requested.
- *
- * Causes a SessionStore:update message to be sent that contains the current
- * scroll positions as a tree of strings. If no frame of the whole frame tree
- * is scrolled this will return null so that we don't tack a property onto
- * the tabData object in the parent process.
- *
- * Example:
- *   {scroll: "100,100", zoom: {resolution: "1.5", displaySize:
- *   {height: "1600", width: "1000"}}, children:
- *   [null, null, {scroll: "200,200"}]}
- */
-class ScrollPositionListener extends Handler {
-  constructor(store) {
-    super(store);
-
-    SessionStoreUtils.addDynamicFrameFilteredListener(
-      this.mm, "mozvisualscroll", this,
-      /* capture */ false, /* system group */ true);
-
-    SessionStoreUtils.addDynamicFrameFilteredListener(
-      this.mm, "mozvisualresize", this,
-      /* capture */ false, /* system group */ true);
-
-    this.stateChangeNotifier.addObserver(this);
-  }
-
-  handleEvent() {
-    this.messageQueue.push("scroll", () => this.collect());
-  }
-
-  onPageLoadCompleted() {
-    this.messageQueue.push("scroll", () => this.collect());
-  }
-
-  onPageLoadStarted() {
-    this.messageQueue.push("scroll", () => null);
-  }
-
-  collect() {
-    // TODO: Keep an eye on bug 1525259; we may not have to manually store zoom
-    // Save the current document resolution.
-    let zoom = 1;
-    const scrolldata = SessionStoreUtils.collectScrollPosition(this.mm.content) || {};
-    const domWindowUtils = this.mm.content.windowUtils;
-    zoom = domWindowUtils.getResolution();
-    scrolldata.zoom = {};
-    scrolldata.zoom.resolution = zoom;
-
-    // Save some data that'll help in adjusting the zoom level
-    // when restoring in a different screen orientation.
-    const displaySize = {};
-    const width = {}, height = {};
-    domWindowUtils.getContentViewerSize(width, height);
-
-    displaySize.width = width.value;
-    displaySize.height = height.value;
-
-    scrolldata.zoom.displaySize = displaySize;
-
-    return scrolldata;
-  }
-}
-
-/**
- * Listens for changes to input elements. Whenever the value of an input
- * element changes we will re-collect data for the current frame tree and send
- * a message to the parent process.
- *
- * Causes a SessionStore:update message to be sent that contains the form data
- * for all reachable frames.
- *
- * Example:
- *   {
- *     formdata: {url: "http://mozilla.org/", id: {input_id: "input value"}},
- *     children: [
- *       null,
- *       {url: "http://sub.mozilla.org/", id: {input_id: "input value 2"}}
- *     ]
- *   }
- */
-class FormDataListener extends Handler {
-  constructor(store) {
-    super(store);
-
-    SessionStoreUtils.addDynamicFrameFilteredListener(this.mm, "input", this, true);
-    this.stateChangeNotifier.addObserver(this);
-  }
-
-  handleEvent() {
-    this.messageQueue.push("formdata", () => this.collect());
-  }
-
-  onPageLoadStarted() {
-    this.messageQueue.push("formdata", () => null);
-  }
-
-  collect() {
-    return SessionStoreUtils.collectFormData(this.mm.content);
-  }
-}
-
-/**
- * A message queue that takes collected data and will take care of sending it
- * to the chrome process. It allows flushing using synchronous messages and
- * takes care of any race conditions that might occur because of that. Changes
- * will be batched if they're pushed in quick succession to avoid a message
- * flood.
- */
-class MessageQueue extends Handler {
-  constructor(store) {
-    super(store);
-
-    /**
-     * A map (string -> lazy fn) holding lazy closures of all queued data
-     * collection routines. These functions will return data collected from the
-     * docShell.
-     */
-    this._data = new Map();
-
-    /**
-     * The delay (in ms) used to delay sending changes after data has been
-     * invalidated.
-     */
-    this.BATCH_DELAY_MS = 1000;
-
-    /**
-     * The minimum idle period (in ms) we need for sending data to chrome process.
-     */
-    this.NEEDED_IDLE_PERIOD_MS = 5;
-
-    /**
-     * Timeout for waiting an idle period to send data. We will set this from
-     * the pref "browser.sessionstore.interval".
-     */
-    this._timeoutWaitIdlePeriodMs = null;
-
-    /**
-     * The current timeout ID, null if there is no queue data. We use timeouts
-     * to damp a flood of data changes and send lots of changes as one batch.
-     */
-    this._timeout = null;
-
-    /**
-     * Whether or not sending batched messages on a timer is disabled. This should
-     * only be used for debugging or testing. If you need to access this value,
-     * you should probably use the timeoutDisabled getter.
-     */
-    this._timeoutDisabled = false;
-
-    /**
-     * True if there is already a send pending idle dispatch, set to prevent
-     * scheduling more than one. If false there may or may not be one scheduled.
-     */
-    this._idleScheduled = false;
-
-    this.timeoutDisabled =
-      Services.prefs.getBoolPref(TIMEOUT_DISABLED_PREF, false);
-    this._timeoutWaitIdlePeriodMs =
-      Services.prefs.getIntPref(PREF_INTERVAL, DEFAULT_INTERVAL_MS);
-
-    Services.prefs.addObserver(TIMEOUT_DISABLED_PREF, this);
-    Services.prefs.addObserver(PREF_INTERVAL, this);
-  }
-
-  /**
-   * True if batched messages are not being fired on a timer. This should only
-   * ever be true when debugging or during tests.
-   */
-  get timeoutDisabled() {
-    return this._timeoutDisabled;
-  }
-
-  /**
-   * Disables sending batched messages on a timer. Also cancels any pending
-   * timers.
-   */
-  set timeoutDisabled(val) {
-    this._timeoutDisabled = val;
-
-    if (val && this._timeout) {
-      clearTimeout(this._timeout);
-      this._timeout = null;
-    }
-
-    return val;
-  }
-
-  uninit() {
-    this.cleanupTimers();
-  }
-
-  /**
-   * Cleanup pending idle callback and timer.
-   */
-  cleanupTimers() {
-    this._idleScheduled = false;
-    if (this._timeout) {
-      clearTimeout(this._timeout);
-      this._timeout = null;
-    }
-  }
-
-  observe(subject, topic, data) {
-    if (topic == "nsPref:changed") {
-      switch (data) {
-        case TIMEOUT_DISABLED_PREF:
-          this.timeoutDisabled =
-            Services.prefs.getBoolPref(TIMEOUT_DISABLED_PREF, false);
-          break;
-        case PREF_INTERVAL:
-          this._timeoutWaitIdlePeriodMs =
-            Services.prefs.getIntPref(PREF_INTERVAL, DEFAULT_INTERVAL_MS);
-          break;
-        default:
-          debug("received unknown message '" + data + "'");
-          break;
-      }
-    }
-  }
-
-  /**
-   * Pushes a given |value| onto the queue. The given |key| represents the type
-   * of data that is stored and can override data that has been queued before
-   * but has not been sent to the parent process, yet.
-   *
-   * @param key (string)
-   *        A unique identifier specific to the type of data this is passed.
-   * @param fn (function)
-   *        A function that returns the value that will be sent to the parent
-   *        process.
-   */
-  push(key, fn) {
-    this._data.set(key, fn);
-
-    if (!this._timeout && !this._timeoutDisabled) {
-      // Wait a little before sending the message to batch multiple changes.
-      this._timeout = setTimeoutWithTarget(
-        () => this.sendWhenIdle(), this.BATCH_DELAY_MS, this.mm.tabEventTarget);
-    }
-  }
-
-  /**
-   * Sends queued data when the remaining idle time is enough or waiting too
-   * long; otherwise, request an idle time again. If the |deadline| is not
-   * given, this function is going to schedule the first request.
-   *
-   * @param deadline (object)
-   *        An IdleDeadline object passed by idleDispatch().
-   */
-  sendWhenIdle(deadline) {
-    if (!this.mm.content) {
-      // The frameloader is being torn down. Nothing more to do.
-      return;
-    }
-
-    if (deadline) {
-      if (deadline.didTimeout || deadline.timeRemaining() > this.NEEDED_IDLE_PERIOD_MS) {
-        this.send();
-        return;
-      }
-    } else if (this._idleScheduled) {
-      // Bail out if there's a pending run.
-      return;
-    }
-    ChromeUtils.idleDispatch((deadline_) => this.sendWhenIdle(deadline_),
-                             {timeout: this._timeoutWaitIdlePeriodMs});
-    this._idleScheduled = true;
-  }
-
-  /**
-   * Sends queued data to the chrome process.
-   *
-   * @param options (object)
-   *        {flushID: 123} to specify that this is a flush
-   *        {isFinal: true} to signal this is the final message sent on unload
-   */
-  send(options = {}) {
-    // Looks like we have been called off a timeout after the tab has been
-    // closed. The docShell is gone now and we can just return here as there
-    // is nothing to do.
-    if (!this.mm.docShell) {
-      return;
-    }
-
-    this.cleanupTimers();
-
-    const flushID = (options && options.flushID) || 0;
-
-    let data = {};
-    for (let [key, func] of this._data) {
-      let value = func();
-
-      if (value || (key != "storagechange" && key != "historychange")) {
-        data[key] = value;
-      }
-    }
-
-    this._data.clear();
-
-    try {
-      // Send all data to the parent process.
-      this.eventDispatcher.sendRequest({
-        type: "GeckoView:StateUpdated",
-        data, flushID,
-        isFinal: options.isFinal || false,
-        epoch: this.store.epoch,
-      });
-    } catch (ex) {
-      if (ex && ex.result == Cr.NS_ERROR_OUT_OF_MEMORY) {
-        warn `Failed to save session state`;
-      }
-    }
-  }
-}
-
-class SessionStateAggregator extends GeckoViewChildModule {
-  constructor(aModuleName, aMessageManager) {
-    super(aModuleName, aMessageManager);
-
-    this.mm = aMessageManager;
-    this.messageQueue = new MessageQueue(this);
-    this.stateChangeNotifier = new StateChangeNotifier(this);
-
-    this.handlers = [
-      new FormDataListener(this),
-      new SessionHistoryListener(this),
-      new ScrollPositionListener(this),
-      this.stateChangeNotifier,
-      this.messageQueue,
-    ];
-  }
-
-  flush({id}) {
-    // Flush the message queue, send the latest updates.
-    this.messageQueue.send({flushID: id});
-  }
-
-  onUnload() {
-    // Upon frameLoader destruction, send a final update message to
-    // the parent and flush all data currently held in the child.
-    this.messageQueue.send({isFinal: true});
-
-    for (let handler of this.handlers) {
-      if (handler.uninit) {
-        handler.uninit();
-      }
-    }
-
-    // We don't need to take care of any StateChangeNotifier observers as they
-    // will die with the content script.
-  }
-}
-
-const {debug, warn} = SessionStateAggregator.initLogging("SessionStateAggregator"); // eslint-disable-line no-unused-vars
-const module = SessionStateAggregator.create(this);
--- a/mobile/android/chrome/geckoview/geckoview.js
+++ b/mobile/android/chrome/geckoview/geckoview.js
@@ -452,21 +452,16 @@ function startup() {
     onInit: {
       resource: "resource://gre/modules/GeckoViewTab.jsm",
     },
   }, {
     name: "GeckoViewContentBlocking",
     onEnable: {
       resource: "resource://gre/modules/GeckoViewContentBlocking.jsm",
     },
-  }, {
-    name: "SessionStateAggregator",
-    onInit: {
-      frameScript: "chrome://geckoview/content/SessionStateAggregator.js",
-    },
   }]);
 
   Services.tm.dispatchToMainThread(() => {
     // This should always be the first thing we do here - any additional delayed
     // initialisation tasks should be added between "browser-delayed-startup-finished"
     // and "browser-idle-startup-tasks-finished".
 
     // Bug 1496684: Various bits of platform stuff depend on this notification
--- a/mobile/android/chrome/geckoview/jar.mn
+++ b/mobile/android/chrome/geckoview/jar.mn
@@ -15,11 +15,10 @@ geckoview.jar:
   content/GeckoViewContentChild.js
   content/GeckoViewMediaChild.js
   content/GeckoViewNavigationChild.js
   content/GeckoViewProgressChild.js
   content/GeckoViewPromptChild.js
   content/GeckoViewScrollChild.js
   content/GeckoViewSettingsChild.js
   content/GeckoViewSelectionActionChild.js
-  content/SessionStateAggregator.js
 
 % content branding %content/branding/
--- a/mobile/android/geckoview/api.txt
+++ b/mobile/android/geckoview/api.txt
@@ -308,16 +308,17 @@ package org.mozilla.geckoview {
     method @android.support.annotation.AnyThread public void loadUri(@android.support.annotation.NonNull android.net.Uri);
     method @android.support.annotation.AnyThread public void loadUri(@android.support.annotation.NonNull android.net.Uri, int);
     method @android.support.annotation.AnyThread public void loadUri(@android.support.annotation.NonNull android.net.Uri, @android.support.annotation.Nullable android.net.Uri, int);
     method @android.support.annotation.UiThread public void open(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoRuntime);
     method @android.support.annotation.AnyThread public void readFromParcel(@android.support.annotation.NonNull android.os.Parcel);
     method @android.support.annotation.UiThread public void releaseDisplay(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoDisplay);
     method @android.support.annotation.AnyThread public void reload();
     method @android.support.annotation.AnyThread public void restoreState(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession.SessionState);
+    method @android.support.annotation.AnyThread @android.support.annotation.NonNull public org.mozilla.geckoview.GeckoResult<org.mozilla.geckoview.GeckoSession.SessionState> saveState();
     method @android.support.annotation.AnyThread public void setActive(boolean);
     method @android.support.annotation.AnyThread public void setContentBlockingDelegate(@android.support.annotation.Nullable org.mozilla.geckoview.ContentBlocking.Delegate);
     method @android.support.annotation.UiThread public void setContentDelegate(@android.support.annotation.Nullable org.mozilla.geckoview.GeckoSession.ContentDelegate);
     method @android.support.annotation.AnyThread public void setFocused(boolean);
     method @android.support.annotation.AnyThread public void setHistoryDelegate(@android.support.annotation.Nullable org.mozilla.geckoview.GeckoSession.HistoryDelegate);
     method @android.support.annotation.AnyThread public void setMediaDelegate(@android.support.annotation.Nullable org.mozilla.geckoview.GeckoSession.MediaDelegate);
     method @android.support.annotation.UiThread public void setNavigationDelegate(@android.support.annotation.Nullable org.mozilla.geckoview.GeckoSession.NavigationDelegate);
     method @android.support.annotation.UiThread public void setPermissionDelegate(@android.support.annotation.Nullable org.mozilla.geckoview.GeckoSession.PermissionDelegate);
@@ -466,17 +467,16 @@ package org.mozilla.geckoview {
   public static interface GeckoSession.PermissionDelegate.Permission implements java.lang.annotation.Annotation {
   }
 
   public static interface GeckoSession.ProgressDelegate {
     method @android.support.annotation.UiThread default public void onPageStart(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, @android.support.annotation.NonNull java.lang.String);
     method @android.support.annotation.UiThread default public void onPageStop(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, boolean);
     method @android.support.annotation.UiThread default public void onProgressChange(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, int);
     method @android.support.annotation.UiThread default public void onSecurityChange(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, @android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession.ProgressDelegate.SecurityInformation);
-    method @android.support.annotation.UiThread default public void onSessionStateChange(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, @android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession.SessionState);
   }
 
   public static class GeckoSession.ProgressDelegate.SecurityInformation {
     ctor protected SecurityInformation();
     field public static final int CONTENT_BLOCKED = 1;
     field public static final int CONTENT_LOADED = 2;
     field public static final int CONTENT_UNKNOWN = 0;
     field public static final int SECURITY_MODE_IDENTIFIED = 1;
@@ -624,19 +624,18 @@ package org.mozilla.geckoview {
   public static class GeckoSession.SelectionActionDelegate.Selection {
     ctor protected Selection();
     field public final android.graphics.RectF clientRect;
     field public final int flags;
     field public final java.lang.String text;
   }
 
   @android.support.annotation.AnyThread public static class GeckoSession.SessionState implements android.os.Parcelable {
-    ctor public SessionState(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession.SessionState);
+    ctor public SessionState(java.lang.String);
     method public void readFromParcel(@android.support.annotation.NonNull android.os.Parcel);
-    method public void updateSessionState(@android.support.annotation.NonNull org.mozilla.gecko.util.GeckoBundle);
     field public static final android.os.Parcelable.Creator<org.mozilla.geckoview.GeckoSession.SessionState> CREATOR;
   }
 
   public static interface GeckoSession.TextInputDelegate {
     method @android.support.annotation.UiThread default public void hideSoftInput(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession);
     method @android.support.annotation.UiThread default public void notifyAutoFill(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, int, int);
     method @android.support.annotation.UiThread default public void restartInput(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession, int);
     method @android.support.annotation.UiThread default public void showSoftInput(@android.support.annotation.NonNull org.mozilla.geckoview.GeckoSession);
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt
@@ -170,16 +170,76 @@ class ContentDelegateTest : BaseSessionT
                 @AssertCalled(count = 1)
                 override fun onCrash(session: GeckoSession) {
                     remainingSessions.remove(session)
                 }
             })
         }
     }
 
+    @WithDevToolsAPI
+    @WithDisplay(width = 400, height = 400)
+    @Test fun saveAndRestoreState() {
+        val startUri = createTestUrl(SAVE_STATE_PATH)
+        mainSession.loadUri(startUri)
+        sessionRule.waitForPageStop()
+
+        mainSession.evaluateJS("$('#name').value = 'the name'; window.setTimeout(() => window.scrollBy(0, 100),0);")
+        sessionRule.waitUntilCalled(Callbacks.ScrollDelegate::class, "onScrollChanged")
+
+        val state = sessionRule.waitForResult(mainSession.saveState())
+        assertThat("State should not be null", state, notNullValue())
+
+        mainSession.loadUri("about:blank")
+        sessionRule.waitForPageStop()
+
+        mainSession.restoreState(state)
+        sessionRule.waitForPageStop()
+
+        sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
+            @AssertCalled
+            override fun onLocationChange(session: GeckoSession, url: String?) {
+                assertThat("URI should match", url, equalTo(startUri))
+            }
+        })
+
+        assertThat("'name' field should match",
+                mainSession.evaluateJS("$('#name').value").toString(),
+                equalTo("the name"))
+
+        assertThat("Scroll position should match",
+                mainSession.evaluateJS("window.visualViewport.pageTop") as Double,
+                closeTo(100.0, .5))
+    }
+
+    @Test fun saveStateSync() {
+        val startUri = createTestUrl(SAVE_STATE_PATH)
+        mainSession.loadUri(startUri)
+        sessionRule.waitForPageStop()
+
+        var worker = thread {
+            Looper.prepare()
+
+            var thread = Thread.currentThread()
+            mainSession.saveState().then<Void> { _: GeckoSession.SessionState? ->
+                assertThat("We should be on the worker thread", Thread.currentThread(),
+                        equalTo(thread))
+                Looper.myLooper().quit()
+                null
+            }
+
+            Looper.loop()
+        }
+
+        worker.join(sessionRule.timeoutMillis)
+        if (worker.isAlive) {
+            throw UiThreadUtils.TimeoutException("Timed out")
+        }
+    }
+
     val ViewNode by lazy {
         AssistStructure.ViewNode::class.java.getDeclaredConstructor().apply { isAccessible = true }
     }
 
     val ViewNodeBuilder by lazy {
         Class.forName("android.app.assist.AssistStructure\$ViewNodeBuilder")
                 .getDeclaredConstructor(AssistStructure::class.java,
                                         AssistStructure.ViewNode::class.java,
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
@@ -57,26 +57,20 @@ class GeckoSessionTestRuleTest : BaseSes
                    sessionRule.session.settings.useTrackingProtection,
                    equalTo(true))
         assertThat("ALLOW_JAVASCRIPT should be set",
                 sessionRule.session.settings.allowJavascript,
                 equalTo(false))
     }
 
     @Test(expected = UiThreadUtils.TimeoutException::class)
-    @TimeoutMillis(2000)
+    @TimeoutMillis(1000)
     fun noPendingCallbacks() {
         // Make sure we don't have unexpected pending callbacks at the start of a test.
-        sessionRule.waitUntilCalled(object : Callbacks.All {
-            // There may be an extraneous onSessionStateChange call after a test,
-            // so ignore the first received.
-            @AssertCalled(count=2)
-            override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) {
-            }
-        })
+        sessionRule.waitUntilCalled(object : Callbacks.All {})
     }
 
     @Test fun includesAllCallbacks() {
         for (ifce in GeckoSession::class.java.classes) {
             if (!ifce.isInterface || !ifce.simpleName.endsWith("Delegate")) {
                 continue
             }
             assertThat("Callbacks.All should include interface " + ifce.simpleName,
@@ -181,20 +175,16 @@ class GeckoSessionTestRuleTest : BaseSes
             override fun onSecurityChange(session: GeckoSession,
                                           securityInfo: GeckoSession.ProgressDelegate.SecurityInformation) {
                 counter++
             }
 
             override fun onProgressChange(session: GeckoSession, progress: Int) {
                 counter++
             }
-
-            override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) {
-                counter++
-            }
         })
 
         assertThat("Callback count should be correct", counter, equalTo(1))
     }
 
     @Test fun waitUntilCalled_specificInterfaceMethod() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.waitUntilCalled(GeckoSession.ProgressDelegate::class,
@@ -256,20 +246,16 @@ class GeckoSessionTestRuleTest : BaseSes
             override fun onSecurityChange(session: GeckoSession,
                                           securityInfo: GeckoSession.ProgressDelegate.SecurityInformation) {
                 counter++
             }
 
             override fun onProgressChange(session: GeckoSession, progress: Int) {
                 counter++
             }
-
-            override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) {
-                counter++
-            }
         })
 
         assertThat("Callback count should be correct", counter, equalTo(1))
     }
 
     @Test fun waitUntilCalled_specificObjectMethod() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
 
@@ -967,28 +953,22 @@ class GeckoSessionTestRuleTest : BaseSes
     @Test fun createClosedSession_withSettings() {
         val settings = GeckoSessionSettings.Builder(sessionRule.session.settings).usePrivateMode(true).build()
 
         val newSession = sessionRule.createClosedSession(settings)
         assertThat("New session has same settings", newSession.settings, equalTo(settings))
     }
 
     @Test(expected = UiThreadUtils.TimeoutException::class)
-    @TimeoutMillis(2000)
+    @TimeoutMillis(1000)
     @ClosedSessionAtStart
     fun noPendingCallbacks_withSpecificSession() {
         sessionRule.createOpenSession()
         // Make sure we don't have unexpected pending callbacks after opening a session.
-        sessionRule.waitUntilCalled(object : Callbacks.All {
-            // There may be an extraneous onSessionStateChange call after a test,
-            // so ignore the first received.
-            @AssertCalled(count=2)
-            override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) {
-            }
-        })
+        sessionRule.waitUntilCalled(object : Callbacks.All {})
     }
 
     @Test fun waitForPageStop_withSpecificSession() {
         val newSession = sessionRule.createOpenSession()
         newSession.loadTestPath(HELLO_HTML_PATH)
         newSession.waitForPageStop()
     }
 
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt
@@ -2,18 +2,16 @@
  * Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 package org.mozilla.geckoview.test
 
 import org.mozilla.geckoview.GeckoResult
 import org.mozilla.geckoview.GeckoSession
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
-import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDevToolsAPI
-import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay
 import org.mozilla.geckoview.test.util.Callbacks
 
 import android.support.test.filters.MediumTest
 import android.support.test.filters.LargeTest
 import android.support.test.runner.AndroidJUnit4
 
 import org.hamcrest.Matchers.*
 import org.junit.Assume.assumeThat
@@ -279,54 +277,9 @@ class ProgressDelegateTest : BaseSession
             }
 
             @AssertCalled(false)
             override fun onSecurityChange(session: GeckoSession,
                                           securityInfo: GeckoSession.ProgressDelegate.SecurityInformation) {
             }
         })
     }
-
-    @WithDevToolsAPI
-    @WithDisplay(width = 400, height = 400)
-    @Test fun saveAndRestoreState() {
-        val startUri = createTestUrl(SAVE_STATE_PATH)
-        mainSession.loadUri(startUri)
-        sessionRule.waitForPageStop()
-
-        mainSession.evaluateJS("$('#name').value = 'the name'; window.setTimeout(() => window.scrollBy(0, 100),0);")
-        mainSession.evaluateJS("$('#name').dispatchEvent(new Event('input'));")
-        sessionRule.waitUntilCalled(Callbacks.ScrollDelegate::class, "onScrollChanged")
-
-        var savedState : GeckoSession.SessionState? = null
-        sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate {
-            @AssertCalled(count=1)
-            override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) {
-                savedState = state
-            }
-        })
-
-        assertThat("State should not be null", savedState, notNullValue())
-
-        mainSession.loadUri("about:blank")
-        sessionRule.waitForPageStop()
-
-        mainSession.restoreState(savedState!!)
-        sessionRule.waitForPageStop()
-
-        sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
-            @AssertCalled
-            override fun onLocationChange(session: GeckoSession, url: String?) {
-                assertThat("URI should match", url, equalTo(startUri))
-            }
-        })
-
-        /* TODO: Reenable when we have a workaround for ContentSessionStore not
-                 saving in response to JS-driven formdata changes.
-        assertThat("'name' field should match",
-                mainSession.evaluateJS("$('#name').value").toString(),
-                equalTo("the name"))*/
-
-        assertThat("Scroll position should match",
-                mainSession.evaluateJS("window.visualViewport.pageTop") as Double,
-                closeTo(100.0, .5))
-    }
 }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -572,18 +572,17 @@ public class GeckoSession implements Par
 
     private final GeckoSessionHandler<ProgressDelegate> mProgressHandler =
         new GeckoSessionHandler<ProgressDelegate>(
             "GeckoViewProgress", this,
             new String[]{
                 "GeckoView:PageStart",
                 "GeckoView:PageStop",
                 "GeckoView:ProgressChanged",
-                "GeckoView:SecurityChanged",
-                "GeckoView:StateUpdated"
+                "GeckoView:SecurityChanged"
             }
         ) {
             @Override
             public void handleMessage(final ProgressDelegate delegate,
                                       final String event,
                                       final GeckoBundle message,
                                       final EventCallback callback) {
                 if ("GeckoView:PageStart".equals(event)) {
@@ -593,22 +592,16 @@ public class GeckoSession implements Par
                     delegate.onPageStop(GeckoSession.this,
                                         message.getBoolean("success"));
                 } else if ("GeckoView:ProgressChanged".equals(event)) {
                     delegate.onProgressChange(GeckoSession.this,
                                               message.getInt("progress"));
                 } else if ("GeckoView:SecurityChanged".equals(event)) {
                     final GeckoBundle identity = message.getBundle("identity");
                     delegate.onSecurityChange(GeckoSession.this, new ProgressDelegate.SecurityInformation(identity));
-                } else if ("GeckoView:StateUpdated".equals(event)) {
-                    final GeckoBundle update = message.getBundle("data");
-                    if (update != null) {
-                        mStateCache.updateSessionState(update);
-                        delegate.onSessionStateChange(GeckoSession.this, new SessionState(mStateCache));
-                    }
                 }
             }
         };
 
     private final GeckoSessionHandler<ScrollDelegate> mScrollHandler =
         new GeckoSessionHandler<ScrollDelegate>(
             "GeckoViewScroll", this,
             new String[]{ "GeckoView:ScrollChanged" }
@@ -1727,135 +1720,94 @@ public class GeckoSession implements Par
         mEventDispatcher.dispatch("GeckoView:SetFocused", msg);
     }
 
     /**
      * Class representing a saved session state.
      */
     @AnyThread
     public static class SessionState implements Parcelable {
-        private GeckoBundle mState;
-
-        private SessionState() {
-            mState = new GeckoBundle(3);
-        }
-
-        private SessionState(final @NonNull GeckoBundle state) {
-            mState = new GeckoBundle(state);
-        }
-
-        public SessionState(final @NonNull SessionState state) {
-            mState = new GeckoBundle(state.mState);
-        }
-
-        public void updateSessionState(final @NonNull GeckoBundle updateData) {
-            if (updateData == null) {
-                Log.w(LOGTAG, "Session state update has no data field.");
-                return;
-            }
-
-            final GeckoBundle history = updateData.getBundle("historychange");
-            final GeckoBundle scroll = updateData.getBundle("scroll");
-            final GeckoBundle formdata = updateData.getBundle("formdata");
-
-            if (history != null) {
-                mState.putBundle("history", history);
-            }
-
-            if (scroll != null) {
-                mState.putBundle("scrolldata", scroll);
-            }
-
-            if (formdata != null) {
-                mState.putBundle("formdata", formdata);
-            }
-
-            return;
+        private String mState;
+
+        /**
+         * Construct a SessionState from a String.
+         *
+         * @param state A String representing a SessionState; should originate as output
+         *              of SessionState.toString().
+         */
+        public SessionState(final String state) {
+            mState = state;
         }
 
         @Override
         public String toString() {
-            if (mState == null) {
-                Log.w(LOGTAG, "Can't convert SessionState with null state to string");
-                return null;
-            }
-
-            String res;
-            try {
-                res = mState.toJSONObject().toString();
-            } catch (JSONException e) {
-                Log.e(LOGTAG, "Could not convert session state to string.");
-                res = null;
-            }
-
-            return res;
+            return mState;
         }
 
         @Override // Parcelable
         public int describeContents() {
             return 0;
         }
 
         @Override // Parcelable
         public void writeToParcel(final Parcel dest, final int flags) {
-            dest.writeString(toString());
+            dest.writeString(mState);
         }
 
         // AIDL code may call readFromParcel even though it's not part of Parcelable.
         public void readFromParcel(final @NonNull Parcel source) {
-            if (source.readString() == null) {
-                Log.w(LOGTAG, "Can't reproduce session state from Parcel");
-            }
-
-            try {
-                mState = GeckoBundle.fromJSONObject(new JSONObject(source.readString()));
-            } catch (JSONException e) {
-                Log.e(LOGTAG, "Could not convert string to session state.");
-                mState = null;
-            }
+            mState = source.readString();
         }
 
         public static final Parcelable.Creator<SessionState> CREATOR =
                 new Parcelable.Creator<SessionState>() {
             @Override
             public SessionState createFromParcel(final Parcel source) {
-                if (source.readString() == null) {
-                    Log.w(LOGTAG, "Can't create session state from Parcel");
-                }
-
-                GeckoBundle res;
-                try {
-                    res = GeckoBundle.fromJSONObject(new JSONObject(source.readString()));
-                } catch (JSONException e) {
-                    Log.e(LOGTAG, "Could not convert parcel to session state.");
-                    res = null;
-                }
-
-                return new SessionState(res);
+                return new SessionState(source.readString());
             }
 
             @Override
             public SessionState[] newArray(final int size) {
                 return new SessionState[size];
             }
         };
     }
 
-    private SessionState mStateCache = new SessionState();
+    /**
+     * Save the current browsing session state of this GeckoSession. This session state
+     * includes the history, scroll position, zoom, and any form data that has been entered,
+     * but does not include information pertaining to the GeckoSession itself (for example,
+     * this does not include settings on the GeckoSession).
+     *
+     * @return A {@link GeckoResult} containing the {@link SessionState}
+     */
+    @AnyThread
+    public @NonNull GeckoResult<SessionState> saveState() {
+        CallbackResult<SessionState> result = new CallbackResult<SessionState>() {
+            @Override
+            public void sendSuccess(final Object value) {
+                complete(new SessionState((String)value));
+            }
+        };
+        mEventDispatcher.dispatch("GeckoView:SaveState", null, result);
+        return result;
+    }
 
     /**
      * Restore a saved state to this GeckoSession; only data that is saved (history, scroll
      * position, zoom, and form data) will be restored. These will overwrite the corresponding
      * state of this GeckoSession.
      *
-     * @param state A saved session state; this should originate from onSessionStateChange().
+     * @param state A saved session state; this should originate from GeckoSession.saveState().
      */
     @AnyThread
     public void restoreState(final @NonNull SessionState state) {
-        mEventDispatcher.dispatch("GeckoView:RestoreState", state.mState);
+        final GeckoBundle msg = new GeckoBundle(1);
+        msg.putString("state", state.toString());
+        mEventDispatcher.dispatch("GeckoView:RestoreState", msg);
     }
 
     // This is the GeckoDisplay acquired via acquireDisplay(), if any.
     private GeckoDisplay mDisplay;
     /* package */ GeckoDisplay getDisplay() {
         return mDisplay;
     }
 
@@ -2623,27 +2575,16 @@ public class GeckoSession implements Par
         /**
         * The security status has been updated.
         * @param session GeckoSession that initiated the callback.
         * @param securityInfo The new security information.
         */
         @UiThread
         default void onSecurityChange(@NonNull GeckoSession session,
                                       @NonNull SecurityInformation securityInfo) {}
-
-        /**
-        * The browser session state has changed. This can happen in response to 
-        * navigation, scrolling, or form data changes; the session state passed
-        * includes the most up to date information on all of these.
-        * @param session GeckoSession that initiated the callback.
-        * @param sessionState SessionState representing the latest browser state.
-        */
-        @UiThread
-        default void onSessionStateChange(@NonNull GeckoSession session,
-                                          @NonNull SessionState sessionState) {}
     }
 
     /**
      * WebResponseInfo contains information about a single web response.
      */
     @AnyThread
     static public class WebResponseInfo {
         /**
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md
@@ -9,20 +9,16 @@ exclude: true
 <h1> GeckoView API Changelog. </h1>
 
 ## v68
 - Added [`GeckoRuntime#configurationChanged`][68.1] to notify the device
   configuration has changed.
 
 [68.1]: ../GeckoRuntime.html#configurationChanged
 
-- Added `onSessionStateChange` to [`ProgressDelegate`][68.2] and removed `saveState`.
-
-[68.2]: ../GeckoSession.ProgressDelegate.html
-
 ## v67
 - Added [`setAutomaticFontSizeAdjustment`][67.2] to
   [`GeckoRuntimeSettings`][67.3] for automatically adjusting font size settings
   depending on the OS-level font size setting.
 
 [67.2]: ../GeckoRuntimeSettings.html#setAutomaticFontSizeAdjustment-boolean-
 [67.3]: ../GeckoRuntimeSettings.html
 
@@ -219,9 +215,9 @@ exclude: true
 [65.23]: ../GeckoSession.FinderResult.html
 
 - Update [`CrashReporter#sendCrashReport`][65.24] to return the crash ID as a
   [`GeckoResult<String>`][65.25].
 
 [65.24]: ../CrashReporter.html#sendCrashReport-android.content.Context-android.os.Bundle-java.lang.String-
 [65.25]: ../GeckoResult.html
 
-[api-version]: e8fa4ed799e78f64fddd3f2c463202942811de11
+[api-version]: 07af02921c277f9461d7532f2a6a78c527c9cb47
--- a/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
+++ b/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
@@ -576,21 +576,16 @@ public class GeckoViewActivity extends A
                 mProgressView.setVisibility(View.GONE);
             }
         }
 
         @Override
         public void onSecurityChange(GeckoSession session, SecurityInformation securityInfo) {
             Log.i(LOGTAG, "Security status changed to " + securityInfo.securityMode);
         }
-
-        @Override
-        public void onSessionStateChange(GeckoSession session, GeckoSession.SessionState state) {
-            Log.i(LOGTAG, "New Session state: " + state.toString());
-        }
     }
 
     private class ExamplePermissionDelegate implements GeckoSession.PermissionDelegate {
 
         public int androidPermissionRequestCode = 1;
         private Callback mCallback;
 
         class ExampleNotificationCallback implements GeckoSession.PermissionDelegate.Callback {
--- a/mobile/android/modules/geckoview/GeckoViewContent.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewContent.jsm
@@ -16,22 +16,25 @@ XPCOMUtils.defineLazyModuleGetters(this,
 class GeckoViewContent extends GeckoViewModule {
   onInit() {
     this.registerListener([
         "GeckoViewContent:ExitFullScreen",
         "GeckoView:ClearMatches",
         "GeckoView:DisplayMatches",
         "GeckoView:FindInPage",
         "GeckoView:RestoreState",
+        "GeckoView:SaveState",
         "GeckoView:SetActive",
         "GeckoView:SetFocused",
         "GeckoView:ZoomToInput",
         "GeckoView:ScrollBy",
         "GeckoView:ScrollTo",
     ]);
+
+    this.messageManager.addMessageListener("GeckoView:SaveStateFinish", this);
   }
 
   onEnable() {
     this.window.addEventListener("MozDOMFullscreen:Entered", this,
                                  /* capture */ true, /* untrusted */ false);
     this.window.addEventListener("MozDOMFullscreen:Exited", this,
                                  /* capture */ true, /* untrusted */ false);
 
@@ -98,18 +101,27 @@ class GeckoViewContent extends GeckoView
         if (aData.focused) {
           this.browser.focus();
           this.browser.setAttribute("primary", "true");
         } else {
           this.browser.removeAttribute("primary");
           this.browser.blur();
         }
         break;
+      case "GeckoView:SaveState":
+        if (!this._saveStateCallbacks) {
+          this._saveStateCallbacks = new Map();
+          this._saveStateNextId = 0;
+        }
+        this._saveStateCallbacks.set(this._saveStateNextId, aCallback);
+        this.messageManager.sendAsyncMessage("GeckoView:SaveState", {id: this._saveStateNextId});
+        this._saveStateNextId++;
+        break;
       case "GeckoView:RestoreState":
-        this.messageManager.sendAsyncMessage("GeckoView:RestoreState", aData);
+        this.messageManager.sendAsyncMessage("GeckoView:RestoreState", {state: aData.state});
         break;
     }
   }
 
   // DOM event handler
   handleEvent(aEvent) {
     debug `handleEvent: ${aEvent.type}`;
 
@@ -134,16 +146,30 @@ class GeckoViewContent extends GeckoView
       case "GeckoView:DOMFullscreenExit":
         this.window.windowUtils
                    .remoteFrameFullscreenReverted();
         break;
       case "GeckoView:DOMFullscreenRequest":
         this.window.windowUtils
                    .remoteFrameFullscreenChanged(aMsg.target);
         break;
+      case "GeckoView:SaveStateFinish":
+        if (!this._saveStateCallbacks || !this._saveStateCallbacks.has(aMsg.data.id)) {
+          warn `Failed to save state due to missing callback`;
+          return;
+        }
+
+        const callback = this._saveStateCallbacks.get(aMsg.data.id);
+        if (aMsg.data.error) {
+          callback.onError(aMsg.data.error);
+        } else {
+          callback.onSuccess(aMsg.data.state);
+        }
+        this._saveStateCallbacks.delete(aMsg.data.id);
+        break;
     }
   }
 
   // nsIObserver event handler
   observe(aSubject, aTopic, aData) {
     debug `observe: ${aTopic}`;
 
     switch (aTopic) {