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"];
|
|
|
|
|
2018-07-30 22:55:22 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
|
2018-07-30 03:08:58 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
ChromeUtils.defineModuleGetter(this, "AppConstants",
|
|
|
|
"resource://gre/modules/AppConstants.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "Utils",
|
|
|
|
"resource://gre/modules/sessionstore/Utils.jsm");
|
|
|
|
|
|
|
|
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":
|
|
|
|
this.goBack();
|
|
|
|
break;
|
|
|
|
case "WebNavigation:GoForward":
|
|
|
|
this.goForward();
|
|
|
|
break;
|
|
|
|
case "WebNavigation:GotoIndex":
|
|
|
|
this.gotoIndex(message.data.index);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:LoadURI":
|
|
|
|
let histogram = Services.telemetry.getKeyedHistogramById("FX_TAB_REMOTE_NAVIGATION_DELAY_MS");
|
|
|
|
histogram.add("WebNavigation:LoadURI",
|
|
|
|
Services.telemetry.msSystemNow() - message.data.requestTime);
|
|
|
|
|
|
|
|
this.loadURI(message.data.uri, message.data.flags,
|
|
|
|
message.data.referrer, message.data.referrerPolicy,
|
|
|
|
message.data.postData, message.data.headers,
|
|
|
|
message.data.baseURI, message.data.triggeringPrincipal);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:SetOriginAttributes":
|
|
|
|
this.setOriginAttributes(message.data.originAttributes);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:Reload":
|
|
|
|
this.reload(message.data.flags);
|
|
|
|
break;
|
|
|
|
case "WebNavigation:Stop":
|
|
|
|
this.stop(message.data.flags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_wrapURIChangeCall(fn) {
|
2018-07-30 22:55:22 +03:00
|
|
|
this.mm.WebProgress.inLoadURI = true;
|
2018-07-30 03:08:58 +03:00
|
|
|
try {
|
|
|
|
fn();
|
|
|
|
} finally {
|
2018-07-30 22:55:22 +03:00
|
|
|
this.mm.WebProgress.inLoadURI = false;
|
2018-07-30 03:08:58 +03:00
|
|
|
this.mm.WebProgress.sendLoadCallResult();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
goBack() {
|
|
|
|
if (this.webNavigation.canGoBack) {
|
|
|
|
this._wrapURIChangeCall(() => this.webNavigation.goBack());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
goForward() {
|
|
|
|
if (this.webNavigation.canGoForward) {
|
|
|
|
this._wrapURIChangeCall(() => this.webNavigation.goForward());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gotoIndex(index) {
|
|
|
|
this._wrapURIChangeCall(() => this.webNavigation.gotoIndex(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
loadURI(uri, flags, referrer, referrerPolicy, postData, headers, baseURI, triggeringPrincipal) {
|
|
|
|
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 (referrer)
|
|
|
|
referrer = Services.io.newURI(referrer);
|
|
|
|
if (postData)
|
|
|
|
postData = Utils.makeInputStream(postData);
|
|
|
|
if (headers)
|
|
|
|
headers = Utils.makeInputStream(headers);
|
|
|
|
if (baseURI)
|
|
|
|
baseURI = Services.io.newURI(baseURI);
|
2019-01-23 15:05:28 +03:00
|
|
|
this._assert(triggeringPrincipal, "We need a triggering principal to continue loading", new Error().lineNumber);
|
2018-07-30 03:08:58 +03:00
|
|
|
if (triggeringPrincipal)
|
|
|
|
triggeringPrincipal = Utils.deserializePrincipal(triggeringPrincipal);
|
2019-01-23 15:05:28 +03:00
|
|
|
this._assert(triggeringPrincipal, "Unable to deserialize passed triggering principal", new Error().lineNumber);
|
2018-08-29 17:49:12 +03:00
|
|
|
if (!triggeringPrincipal) {
|
2019-01-23 15:05:28 +03:00
|
|
|
triggeringPrincipal = Services.scriptSecurityManager.getSystemPrincipal({});
|
2018-08-29 17:49:12 +03:00
|
|
|
}
|
2019-01-23 15:05:28 +03:00
|
|
|
|
2019-01-11 14:44:20 +03:00
|
|
|
let loadURIOptions = {
|
|
|
|
triggeringPrincipal,
|
|
|
|
loadFlags: flags,
|
|
|
|
referrerURI: referrer,
|
|
|
|
referrerPolicy,
|
|
|
|
postData,
|
|
|
|
headers,
|
|
|
|
baseURI,
|
|
|
|
};
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reload(flags) {
|
|
|
|
this.webNavigation.reload(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
stop(flags) {
|
|
|
|
this.webNavigation.stop(flags);
|
|
|
|
}
|
|
|
|
}
|