Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
5 "use strict";
7 const gcli = require("gcli/index");
9 loader.lazyImporter(this, "AppCacheUtils", "resource:///modules/devtools/AppCacheUtils.jsm");
11 exports.items = [
12 {
13 name: "appcache",
14 description: gcli.lookup("appCacheDesc")
15 },
16 {
17 name: "appcache validate",
18 description: gcli.lookup("appCacheValidateDesc"),
19 manual: gcli.lookup("appCacheValidateManual"),
20 returnType: "appcacheerrors",
21 params: [{
22 group: "options",
23 params: [
24 {
25 type: "string",
26 name: "uri",
27 description: gcli.lookup("appCacheValidateUriDesc"),
28 defaultValue: null,
29 }
30 ]
31 }],
32 exec: function(args, context) {
33 let utils;
34 let deferred = context.defer();
36 if (args.uri) {
37 utils = new AppCacheUtils(args.uri);
38 } else {
39 utils = new AppCacheUtils(context.environment.document);
40 }
42 utils.validateManifest().then(function(errors) {
43 deferred.resolve([errors, utils.manifestURI || "-"]);
44 });
46 return deferred.promise;
47 }
48 },
49 {
50 item: "converter",
51 from: "appcacheerrors",
52 to: "view",
53 exec: function([errors, manifestURI], context) {
54 if (errors.length == 0) {
55 return context.createView({
56 html: "<span>" + gcli.lookup("appCacheValidatedSuccessfully") + "</span>"
57 });
58 }
60 return context.createView({
61 html:
62 "<div>" +
63 " <h4>Manifest URI: ${manifestURI}</h4>" +
64 " <ol>" +
65 " <li foreach='error in ${errors}'>${error.msg}</li>" +
66 " </ol>" +
67 "</div>",
68 data: {
69 errors: errors,
70 manifestURI: manifestURI
71 }
72 });
73 }
74 },
75 {
76 name: "appcache clear",
77 description: gcli.lookup("appCacheClearDesc"),
78 manual: gcli.lookup("appCacheClearManual"),
79 exec: function(args, context) {
80 let utils = new AppCacheUtils(args.uri);
81 utils.clearAll();
83 return gcli.lookup("appCacheClearCleared");
84 }
85 },
86 {
87 name: "appcache list",
88 description: gcli.lookup("appCacheListDesc"),
89 manual: gcli.lookup("appCacheListManual"),
90 returnType: "appcacheentries",
91 params: [{
92 group: "options",
93 params: [
94 {
95 type: "string",
96 name: "search",
97 description: gcli.lookup("appCacheListSearchDesc"),
98 defaultValue: null,
99 },
100 ]
101 }],
102 exec: function(args, context) {
103 let utils = new AppCacheUtils();
104 return utils.listEntries(args.search);
105 }
106 },
107 {
108 item: "converter",
109 from: "appcacheentries",
110 to: "view",
111 exec: function(entries, context) {
112 return context.createView({
113 html: "" +
114 "<ul class='gcli-appcache-list'>" +
115 " <li foreach='entry in ${entries}'>" +
116 " <table class='gcli-appcache-detail'>" +
117 " <tr>" +
118 " <td>" + gcli.lookup("appCacheListKey") + "</td>" +
119 " <td>${entry.key}</td>" +
120 " </tr>" +
121 " <tr>" +
122 " <td>" + gcli.lookup("appCacheListFetchCount") + "</td>" +
123 " <td>${entry.fetchCount}</td>" +
124 " </tr>" +
125 " <tr>" +
126 " <td>" + gcli.lookup("appCacheListLastFetched") + "</td>" +
127 " <td>${entry.lastFetched}</td>" +
128 " </tr>" +
129 " <tr>" +
130 " <td>" + gcli.lookup("appCacheListLastModified") + "</td>" +
131 " <td>${entry.lastModified}</td>" +
132 " </tr>" +
133 " <tr>" +
134 " <td>" + gcli.lookup("appCacheListExpirationTime") + "</td>" +
135 " <td>${entry.expirationTime}</td>" +
136 " </tr>" +
137 " <tr>" +
138 " <td>" + gcli.lookup("appCacheListDataSize") + "</td>" +
139 " <td>${entry.dataSize}</td>" +
140 " </tr>" +
141 " <tr>" +
142 " <td>" + gcli.lookup("appCacheListDeviceID") + "</td>" +
143 " <td>${entry.deviceID} <span class='gcli-out-shortcut' " +
144 "onclick='${onclick}' ondblclick='${ondblclick}' " +
145 "data-command='appcache viewentry ${entry.key}'" +
146 ">" + gcli.lookup("appCacheListViewEntry") + "</span>" +
147 " </td>" +
148 " </tr>" +
149 " </table>" +
150 " </li>" +
151 "</ul>",
152 data: {
153 entries: entries,
154 onclick: context.update,
155 ondblclick: context.updateExec
156 }
157 });
158 }
159 },
160 {
161 name: "appcache viewentry",
162 description: gcli.lookup("appCacheViewEntryDesc"),
163 manual: gcli.lookup("appCacheViewEntryManual"),
164 params: [
165 {
166 type: "string",
167 name: "key",
168 description: gcli.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 ];