tor-browser

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

PresentationConnection_onclose-manual.https.html (2839B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Closing a PresentationConnection</title>
      4 <link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs">
      5 <link rel="help" href="https://w3c.github.io/presentation-api/#closing-a-presentationconnection">
      6 <script src="common.js"></script>
      7 <script src="support/stash.js"></script>
      8 <style>
      9 iframe { display: none; }
     10 </style>
     11 
     12 <p>Click the button below and select the available presentation display, to start the manual test.</p>
     13 <button id="presentBtn" disabled>Start Presentation Test</button>
     14 <iframe id="childFrame" sandbox="allow-scripts allow-presentation" src="support/iframe.html"></iframe>
     15 
     16 <script>
     17  let connection;
     18  const presentBtn = document.getElementById('presentBtn');
     19  const child = document.getElementById('childFrame');
     20 
     21  child.onload = () => { presentBtn.disabled = false; };
     22 
     23  presentBtn.onclick = () => {
     24    presentBtn.disabled = true;
     25    const stash = new Stash(stashIds.toController, stashIds.toReceiver);
     26    const request = new PresentationRequest('support/PresentationConnection_onclose_receiving-ua.html');
     27 
     28    return request.start().then(c => {
     29      connection = c;
     30      return stash.init();
     31    }).then(() => {
     32      return stash.receive();
     33    }).then(data => {
     34      const result = JSON.parse(data);
     35      if (result.type === 'ok') {
     36        return request.reconnect(connection.id).then(() => data);
     37      }
     38      else
     39        return data;
     40    }).then(data => {
     41      const result = JSON.parse(data);
     42      if (result.type === 'ok') {
     43        connection.onclose = null;
     44        connection.close();
     45        return stash.receive();
     46      }
     47      else
     48        return data;
     49    }).then(data => {
     50      const result = JSON.parse(data);
     51      if (result.type === 'ok') {
     52        child.contentWindow.postMessage({ type: 'connect', id: connection.id, url: connection.url }, '*');
     53        return stash.receive();
     54      }
     55      else
     56        return data;
     57    }).then(data => {
     58      const result = JSON.parse(data);
     59      if (result.type === 'ok') {
     60        child.parentNode.removeChild(child);
     61        return stash.receive();
     62      }
     63      else
     64        return data;
     65    }).then(result => {
     66      const json = JSON.parse(result);
     67      // notify receiver's results of a parent window (e.g. test runner)
     68      if (window.opener && 'completion_callback' in window.opener) {
     69        window.opener.completion_callback(json.tests, json.status);
     70      }
     71      // display receiver's results as HTML
     72      const log = document.createElement('div');
     73      log.id = 'log';
     74      log.innerHTML = json.log;
     75      document.body.appendChild(log);
     76 
     77      connection.onconnect = () => { connection.terminate(); };
     78      if (connection.state === 'closed')
     79        request.reconnect(connection.id);
     80      else
     81        connection.terminate();
     82    });
     83  };
     84 </script>