tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

head.js (2888B)


      1 const OOP_BASE_PAGE_URI =
      2  "https://example.com/browser/browser/base/content/test/outOfProcess/file_base.html";
      3 
      4 // The number of frames and subframes that exist for the basic OOP test. If frames are
      5 // modified within file_base.html, update this value.
      6 const TOTAL_FRAME_COUNT = 8;
      7 
      8 // The frames are assigned different colors based on their process ids. If you add a
      9 // frame you might need to add more colors to this list.
     10 const FRAME_COLORS = ["white", "seashell", "lightcyan", "palegreen"];
     11 
     12 /**
     13 * Set up a set of child frames for the given browser for testing
     14 * out of process frames. 'OOP_BASE_PAGE_URI' is the base page and subframes
     15 * contain pages from the same or other domains.
     16 *
     17 * @param browser browser containing frame hierarchy to set up
     18 * @param insertHTML HTML or function that returns what to insert into each frame
     19 * @returns array of all browsing contexts in depth-first order
     20 *
     21 * This function adds a browsing context and process id label to each
     22 * child subframe. It also sets the background color of each frame to
     23 * different colors based on the process id. The browser_basic_outofprocess.js
     24 * test verifies these colors to ensure that the frame/process hierarchy
     25 * has been set up as expected. Colors are used to help people visualize
     26 * the process setup.
     27 *
     28 * The insertHTML argument may be either a fixed string of HTML to insert
     29 * into each subframe, or a function that returns the string to insert. The
     30 * function takes one argument, the browsing context being processed.
     31 */
     32 async function initChildFrames(browser, insertHTML) {
     33  let colors = FRAME_COLORS.slice();
     34  let colorMap = new Map();
     35 
     36  let browsingContexts = [];
     37 
     38  async function processBC(bc) {
     39    browsingContexts.push(bc);
     40 
     41    let pid = bc.currentWindowGlobal.osPid;
     42    let ident = "BrowsingContext: " + bc.id + "\nProcess: " + pid;
     43 
     44    let color = colorMap.get(pid);
     45    if (!color) {
     46      if (!colors.length) {
     47        ok(false, "ran out of available colors");
     48      }
     49 
     50      color = colors.shift();
     51      colorMap.set(pid, color);
     52    }
     53 
     54    let insertHTMLString = insertHTML;
     55    if (typeof insertHTML == "function") {
     56      insertHTMLString = insertHTML(bc);
     57    }
     58 
     59    await SpecialPowers.spawn(
     60      bc,
     61      [ident, color, insertHTMLString],
     62      (identChild, colorChild, insertHTMLChild) => {
     63        let root = content.document.documentElement;
     64        root.style = "background-color: " + colorChild;
     65 
     66        let pre = content.document.createElement("pre");
     67        pre.textContent = identChild;
     68        root.insertBefore(pre, root.firstChild);
     69 
     70        if (insertHTMLChild) {
     71          content.document.getElementById("insertPoint").innerHTML =
     72            insertHTMLChild;
     73        }
     74      }
     75    );
     76 
     77    for (let childBC of bc.children) {
     78      await processBC(childBC);
     79    }
     80  }
     81  await processBC(browser.browsingContext);
     82 
     83  return browsingContexts;
     84 }