2018-07-30 03:08:58 +03:00
|
|
|
/* -*- 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";
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = ["WebNavigationChild"];
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { ActorChild } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/ActorChild.jsm"
|
|
|
|
);
|
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
|
|
|
);
|
2019-07-05 12:04:56 +03:00
|
|
|
|
2018-07-30 03:08:58 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"AppConstants",
|
|
|
|
"resource://gre/modules/AppConstants.jsm"
|
|
|
|
);
|
2019-02-12 22:35:24 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"E10SUtils",
|
|
|
|
"resource://gre/modules/E10SUtils.jsm"
|
|
|
|
);
|
2019-07-05 12:04:56 +03:00
|
|
|
|
2018-07-30 03:08:58 +03:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(
|
|
|
|
this,
|
|
|
|
"CrashReporter",
|
|
|
|
"@mozilla.org/xre/app-info;1",
|
|
|
|
"nsICrashReporter"
|
|
|
|
);
|
|
|
|
|
2018-07-30 22:55:22 +03:00
|
|
|
class WebNavigationChild extends ActorChild {
|
2018-07-30 03:08:58 +03:00
|
|
|
get webNavigation() {
|
|
|
|
return this.mm.docShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
}
|
|
|
|
|
|
|
|
receiveMessage(message) {
|
|
|
|
switch (message.name) {
|
|
|
|
case "WebNavigation:GoBack":
|
2019-05-01 02:31:46 +03:00
|
|
|
this.goBack(message.data);
|
2018-07-30 03:08:58 +03:00
|
|
|
break;
|
|
|
|
case "WebNavigation:GoForward":
|
2019-05-01 02:31:46 +03:00
|
|
|
this.goForward(message.data);
|
2018-07-30 03:08:58 +03:00
|
|
|
break;
|
|
|
|
case "WebNavigation:GotoIndex":
|
2019-05-01 02:31:46 +03:00
|
|
|
this.gotoIndex(message.data);
|
2018-07-30 03:08:58 +03:00
|
|
|
break;
|
|
|
|
case "WebNavigation:LoadURI":
|
2019-02-22 11:19:26 +03:00
|
|
|
this.loadURI(message.data);
|
2018-07-30 03:08:58 +03:00
|
|
|
break;
|
|
|
|
case "WebNavigation:SetOriginAttributes":
|
|
|
|
this.setOriginAttributes(message.data.originAttributes);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:Reload":
|
2019-06-08 14:04:27 +03:00
|
|
|
this.reload(message.data.loadFlags);
|
2018-07-30 03:08:58 +03:00
|
|
|
break;
|
|
|
|
case "WebNavigation:Stop":
|
2019-06-08 14:04:27 +03:00
|
|
|
this.stop(message.data.loadFlags);
|
2018-07-30 03:08:58 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_wrapURIChangeCall(fn) {
|
|
|
|
try {
|
|
|
|
fn();
|
|
|
|
} finally {
|
2019-06-14 00:00:34 +03:00
|
|
|
this.mm.docShell
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIBrowserChild)
|
|
|
|
.notifyNavigationFinished();
|
2018-07-30 03:08:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 02:31:46 +03:00
|
|
|
goBack(params) {
|
2018-07-30 03:08:58 +03:00
|
|
|
if (this.webNavigation.canGoBack) {
|
2019-05-01 02:31:46 +03:00
|
|
|
this.mm.docShell.setCancelContentJSEpoch(params.cancelContentJSEpoch);
|
2018-07-30 03:08:58 +03:00
|
|
|
this._wrapURIChangeCall(() => this.webNavigation.goBack());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 02:31:46 +03:00
|
|
|
goForward(params) {
|
2018-07-30 03:08:58 +03:00
|
|
|
if (this.webNavigation.canGoForward) {
|
2019-05-01 02:31:46 +03:00
|
|
|
this.mm.docShell.setCancelContentJSEpoch(params.cancelContentJSEpoch);
|
2018-07-30 03:08:58 +03:00
|
|
|
this._wrapURIChangeCall(() => this.webNavigation.goForward());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 02:31:46 +03:00
|
|
|
gotoIndex(params) {
|
|
|
|
let { index, cancelContentJSEpoch } = params || {};
|
|
|
|
this.mm.docShell.setCancelContentJSEpoch(cancelContentJSEpoch);
|
2018-07-30 03:08:58 +03:00
|
|
|
this._wrapURIChangeCall(() => this.webNavigation.gotoIndex(index));
|
|
|
|
}
|
|
|
|
|
2019-02-22 11:19:26 +03:00
|
|
|
loadURI(params) {
|
|
|
|
let {
|
|
|
|
uri,
|
2019-06-08 14:04:27 +03:00
|
|
|
loadFlags,
|
2019-02-22 11:19:26 +03:00
|
|
|
referrerInfo,
|
|
|
|
postData,
|
|
|
|
headers,
|
|
|
|
baseURI,
|
|
|
|
triggeringPrincipal,
|
|
|
|
csp,
|
2019-05-01 02:31:46 +03:00
|
|
|
cancelContentJSEpoch,
|
2019-02-22 11:19:26 +03:00
|
|
|
} = params || {};
|
|
|
|
|
2018-07-30 03:08:58 +03:00
|
|
|
if (AppConstants.MOZ_CRASHREPORTER && CrashReporter.enabled) {
|
|
|
|
let annotation = uri;
|
|
|
|
try {
|
|
|
|
let url = Services.io.newURI(uri);
|
|
|
|
// If the current URI contains a username/password, remove it.
|
|
|
|
url = url
|
|
|
|
.mutate()
|
|
|
|
.setUserPass("")
|
|
|
|
.finalize();
|
|
|
|
annotation = url.spec;
|
|
|
|
} catch (ex) {
|
|
|
|
/* Ignore failures to parse and failures
|
|
|
|
on about: URIs. */
|
|
|
|
}
|
|
|
|
CrashReporter.annotateCrashReport("URL", annotation);
|
|
|
|
}
|
|
|
|
if (postData) {
|
2019-02-19 05:34:09 +03:00
|
|
|
postData = E10SUtils.makeInputStream(postData);
|
2019-07-05 12:04:56 +03:00
|
|
|
}
|
2018-07-30 03:08:58 +03:00
|
|
|
if (headers) {
|
2019-02-19 05:34:09 +03:00
|
|
|
headers = E10SUtils.makeInputStream(headers);
|
2019-07-05 12:04:56 +03:00
|
|
|
}
|
2018-07-30 03:08:58 +03:00
|
|
|
if (baseURI) {
|
|
|
|
baseURI = Services.io.newURI(baseURI);
|
2019-07-05 12:04:56 +03:00
|
|
|
}
|
2019-01-23 15:05:28 +03:00
|
|
|
this._assert(
|
|
|
|
triggeringPrincipal,
|
|
|
|
"We need a triggering principal to continue loading",
|
|
|
|
new Error().lineNumber
|
|
|
|
);
|
2019-02-21 21:12:35 +03:00
|
|
|
|
|
|
|
triggeringPrincipal = E10SUtils.deserializePrincipal(
|
|
|
|
triggeringPrincipal,
|
|
|
|
() => {
|
|
|
|
this._assert(
|
|
|
|
false,
|
|
|
|
"Unable to deserialize passed triggering principal",
|
|
|
|
new Error().lineNumber
|
|
|
|
);
|
|
|
|
return Services.scriptSecurityManager.getSystemPrincipal({});
|
|
|
|
}
|
|
|
|
);
|
2019-02-22 11:19:26 +03:00
|
|
|
if (csp) {
|
|
|
|
csp = E10SUtils.deserializeCSP(csp);
|
|
|
|
}
|
2019-01-23 15:05:28 +03:00
|
|
|
|
2019-01-11 14:44:20 +03:00
|
|
|
let loadURIOptions = {
|
|
|
|
triggeringPrincipal,
|
2019-02-22 11:19:26 +03:00
|
|
|
csp,
|
2019-06-08 14:04:27 +03:00
|
|
|
loadFlags,
|
2019-02-12 22:35:24 +03:00
|
|
|
referrerInfo: E10SUtils.deserializeReferrerInfo(referrerInfo),
|
2019-01-11 14:44:20 +03:00
|
|
|
postData,
|
|
|
|
headers,
|
|
|
|
baseURI,
|
|
|
|
};
|
2019-05-01 02:31:46 +03:00
|
|
|
this.mm.docShell.setCancelContentJSEpoch(cancelContentJSEpoch);
|
2018-07-30 03:08:58 +03:00
|
|
|
this._wrapURIChangeCall(() => {
|
2019-01-11 14:44:20 +03:00
|
|
|
return this.webNavigation.loadURI(uri, loadURIOptions);
|
2018-07-30 03:08:58 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-23 15:05:28 +03:00
|
|
|
_assert(condition, msg, line = 0) {
|
|
|
|
let debug = Cc["@mozilla.org/xpcom/debug;1"].getService(Ci.nsIDebug2);
|
|
|
|
if (!condition && debug.isDebugBuild) {
|
|
|
|
debug.warning(
|
|
|
|
`${msg} - ${new Error().stack}`,
|
|
|
|
"WebNavigationChild.js",
|
|
|
|
line
|
|
|
|
);
|
|
|
|
debug.abort("WebNavigationChild.js", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 03:08:58 +03:00
|
|
|
setOriginAttributes(originAttributes) {
|
|
|
|
if (originAttributes) {
|
|
|
|
this.webNavigation.setOriginAttributesBeforeLoading(originAttributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 14:04:27 +03:00
|
|
|
reload(loadFlags) {
|
|
|
|
this.webNavigation.reload(loadFlags);
|
2018-07-30 03:08:58 +03:00
|
|
|
}
|
|
|
|
|
2019-06-08 14:04:27 +03:00
|
|
|
stop(loadFlags) {
|
|
|
|
this.webNavigation.stop(loadFlags);
|
2018-07-30 03:08:58 +03:00
|
|
|
}
|
|
|
|
}
|