Bug 1610377 - [remote] Move session history navigation code into the parent process. r=remote-protocol-reviewers,maja_zf

Differential Revision: https://phabricator.services.mozilla.com/D62588

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Henrik Skupin 2020-02-13 08:55:27 +00:00
parent 938fe1ae72
commit ed04cb5f4b
2 changed files with 64 additions and 54 deletions

View File

@ -91,40 +91,6 @@ class Page extends ContentProcessDomain {
}
}
/**
* Returns navigation history for the current page.
*
* @return {currentIndex:number, entries:Array<NavigationEntry>}
* Based on the transferMode setting data is a base64-encoded string,
* or stream is a handle to a OS.File stream.
*/
getNavigationHistory() {
const sessionHistory = this.docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsISHistory);
const entries = [];
for (let index = 0; index < sessionHistory.count; index++) {
const entry = sessionHistory.getEntryAtIndex(index);
const typedURL = entry.originalURI || entry.URI;
entries.push({
id: entry.ID,
url: entry.URI.spec,
userTypedURL: typedURL.spec,
title: entry.title,
// TODO: Bug 1609514
transitionType: null,
});
}
return {
currentIndex: sessionHistory.index,
entries,
};
}
async navigate({ url, referrer, transitionType, frameId } = {}) {
if (frameId && frameId != this.docShell.browsingContext.id.toString()) {
throw new UnsupportedError("frameId not supported");
@ -347,22 +313,6 @@ class Page extends ContentProcessDomain {
return this.content.devicePixelRatio;
}
_getIndexForHistoryEntryId(id) {
const sessionHistory = this.docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsISHistory);
for (let index = 0; index < sessionHistory.count; index++) {
const entry = sessionHistory.getEntryAtIndex(index);
if (entry.ID == id) {
return index;
}
}
return null;
}
_getScrollbarSize() {
const scrollbarHeight = {};
const scrollbarWidth = {};

View File

@ -6,6 +6,14 @@
var EXPORTED_SYMBOLS = ["Page"];
var { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
SessionStore: "resource:///modules/sessionstore/SessionStore.jsm",
});
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const { clearInterval, setInterval } = ChromeUtils.import(
"resource://gre/modules/Timer.jsm"
@ -278,6 +286,40 @@ class Page extends Domain {
};
}
/**
* Returns navigation history for the current page.
*
* @return {currentIndex:number, entries:Array<NavigationEntry>}
*/
async getNavigationHistory() {
const { window } = this.session.target;
return new Promise(resolve => {
function updateSessionHistory(sessionHistory) {
const entries = sessionHistory.entries.map(entry => {
return {
id: entry.ID,
url: entry.url,
userTypedURL: entry.originalURI || entry.url,
title: entry.title,
// TODO: Bug 1609514
transitionType: null,
};
});
resolve({
currentIndex: sessionHistory.index,
entries,
});
}
SessionStore.getSessionHistory(
window.gBrowser.selectedTab,
updateSessionHistory
);
});
}
/**
* Interact with the currently opened JavaScript dialog (alert, confirm,
* prompt) for this page. This will always close the dialog, either accepting
@ -307,10 +349,7 @@ class Page extends Domain {
async navigateToHistoryEntry(options = {}) {
const { entryId } = options;
const index = await this.executeInChild(
"_getIndexForHistoryEntryId",
entryId
);
const index = await this._getIndexForHistoryEntryId(entryId);
if (index == null) {
throw new Error("No entry with passed id");
@ -530,6 +569,27 @@ class Page extends Domain {
*/
setInterceptFileChooserDialog(options = {}) {}
_getIndexForHistoryEntryId(id) {
const { window } = this.session.target;
return new Promise(resolve => {
function updateSessionHistory(sessionHistory) {
sessionHistory.entries.forEach((entry, index) => {
if (entry.ID == id) {
resolve(index);
}
});
resolve(null);
}
SessionStore.getSessionHistory(
window.gBrowser.selectedTab,
updateSessionHistory
);
});
}
/**
* Emit the proper CDP event javascriptDialogOpening when a javascript dialog
* opens for the current target.