tor-browser

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

partitioned-estimate-usage-details-caches-helper-frame.html (2200B)


      1 <!DOCTYPE html>
      2 <meta name=help href="https://privacycg.github.io/storage-partitioning/">
      3 <title>Helper frame</title>
      4 
      5 <!-- This resource file is used in the WPT at:
      6     wpt/storage/partitioned-estimate-usage-details-caches.tentative.https.sub.html
      7     A full list of the test steps referenced here are defined in that WPT -->
      8 
      9 <script>
     10  // Helper function to obtain cache usage details for both the same-partition
     11  // iframe and cross-partition iframe.
     12  const usageDetails = async () =>
     13    (await navigator.storage.estimate()).usageDetails.caches || 0;
     14 
     15  // Define test variables.
     16  let details = {};
     17 
     18  // Step 5: Our same-partition iframe intercepts the "get-details" postMessage,
     19  // obtains the cache usage details available to the iframe, and postMessages
     20  // the usage back to the test window.
     21  window.addEventListener("message", async event => {
     22    if (event.data === "get-details") {
     23      details.source = "same-site";
     24      details.init = await usageDetails();
     25      event.source.postMessage(details, event.source.origin);
     26    }
     27  });
     28 
     29  // Step 8: Once created and loaded, our cross-partition iframe has an on-load
     30  // listener that is triggered. To check that our script is executing in
     31  // the cross-partition iframe (and not the same-partition iframe), we check
     32  // that our parent has a valid opener value.
     33  window.addEventListener("load", async () => {
     34    if (parent.opener) {
     35      // Step 9: Then, our cross-partition iframe obtains the cache usage
     36      // details available to it and postMessages the usage back to the test
     37      // window.
     38      details.source = "cross-site";
     39      details.init = await usageDetails();
     40      parent.opener.postMessage(details, parent.opener.origin);
     41    }
     42  });
     43 
     44  // Step 1: Notify our parent test window that the same-partition iframe
     45  // has been created. (Note: this script is shared between both the same-
     46  // partition iframe and the cross-partition iframe, but is only intercepted
     47  // by the test window in the case of the same-partition iframe). This
     48  // postMessage alerts our test window that it can begin recording
     49  // cache usage.
     50  window.parent.postMessage("iframe-is-ready", window.parent.origin);
     51 </script>