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
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161

content / test / data / filesystem_url_navigations.html [blame]

<html>
<body onload="setupHandlers()">

<h3>HTML mimetype</h3>

<a download id="download-link"><a download link></a>
<br><br>
<button id='navigate-top-frame-to-html'>
  Navigate top frame to filesystem URL HTML
</button>
<br>
<button id='window-open-html'>
  Open new window with a filesystem URL HTML
</button>
<button id='window-open-redirect'>
  Open new window with a redirect to filesystem URL
</button>
<br>
<form method="post" id="form-post-to-html-form">
  <input type=submit id='form-post-to-html'
      value="Submit form to filesystem URL HTML">
</form>

<h3>octet-stream mimetype</h3>

<button id='navigate-top-frame-to-octetstream'>
  Navigate top frame to filesystem URL octet-stream
</button>
<br>
<button id='window-open-octetstream'>
  Open new window with a filesystem URL octet-stream
</button>
<form method="post" id="form-post-to-octetstream-form">
  <input type=submit id="form-post-to-octetstream"
      value="Submit form to filesystem URL octet-stream">
</form>
<h3>PDF mimetype</h3>

<button id='navigate-top-frame-to-pdf'>
  Navigate top frame to filesystem URL PDF
</button>
<br>
<button id='window-open-pdf'>
  Open new window with a filesystem URL PDF
</button>
<br>
<form method="post" id="form-post-to-pdf-form">
  <input type=submit id='form-post-to-pdf'
      value="Submit form to filesystem URL PDF">
</form>

<h3>Unknown mimetype</h3>

<button id='navigate-top-frame-to-unknown-mimetype'>
  Navigate top frame to filesystem URL unknown mimetype
</button>
<br>
<button id="window-open-unknown-mimetype">
  Open new window with a filesystem URL unknown mimetype
</button>
<form method="post" id="form-post-to-unknown-mimetype-form">
  <input type=submit id='form-post-to-unknown-mimetype'
         value='Submit form to filesystem URL unknown mimetype'>
</form>

<script>
var PDF =
  "%PDF-1.7\n" +
  "1 0 obj << /Type /Page /Parent 3 0 R /Resources 5 0 R /Contents 2 0 R >>\n" +
  "endobj\n" +
  "2 0 obj << /Length 51 >>\n" +
  " stream BT\n" +
  " /F1 12 Tf\n" +
  " 1 0 0 1 100 20 Tm\n" +
  " (Hello World)Tj\n" +
  " ET\n" +
  " endstream\n" +
  "endobj\n" +
  "3 0 obj << /Type /Pages /Kids [ 1 0 R ] /Count 1 /MediaBox [ 0 0 300 50] >>\n" +
  "endobj\n" +
  "4 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont/Arial >>\n" +
  "endobj\n" +
  "5 0 obj << /ProcSet[/PDF/Text] /Font <</F1 4 0 R >> >>\n" +
  "endobj\n" +
  "6 0 obj << /Type /Catalog /Pages 3 0 R >>\n" +
  "endobj\n" +
  "trailer << /Root 6 0 R >>";

function setupHandlers() {
  window.webkitRequestFileSystem(window.TEMPORARY, 1024, fs => {
    // HTML mime type:
    fs.root.getFile('test.html', {create: true}, entry => {
      entry.createWriter(w => {
        w.write(new Blob([
            "NAVIGATION_SUCCESSFUL" +
            "<script" + ">console.log('NAVIGATION_SUCCESSFUL')<" + "/script>"],
            {type: "text/html"}));
      });
      document.getElementById("download-link").href = entry.toURL();
      document.getElementById("navigate-top-frame-to-html").onclick = function() {
        top.location.href = entry.toURL();
      };
      document.getElementById("window-open-html").onclick = function() {
        window.open(entry.toURL());
      };
      document.getElementById("window-open-redirect").onclick = function() {
        window.open("/server-redirect?" + entry.toURL());
      };
      document.getElementById("form-post-to-html-form").action = entry.toURL();

      // PDF:
      fs.root.getFile('test.pdf', {create: true}, entry => {
        entry.createWriter(w => {
          var blob = new Blob([PDF], {type: "application/pdf"});
          w.write(blob);
        });
        document.getElementById("navigate-top-frame-to-pdf").onclick = function() {
          top.location.href = entry.toURL();
        };
        document.getElementById("window-open-pdf").onclick = function() {
          window.open(entry.toURL());
        };
        document.getElementById("form-post-to-pdf-form").action = entry.toURL();

        // Binary mime type:
        fs.root.getFile('test.binary', {create: true}, entry => {
          entry.createWriter(w => {
            w.write(new Blob(["testdata"], {type: "application/octet-stream"}));
          });
          document.getElementById("navigate-top-frame-to-octetstream").onclick = function() {
            top.location.href = entry.toURL();
          };
          document.getElementById("window-open-octetstream").onclick = function() {
            window.open(entry.toURL());
          };
          document.getElementById("form-post-to-octetstream-form").action = entry.toURL();

          // Unknown mime type:
          fs.root.getFile('test.unknown', {create: true}, entry => {
            entry.createWriter(w => {
              w.write(new Blob(["test"], {type: "unknown/mimetype"}));
            });
            document.getElementById("navigate-top-frame-to-unknown-mimetype").onclick = function() {
              top.location.href = entry.toURL();
            };
            document.getElementById("window-open-unknown-mimetype").onclick = function() {
              window.open(entry.toURL());
            };
            document.getElementById("form-post-to-unknown-mimetype-form").action = entry.toURL();

            if (window.domAutomationController)
              window.domAutomationController.send("READY");
          });
        });
      });
    });
  });
}
</script>
</body>
</html>