web_packaged_app.sjs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. var Cc = Components.classes;
  2. var Ci = Components.interfaces;
  3. var Cu = Components.utils;
  4. function handleRequest(request, response)
  5. {
  6. response.setHeader("Content-Type", "application/package", false);
  7. response.write(octetStreamData.getData());
  8. return;
  9. }
  10. // The package content
  11. // getData formats it as described at http://www.w3.org/TR/web-packaging/#streamable-package-format
  12. var octetStreamData = {
  13. content: [
  14. { headers: ["Content-Location: /index.html", "Content-Type: text/html"], data: "<html>\r\n <head>\r\n <script> alert('OK: hello'); alert('DONE'); </script>\r\n</head>\r\n Web Packaged App Index\r\n</html>\r\n", type: "text/html" },
  15. { headers: ["Content-Location: /scripts/app.js", "Content-Type: text/javascript"], data: "module Math from '/scripts/helpers/math.js';\r\n...\r\n", type: "text/javascript" },
  16. { headers: ["Content-Location: /scripts/helpers/math.js", "Content-Type: text/javascript"], data: "export function sum(nums) { ... }\r\n...\r\n", type: "text/javascript" }
  17. ],
  18. token : "gc0pJq0M:08jU534c0p",
  19. getData: function() {
  20. var str = "";
  21. for (var i in this.content) {
  22. str += "--" + this.token + "\r\n";
  23. for (var j in this.content[i].headers) {
  24. str += this.content[i].headers[j] + "\r\n";
  25. }
  26. str += "\r\n";
  27. str += this.content[i].data + "\r\n";
  28. }
  29. str += "--" + this.token + "--";
  30. return str;
  31. }
  32. }