File: RemoteWebNavigation.jsm

package info (click to toggle)
thunderbird 1%3A68.10.0-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,754,812 kB
  • sloc: cpp: 5,411,679; javascript: 4,161,772; ansic: 2,639,702; python: 763,064; java: 346,606; xml: 266,623; asm: 265,884; sh: 117,270; lisp: 41,340; makefile: 23,560; perl: 18,042; objc: 5,277; yacc: 1,778; ada: 1,681; pascal: 1,673; lex: 1,417; cs: 879; exp: 527; awk: 495; php: 436; ruby: 221; sed: 69; csh: 27
file content (213 lines) | stat: -rw-r--r-- 6,647 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// -*- 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/.

ChromeUtils.defineModuleGetter(
  this,
  "Services",
  "resource://gre/modules/Services.jsm"
);
ChromeUtils.defineModuleGetter(
  this,
  "Utils",
  "resource://gre/modules/sessionstore/Utils.jsm"
);
ChromeUtils.defineModuleGetter(
  this,
  "PrivateBrowsingUtils",
  "resource://gre/modules/PrivateBrowsingUtils.jsm"
);
ChromeUtils.defineModuleGetter(
  this,
  "E10SUtils",
  "resource://gre/modules/E10SUtils.jsm"
);

function makeURI(url) {
  return Services.io.newURI(url);
}

function RemoteWebNavigation() {
  this.wrappedJSObject = this;
  this._cancelContentJSEpoch = 1;
}

RemoteWebNavigation.prototype = {
  classDescription: "nsIWebNavigation for remote browsers",
  classID: Components.ID("{4b56964e-cdf3-4bb8-830c-0e2dad3f4ebd}"),
  contractID: "@mozilla.org/remote-web-navigation;1",

  QueryInterface: ChromeUtils.generateQI([Ci.nsIWebNavigation]),

  swapBrowser(aBrowser) {
    this._browser = aBrowser;
  },

  LOAD_FLAGS_MASK: 65535,
  LOAD_FLAGS_NONE: 0,
  LOAD_FLAGS_IS_REFRESH: 16,
  LOAD_FLAGS_IS_LINK: 32,
  LOAD_FLAGS_BYPASS_HISTORY: 64,
  LOAD_FLAGS_REPLACE_HISTORY: 128,
  LOAD_FLAGS_BYPASS_CACHE: 256,
  LOAD_FLAGS_BYPASS_PROXY: 512,
  LOAD_FLAGS_CHARSET_CHANGE: 1024,
  LOAD_FLAGS_STOP_CONTENT: 2048,
  LOAD_FLAGS_FROM_EXTERNAL: 4096,
  LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP: 8192,
  LOAD_FLAGS_FIRST_LOAD: 16384,
  LOAD_FLAGS_ALLOW_POPUPS: 32768,
  LOAD_FLAGS_BYPASS_CLASSIFIER: 65536,
  LOAD_FLAGS_FORCE_ALLOW_COOKIES: 131072,

  STOP_NETWORK: 1,
  STOP_CONTENT: 2,
  STOP_ALL: 3,

  canGoBack: false,
  canGoForward: false,
  goBack() {
    let cancelContentJSEpoch = this._cancelContentJSEpoch++;
    this._browser.frameLoader.remoteTab.maybeCancelContentJSExecution(
      Ci.nsIRemoteTab.NAVIGATE_BACK,
      { epoch: cancelContentJSEpoch }
    );
    this._sendMessage("WebNavigation:GoBack", { cancelContentJSEpoch });
  },
  goForward() {
    let cancelContentJSEpoch = this._cancelContentJSEpoch++;
    this._browser.frameLoader.remoteTab.maybeCancelContentJSExecution(
      Ci.nsIRemoteTab.NAVIGATE_FORWARD,
      { epoch: cancelContentJSEpoch }
    );
    this._sendMessage("WebNavigation:GoForward", { cancelContentJSEpoch });
  },
  gotoIndex(aIndex) {
    let cancelContentJSEpoch = this._cancelContentJSEpoch++;
    this._browser.frameLoader.remoteTab.maybeCancelContentJSExecution(
      Ci.nsIRemoteTab.NAVIGATE_INDEX,
      { index: aIndex, epoch: cancelContentJSEpoch }
    );
    this._sendMessage("WebNavigation:GotoIndex", {
      index: aIndex,
      cancelContentJSEpoch,
    });
  },
  loadURI(aURI, aLoadURIOptions) {
    let uri;

    // We know the url is going to be loaded, let's start requesting network
    // connection before the content process asks.
    // Note that we might have already setup the speculative connection in some
    // cases, especially when the url is from location bar or its popup menu.
    if (aURI.startsWith("http:") || aURI.startsWith("https:")) {
      try {
        uri = makeURI(aURI);
        let principal = aLoadURIOptions.triggeringPrincipal;
        // We usually have a triggeringPrincipal assigned, but in case we
        // don't have one or if it's a SystemPrincipal, let's create it with OA
        // inferred from the current context.
        if (!principal || principal.isSystemPrincipal) {
          let attrs = {
            userContextId: this._browser.getAttribute("usercontextid") || 0,
            privateBrowsingId: PrivateBrowsingUtils.isBrowserPrivate(
              this._browser
            )
              ? 1
              : 0,
          };
          principal = Services.scriptSecurityManager.createCodebasePrincipal(
            uri,
            attrs
          );
        }
        Services.io.speculativeConnect(uri, principal, null);
      } catch (ex) {
        // Can't setup speculative connection for this uri string for some
        // reason (such as failing to parse the URI), just ignore it.
      }
    }

    let cancelContentJSEpoch = this._cancelContentJSEpoch++;
    this._browser.frameLoader.remoteTab.maybeCancelContentJSExecution(
      Ci.nsIRemoteTab.NAVIGATE_URL,
      { uri, epoch: cancelContentJSEpoch }
    );
    this._sendMessage("WebNavigation:LoadURI", {
      uri: aURI,
      flags: aLoadURIOptions.loadFlags,
      referrerInfo: E10SUtils.serializeReferrerInfo(
        aLoadURIOptions.referrerInfo
      ),
      postData: aLoadURIOptions.postData
        ? Utils.serializeInputStream(aLoadURIOptions.postData)
        : null,
      headers: aLoadURIOptions.headers
        ? Utils.serializeInputStream(aLoadURIOptions.headers)
        : null,
      baseURI: aLoadURIOptions.baseURI ? aLoadURIOptions.baseURI.spec : null,
      triggeringPrincipal: E10SUtils.serializePrincipal(
        aLoadURIOptions.triggeringPrincipal ||
          Services.scriptSecurityManager.createNullPrincipal({})
      ),
      csp: aLoadURIOptions.csp
        ? E10SUtils.serializeCSP(aLoadURIOptions.csp)
        : null,
      requestTime: Services.telemetry.msSystemNow(),
      cancelContentJSEpoch,
    });
  },
  setOriginAttributesBeforeLoading(aOriginAttributes) {
    this._sendMessage("WebNavigation:SetOriginAttributes", {
      originAttributes: aOriginAttributes,
    });
  },
  reload(aReloadFlags) {
    this._sendMessage("WebNavigation:Reload", { flags: aReloadFlags });
  },
  stop(aStopFlags) {
    this._sendMessage("WebNavigation:Stop", { flags: aStopFlags });
  },

  get document() {
    return this._browser.contentDocument;
  },

  _currentURI: null,
  get currentURI() {
    if (!this._currentURI) {
      this._currentURI = makeURI("about:blank");
    }

    return this._currentURI;
  },
  set currentURI(aURI) {
    // Bug 1498600 verify usages of systemPrincipal here
    let loadURIOptions = {
      triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
    };
    this.loadURI(aURI.spec, loadURIOptions);
  },

  referringURI: null,

  // Bug 1233803 - accessing the sessionHistory of remote browsers should be
  // done in content scripts.
  get sessionHistory() {
    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
  },
  set sessionHistory(aValue) {
    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
  },

  _sendMessage(aMessage, aData) {
    try {
      this._browser.messageManager.sendAsyncMessage(aMessage, aData);
    } catch (e) {
      Cu.reportError(e);
    }
  },
};

var EXPORTED_SYMBOLS = ["RemoteWebNavigation"];