appcache.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const l10n = require("gcli/l10n");
  6. loader.lazyImporter(this, "AppCacheUtils", "resource://devtools/client/shared/AppCacheUtils.jsm");
  7. exports.items = [
  8. {
  9. item: "command",
  10. name: "appcache",
  11. description: l10n.lookup("appCacheDesc")
  12. },
  13. {
  14. item: "command",
  15. runAt: "server",
  16. name: "appcache validate",
  17. description: l10n.lookup("appCacheValidateDesc"),
  18. manual: l10n.lookup("appCacheValidateManual"),
  19. returnType: "appcacheerrors",
  20. params: [{
  21. group: "options",
  22. params: [
  23. {
  24. type: "string",
  25. name: "uri",
  26. description: l10n.lookup("appCacheValidateUriDesc"),
  27. defaultValue: null,
  28. }
  29. ]
  30. }],
  31. exec: function(args, context) {
  32. let utils;
  33. let deferred = context.defer();
  34. if (args.uri) {
  35. utils = new AppCacheUtils(args.uri);
  36. } else {
  37. utils = new AppCacheUtils(context.environment.document);
  38. }
  39. utils.validateManifest().then(function(errors) {
  40. deferred.resolve([errors, utils.manifestURI || "-"]);
  41. });
  42. return deferred.promise;
  43. }
  44. },
  45. {
  46. item: "converter",
  47. from: "appcacheerrors",
  48. to: "view",
  49. exec: function([errors, manifestURI], context) {
  50. if (errors.length == 0) {
  51. return context.createView({
  52. html: "<span>" + l10n.lookup("appCacheValidatedSuccessfully") + "</span>"
  53. });
  54. }
  55. return context.createView({
  56. html:
  57. "<div>" +
  58. " <h4>Manifest URI: ${manifestURI}</h4>" +
  59. " <ol>" +
  60. " <li foreach='error in ${errors}'>${error.msg}</li>" +
  61. " </ol>" +
  62. "</div>",
  63. data: {
  64. errors: errors,
  65. manifestURI: manifestURI
  66. }
  67. });
  68. }
  69. },
  70. {
  71. item: "command",
  72. runAt: "server",
  73. name: "appcache clear",
  74. description: l10n.lookup("appCacheClearDesc"),
  75. manual: l10n.lookup("appCacheClearManual"),
  76. exec: function(args, context) {
  77. let utils = new AppCacheUtils(args.uri);
  78. utils.clearAll();
  79. return l10n.lookup("appCacheClearCleared");
  80. }
  81. },
  82. {
  83. item: "command",
  84. runAt: "server",
  85. name: "appcache list",
  86. description: l10n.lookup("appCacheListDesc"),
  87. manual: l10n.lookup("appCacheListManual"),
  88. returnType: "appcacheentries",
  89. params: [{
  90. group: "options",
  91. params: [
  92. {
  93. type: "string",
  94. name: "search",
  95. description: l10n.lookup("appCacheListSearchDesc"),
  96. defaultValue: null,
  97. },
  98. ]
  99. }],
  100. exec: function(args, context) {
  101. let utils = new AppCacheUtils();
  102. return utils.listEntries(args.search);
  103. }
  104. },
  105. {
  106. item: "converter",
  107. from: "appcacheentries",
  108. to: "view",
  109. exec: function(entries, context) {
  110. return context.createView({
  111. html: "" +
  112. "<ul class='gcli-appcache-list'>" +
  113. " <li foreach='entry in ${entries}'>" +
  114. " <table class='gcli-appcache-detail'>" +
  115. " <tr>" +
  116. " <td>" + l10n.lookup("appCacheListKey") + "</td>" +
  117. " <td>${entry.key}</td>" +
  118. " </tr>" +
  119. " <tr>" +
  120. " <td>" + l10n.lookup("appCacheListFetchCount") + "</td>" +
  121. " <td>${entry.fetchCount}</td>" +
  122. " </tr>" +
  123. " <tr>" +
  124. " <td>" + l10n.lookup("appCacheListLastFetched") + "</td>" +
  125. " <td>${entry.lastFetched}</td>" +
  126. " </tr>" +
  127. " <tr>" +
  128. " <td>" + l10n.lookup("appCacheListLastModified") + "</td>" +
  129. " <td>${entry.lastModified}</td>" +
  130. " </tr>" +
  131. " <tr>" +
  132. " <td>" + l10n.lookup("appCacheListExpirationTime") + "</td>" +
  133. " <td>${entry.expirationTime}</td>" +
  134. " </tr>" +
  135. " <tr>" +
  136. " <td>" + l10n.lookup("appCacheListDataSize") + "</td>" +
  137. " <td>${entry.dataSize}</td>" +
  138. " </tr>" +
  139. " <tr>" +
  140. " <td>" + l10n.lookup("appCacheListDeviceID") + "</td>" +
  141. " <td>${entry.deviceID} <span class='gcli-out-shortcut' " +
  142. "onclick='${onclick}' ondblclick='${ondblclick}' " +
  143. "data-command='appcache viewentry ${entry.key}'" +
  144. ">" + l10n.lookup("appCacheListViewEntry") + "</span>" +
  145. " </td>" +
  146. " </tr>" +
  147. " </table>" +
  148. " </li>" +
  149. "</ul>",
  150. data: {
  151. entries: entries,
  152. onclick: context.update,
  153. ondblclick: context.updateExec
  154. }
  155. });
  156. }
  157. },
  158. {
  159. item: "command",
  160. runAt: "server",
  161. name: "appcache viewentry",
  162. description: l10n.lookup("appCacheViewEntryDesc"),
  163. manual: l10n.lookup("appCacheViewEntryManual"),
  164. params: [
  165. {
  166. type: "string",
  167. name: "key",
  168. description: l10n.lookup("appCacheViewEntryKey"),
  169. defaultValue: null,
  170. }
  171. ],
  172. exec: function(args, context) {
  173. let utils = new AppCacheUtils();
  174. return utils.viewEntry(args.key);
  175. }
  176. }
  177. ];