browser/modules/E10SUtils.jsm
author Brian Nicholson <bnicholson@mozilla.com>
Thu, 02 Oct 2014 09:48:50 -0700
changeset 208635 279afba13f4c109111417b3987205d6fe0f0eaed
parent 207247 bd3fa77c80f0e7544414550cda725dd352689c09
child 210418 4ab8a1de595ba8b285e4f40b66e8d591bc0d8752
permissions -rw-r--r--
Bug 1076438 - Add tracking ID to SuggestedSites API. r=lucasr

/* 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";

this.EXPORTED_SYMBOLS = ["E10SUtils"];

const {interfaces: Ci, utils: Cu, classes: Cc} = Components;

Cu.import("resource://gre/modules/Services.jsm");

this.E10SUtils = {
  shouldBrowserBeRemote: function(aURL) {
    // loadURI in browser.xml treats null as about:blank
    if (!aURL)
      aURL = "about:blank";

    if (aURL.startsWith("about:") &&
        aURL.toLowerCase() != "about:home" &&
        aURL.toLowerCase() != "about:blank" &&
        !aURL.toLowerCase().startsWith("about:neterror")) {
      return false;
    }

    return true;
  },

  shouldLoadURI: function(aDocShell, aURI, aReferrer) {
    // about:blank is the initial document and can load anywhere
    if (aURI.spec == "about:blank")
      return true;

    // Inner frames should always load in the current process
    if (aDocShell.QueryInterface(Ci.nsIDocShellTreeItem).sameTypeParent)
      return true;

    // If the URI can be loaded in the current process then continue
    let isRemote = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
    if (this.shouldBrowserBeRemote(aURI.spec) == isRemote)
      return true;

    return false;
  },

  redirectLoad: function(aDocShell, aURI, aReferrer) {
    // Retarget the load to the correct process
    let messageManager = aDocShell.QueryInterface(Ci.nsIInterfaceRequestor)
                                  .getInterface(Ci.nsIContentFrameMessageManager);
    let sessionHistory = aDocShell.getInterface(Ci.nsIWebNavigation).sessionHistory;

    messageManager.sendAsyncMessage("Browser:LoadURI", {
      uri: aURI.spec,
      referrer: aReferrer ? aReferrer.spec : null,
      historyIndex: sessionHistory.requestedIndex,
    });
    return false;
  },
};