Bug 1599257 - [remote] Move "Page.navigate" to parent process r=remote-protocol-reviewers,whimboo

This facilitates monitoring the navigation response.

The remaining work for moving navigation-related code into
the parent process should be done in Bug 1612538.

Differential Revision: https://phabricator.services.mozilla.com/D71654
This commit is contained in:
Maja Frydrychowicz 2020-04-24 16:29:43 +00:00
Родитель 84e60a5d6c
Коммит 9c69406a63
2 изменённых файлов: 49 добавлений и 28 удалений

Просмотреть файл

@ -6,7 +6,6 @@
var EXPORTED_SYMBOLS = ["Page"]; var EXPORTED_SYMBOLS = ["Page"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import( const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm" "resource://gre/modules/XPCOMUtils.jsm"
); );
@ -115,23 +114,6 @@ class Page extends ContentProcessDomain {
} }
} }
async navigate({ url, referrer, transitionType, frameId } = {}) {
if (frameId && frameId != this.docShell.browsingContext.id.toString()) {
throw new UnsupportedError("frameId not supported");
}
const opts = {
loadFlags: transitionToLoadFlag(transitionType),
referrerURI: referrer,
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
};
this.docShell.loadURI(url, opts);
return {
frameId: this.docShell.browsingContext.id.toString(),
};
}
async reload({ ignoreCache }) { async reload({ ignoreCache }) {
let flags = LOAD_FLAGS_NONE; let flags = LOAD_FLAGS_NONE;
if (ignoreCache) { if (ignoreCache) {
@ -396,13 +378,3 @@ class Page extends ContentProcessDomain {
}; };
} }
} }
function transitionToLoadFlag(transitionType) {
switch (transitionType) {
case "reload":
return Ci.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH;
case "link":
default:
return Ci.nsIWebNavigation.LOAD_FLAGS_IS_LINK;
}
}

Просмотреть файл

@ -10,6 +10,8 @@ var { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm" "resource://gre/modules/XPCOMUtils.jsm"
); );
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetters(this, { XPCOMUtils.defineLazyModuleGetters(this, {
SessionStore: "resource:///modules/sessionstore/SessionStore.jsm", SessionStore: "resource:///modules/sessionstore/SessionStore.jsm",
}); });
@ -71,6 +73,43 @@ class Page extends Domain {
// commands // commands
/**
* Navigates current page to given URL.
*
* @param {Object} options
* @param {string} options.url
* destination URL
* @param {string=} options.frameId
* frame id to navigate (not supported),
* if not specified navigate top frame
* @param {string=} options.referrer
* referred URL (optional)
* @param {string=} options.transitionType
* intended transition type
* @return {Object}
* - frameId {string} frame id that has navigated (or failed to)
* - errorText {string} error message if navigation has failed
* (not supported)
* - loaderId {string} (not supported)
*/
async navigate(options = {}) {
const { url, frameId, referrer, transitionType } = options;
if (frameId && frameId != this.session.browsingContext.id.toString()) {
throw new UnsupportedError("frameId not supported");
}
const opts = {
loadFlags: transitionToLoadFlag(transitionType),
referrerURI: referrer,
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
};
this.session.browsingContext.loadURI(url, opts);
return {
frameId: this.session.browsingContext.id.toString(),
};
}
/** /**
* Capture page screenshot. * Capture page screenshot.
* *
@ -633,3 +672,13 @@ class Page extends Domain {
this.emit("Page.javascriptDialogOpening", { message, type }); this.emit("Page.javascriptDialogOpening", { message, type });
} }
} }
function transitionToLoadFlag(transitionType) {
switch (transitionType) {
case "reload":
return Ci.nsIWebNavigation.LOAD_FLAGS_IS_REFRESH;
case "link":
default:
return Ci.nsIWebNavigation.LOAD_FLAGS_IS_LINK;
}
}