tor-browser

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

file_postMessage_parent.html (1798B)


      1 <!doctype html>
      2 <script>
      3  dump("Content running top level script " + window.location.href + "\n");
      4 
      5  var winID = SpecialPowers.wrap(this).windowGlobalChild.innerWindowId;
      6 
      7  var observer = {
      8    observe(subject) {
      9      var currID = SpecialPowers.wrap(subject).QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
     10      if (currID != winID) {
     11        return;
     12      }
     13      // We should be able to wrap the inner window when the outer
     14      // window has navigated out of process.
     15      SpecialPowers.Cu.getGlobalForObject({});
     16 
     17      SpecialPowers.removeObserver(observer, "inner-window-nuked");
     18    }
     19  };
     20  SpecialPowers.addObserver(observer, "inner-window-nuked");
     21 
     22  // Unfortunately, we don't currently fire the onload event on a remote iframe,
     23  // so we can't listen for the load event directly on the iframe. Instead, we
     24  // postMessage from the iframe when the load event would be fired.
     25  window.addEventListener("load", function onload() {
     26    dump("Content got load of " + window.location.href + "\n");
     27    if (window.parent) {
     28      window.parent.postMessage({
     29        event: "load",
     30        location: window.location.href,
     31      }, "*");
     32    }
     33 
     34    let h1 = document.createElement("h1");
     35    h1.textContent = window.location.href;
     36    document.body.appendChild(h1);
     37  }, { once: true });
     38 
     39  // In addition, we listen to the message event to trigger navigations of
     40  // ourself when requested, as we don't fully support our embedder triggering
     41  // us being navigated yet for Totally Not Buggy Reasons.
     42  window.addEventListener("message", function onmessage(event) {
     43    dump("Content got event " + window.location.href + " " + JSON.stringify(event.data) + "\n");
     44    if (event.data.action === "navigate") {
     45      window.location = event.data.location;
     46    }
     47  });
     48 </script>