summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-locks/resources/iframe-parent.html
blob: ec63045b4a0561d4119e6890195e15bc3b6410af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<title>Helper IFrame</title>
<script>
'use strict';

async function onLoad() {
  // Nested Step 5: wpt/web-locks/partitioned-web-locks.tentative.https.html
  // Load the innermost child iframe and its content.
  const params = new URLSearchParams(self.location.search);
  const frame = document.createElement('iframe');
  frame.src = params.get('target');
  document.body.appendChild(frame);

  self.addEventListener('message', evt => {
    // Nested Step 6: wpt/web-locks/partitioned-web-locks.tentative.https.html
    // Pass any operations request messages to the
    // innermost child iframe.
    if (evt.data.op){
      // Ensure that the iframe has loaded before passing
      // on the message.
      frame.addEventListener('load', function(){
        frame.contentWindow.postMessage(evt.data, '*');
      });
    }
    // Nested Step 8: wpt/web-locks/partitioned-web-locks.tentative.https.html
    else {
      // All other messages, should be sent back to the
      // top-level site.
      if (self.opener)
        self.opener.postMessage(evt.data, '*');
      else
        self.top.postMessage(evt.data, '*');
    }
  });
}
self.addEventListener('load', onLoad);
</script>