1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 var EXPORTED_SYMBOLS = ["WebNavigationChild"];
9 const {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
10 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
11 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
13 ChromeUtils.defineModuleGetter(this, "AppConstants",
14 "resource://gre/modules/AppConstants.jsm");
15 ChromeUtils.defineModuleGetter(this, "E10SUtils",
16 "resource://gre/modules/E10SUtils.jsm");
18 XPCOMUtils.defineLazyServiceGetter(this, "CrashReporter",
19 "@mozilla.org/xre/app-info;1",
22 class WebNavigationChild extends ActorChild {
24 return this.mm.docShell.QueryInterface(Ci.nsIWebNavigation);
27 receiveMessage(message) {
28 switch (message.name) {
29 case "WebNavigation:GoBack":
32 case "WebNavigation:GoForward":
35 case "WebNavigation:GotoIndex":
36 this.gotoIndex(message.data.index);
38 case "WebNavigation:LoadURI":
39 let histogram = Services.telemetry.getKeyedHistogramById("FX_TAB_REMOTE_NAVIGATION_DELAY_MS");
40 histogram.add("WebNavigation:LoadURI",
41 Services.telemetry.msSystemNow() - message.data.requestTime);
43 this.loadURI(message.data);
46 case "WebNavigation:SetOriginAttributes":
47 this.setOriginAttributes(message.data.originAttributes);
49 case "WebNavigation:Reload":
50 this.reload(message.data.flags);
52 case "WebNavigation:Stop":
53 this.stop(message.data.flags);
58 _wrapURIChangeCall(fn) {
59 this.mm.WebProgress.inLoadURI = true;
63 this.mm.WebProgress.inLoadURI = false;
64 this.mm.WebProgress.sendLoadCallResult();
69 if (this.webNavigation.canGoBack) {
70 this._wrapURIChangeCall(() => this.webNavigation.goBack());
75 if (this.webNavigation.canGoForward) {
76 this._wrapURIChangeCall(() => this.webNavigation.goForward());
81 this._wrapURIChangeCall(() => this.webNavigation.gotoIndex(index));
96 if (AppConstants.MOZ_CRASHREPORTER && CrashReporter.enabled) {
99 let url = Services.io.newURI(uri);
100 // If the current URI contains a username/password, remove it.
104 annotation = url.spec;
105 } catch (ex) { /* Ignore failures to parse and failures
107 CrashReporter.annotateCrashReport("URL", annotation);
110 postData = E10SUtils.makeInputStream(postData);
112 headers = E10SUtils.makeInputStream(headers);
114 baseURI = Services.io.newURI(baseURI);
115 this._assert(triggeringPrincipal, "We need a triggering principal to continue loading", new Error().lineNumber);
117 triggeringPrincipal = E10SUtils.deserializePrincipal(triggeringPrincipal, () => {
118 this._assert(false, "Unable to deserialize passed triggering principal", new Error().lineNumber);
119 return Services.scriptSecurityManager.getSystemPrincipal({});
122 csp = E10SUtils.deserializeCSP(csp);
125 let loadURIOptions = {
129 referrerInfo: E10SUtils.deserializeReferrerInfo(referrerInfo),
134 this._wrapURIChangeCall(() => {
135 return this.webNavigation.loadURI(uri, loadURIOptions);
139 _assert(condition, msg, line = 0) {
140 let debug = Cc["@mozilla.org/xpcom/debug;1"].getService(Ci.nsIDebug2);
141 if (!condition && debug.isDebugBuild) {
142 debug.warning(`${msg} - ${new Error().stack}`, "WebNavigationChild.js", line);
143 debug.abort("WebNavigationChild.js", line);
147 setOriginAttributes(originAttributes) {
148 if (originAttributes) {
149 this.webNavigation.setOriginAttributesBeforeLoading(originAttributes);
154 this.webNavigation.reload(flags);
158 this.webNavigation.stop(flags);