browser/modules/E10SUtils.jsm
author Heiher <r@hev.cc>
Thu, 22 Jan 2015 07:50:00 -0500
changeset 225555 11540adce3b616c36314a7d278deed6c73fdc68a
parent 213080 8c589a6d637e7cad54652f03cbf87f978927fa39
child 227327 580a54390e831000299c9a4038008947030a3165
permissions -rw-r--r--
Bug 1057082 - MIPS changes for ProfilingFrameIterator JitFrame support. r=nbp

/* 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") &&
        !aURL.toLowerCase().startsWith("about:certerror")) {
      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", {
      loadOptions: {
        uri: aURI.spec,
        flags: Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
        referrer: aReferrer ? aReferrer.spec : null,
      },
      historyIndex: sessionHistory.requestedIndex,
    });
    return false;
  },
};