Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 {% set title = 'Isolate Server' %} | 1 {% set title = 'Isolate Server' %} |
| 2 {% extends "isolate/base.html" %} | 2 {% extends "isolate/base.html" %} |
| 3 | 3 |
| 4 | 4 |
| 5 {% block headers %} | 5 {% block headers %} |
| 6 <style> | 6 <style> |
| 7 html, body { | 7 html, body { |
| 8 height: 100%; | 8 height: 95%; |
| 9 margin: 0; | 9 margin: 0; |
| 10 width: 100%; | 10 width: 100%; |
| 11 } | 11 } |
| 12 div.use_all_space { | 12 div.use_all_space { |
| 13 margin: 0; | 13 margin: 0; |
| 14 overflow-y: hidden; | 14 overflow-y: hidden; |
| 15 padding: 0; | 15 padding: 0; |
| 16 width: 100%; | 16 width: 100%; |
| 17 } | 17 } |
| 18 .monospace { | 18 .monospace { |
| 19 font-family: monospace; | 19 font-family: monospace; |
| 20 white-space: pre-wrap; | 20 white-space: pre-wrap; |
| 21 } | 21 } |
| 22 iframe.use_all_space { | 22 iframe.use_all_space { |
| 23 margin: 0; | 23 margin: 0; |
| 24 overflow-y: hidden; | 24 overflow-y: hidden; |
| 25 padding: 0; | 25 padding: 0; |
| 26 width: 100%; | 26 width: 100%; |
| 27 min-height: 80%; | |
| 27 } | 28 } |
| 28 </style> | 29 </style> |
| 29 | 30 |
| 30 | |
| 31 {# | |
| 32 TODO(maruel): Reenable once Web UI authentication is switched to OAuth2. | |
| 33 <script type="text/javascript" src="third_party/pako/pako-0.2.3.min.js"> | |
| 34 </script> | |
| 35 <script> | |
| 36 if (typeof String.prototype.endsWith !== 'function') { | |
| 37 String.prototype.endsWith = function(suffix) { | |
| 38 return this.indexOf(suffix, this.length - suffix.length) !== -1; | |
| 39 }; | |
| 40 } | |
| 41 | |
| 42 // Fetch the content, uncompress it if necessary, then write it to the iframe. | |
| 43 function update() { | |
| 44 var digest = encodeURIComponent(document.getElementById('digest').value); | |
| 45 var namespace = encodeURIComponent( | |
| 46 document.getElementById('namespace').value); | |
| 47 var url = '/_ah/api/isolateservice/v1/retrieve'; | |
| 48 fetch(url, namespace, digest); | |
| 49 // TODO(maruel): Add back once endpoint API is rewritten. | |
| 50 //document.getElementById('generated_link').innerHTML = ( | |
| 51 // '<a href="' + url + '">Link to ' + digest + '</a>'); | |
| 52 } | |
| 53 | |
| 54 function ab2str(buf) { | |
| 55 return String.fromCharCode.apply(null, new Uint8Array(buf)); | |
| 56 } | |
| 57 | |
| 58 function fetch(url, namespace, digest) { | |
| 59 var xhr = new XMLHttpRequest(); | |
| 60 // TODO(maruel): Change back to a HTTP GET once endpoint API is rewritten. | |
| 61 xhr.open('POST', url, true); | |
| 62 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); | |
| 63 var oauthToken = gapi.auth.getToken(); | |
| 64 xhr.setRequestHeader('Authorization', 'Bearer ' + oauthToken.access_token); | |
| 65 xhr.responseType = 'arraybuffer'; | |
| 66 xhr.onload = function(e) { | |
| 67 if (this.status == 200) { | |
| 68 post_process_async( | |
| 69 namespace, new Uint8Array(this.response), write_to_iframe); | |
| 70 } else { | |
| 71 alert(ab2str(this.response)); | |
| 72 } | |
| 73 }; | |
| 74 xhr.send(JSON.stringify({namespace: {namespace:namespace}, digest: digest})) ; | |
| 75 } | |
| 76 | |
| 77 function decompress_to_string_async(data, callback) { | |
| 78 var bytes = pako.inflate(new Uint8Array(data)); | |
| 79 var bb = new Blob([bytes]); | |
| 80 var f = new FileReader(); | |
| 81 f.onload = function(e) { | |
| 82 callback(e.target.result); | |
| 83 }; | |
| 84 f.readAsText(bb); | |
| 85 } | |
| 86 | |
| 87 function post_process_async(namespace, data, callback) { | |
| 88 // Note that -gzip is a misnomer, it's actually -deflate. | |
| 89 if (namespace.endsWith('-gzip') || namespace.endsWith('-deflate')) { | |
| 90 decompress_to_string_async(data, function(x) { | |
| 91 // Now act as if the namespace was the default uncompressed one so | |
| 92 // further processing can be done. | |
| 93 post_process_async('default', x, callback); | |
| 94 }); | |
| 95 return; | |
| 96 } | |
| 97 if (data[0] == 'P' && data[1] == 'K') { | |
| 98 // TODO(maruel): Implement PKzip decoding to be able to list files? | |
| 99 callback("Found a .zip file (" + data.length + " bytes)"); | |
| 100 return; | |
| 101 } | |
| 102 if (data[0] == '{') { | |
| 103 // Assume a json file, pretty-print it. | |
| 104 // TODO(maruel): Convert .isolated files to browsable file. | |
| 105 // TODO(maruel): Catch exception and print data as-is in that case. | |
| 106 var pretty = JSON.stringify(JSON.parse(data), null, 2); | |
| 107 callback(pretty); | |
| 108 return; | |
| 109 } | |
| 110 // Fallback. | |
| 111 callback(data); | |
| 112 } | |
| 113 | |
| 114 function write_to_iframe(data) { | |
| 115 var ifrm = document.getElementById('content').contentDocument; | |
| 116 ifrm.open(); | |
| 117 ifrm.write('<html><body><pre>' + data + '</pre></body></html>'); | |
| 118 ifrm.close(); | |
| 119 } | |
| 120 </script> | |
| 121 #} | |
| 122 {% endblock %} | 31 {% endblock %} |
| 123 | 32 |
| 124 | |
| 125 {% block body %} | 33 {% block body %} |
| 126 | 34 |
| 127 <h1>File browser</h1> | 35 <h1>File browser</h1> |
| 128 | 36 |
| 129 Enter the namespace and digest of an object:<br> | 37 Enter the namespace and digest of an object:<br> |
| 130 <form id="form1" method="GET"> | 38 <form id="form1" method="GET"> |
| 131 <input id="namespace" name="namespace" value="{{namespace}}" /><br> | 39 <input id="namespace" name="namespace" value="{{namespace}}" /><br> |
| 132 <input id="digest" name="digest" maxlength=40 size=40 value="{{digest}}" /> | 40 <input id="digest" name="digest" maxlength=40 size=40 value="{{digest}}" /> |
| 133 <br> | 41 <br> |
| 134 <input type=submit value="Load item"/><br> | 42 <input type=submit value="Load item"/><br> |
| 135 </form> | 43 </form> |
| 136 <p> | |
| 137 <div id="generated_link"> </div> | |
| 138 <p> | |
| 139 <hr> | 44 <hr> |
| 140 <div class="use_all_space monospace">{{content}}{# <iframe id="content" class=" use_all_space" sandbox="allow-same-origin"></iframe>#}</div> | |
| 141 | 45 |
| 46 <div id="iframe-entry"></div> | |
| 47 <iframe id="content" class="use_all_space" sandbox="allow-same-origin allow-popu ps" src="content?namespace={{namespace}}&digest={{digest}}"> | |
|
M-A Ruel
2016/04/14 14:05:06
src="/content?... ?
kjlubick
2016/04/14 14:57:37
Done.
| |
| 48 </iframe> | |
| 142 {% endblock %} | 49 {% endblock %} |
| OLD | NEW |