1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/gcli/commands/appcache.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,177 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +const gcli = require("gcli/index"); 1.11 + 1.12 +loader.lazyImporter(this, "AppCacheUtils", "resource:///modules/devtools/AppCacheUtils.jsm"); 1.13 + 1.14 +exports.items = [ 1.15 + { 1.16 + name: "appcache", 1.17 + description: gcli.lookup("appCacheDesc") 1.18 + }, 1.19 + { 1.20 + name: "appcache validate", 1.21 + description: gcli.lookup("appCacheValidateDesc"), 1.22 + manual: gcli.lookup("appCacheValidateManual"), 1.23 + returnType: "appcacheerrors", 1.24 + params: [{ 1.25 + group: "options", 1.26 + params: [ 1.27 + { 1.28 + type: "string", 1.29 + name: "uri", 1.30 + description: gcli.lookup("appCacheValidateUriDesc"), 1.31 + defaultValue: null, 1.32 + } 1.33 + ] 1.34 + }], 1.35 + exec: function(args, context) { 1.36 + let utils; 1.37 + let deferred = context.defer(); 1.38 + 1.39 + if (args.uri) { 1.40 + utils = new AppCacheUtils(args.uri); 1.41 + } else { 1.42 + utils = new AppCacheUtils(context.environment.document); 1.43 + } 1.44 + 1.45 + utils.validateManifest().then(function(errors) { 1.46 + deferred.resolve([errors, utils.manifestURI || "-"]); 1.47 + }); 1.48 + 1.49 + return deferred.promise; 1.50 + } 1.51 + }, 1.52 + { 1.53 + item: "converter", 1.54 + from: "appcacheerrors", 1.55 + to: "view", 1.56 + exec: function([errors, manifestURI], context) { 1.57 + if (errors.length == 0) { 1.58 + return context.createView({ 1.59 + html: "<span>" + gcli.lookup("appCacheValidatedSuccessfully") + "</span>" 1.60 + }); 1.61 + } 1.62 + 1.63 + return context.createView({ 1.64 + html: 1.65 + "<div>" + 1.66 + " <h4>Manifest URI: ${manifestURI}</h4>" + 1.67 + " <ol>" + 1.68 + " <li foreach='error in ${errors}'>${error.msg}</li>" + 1.69 + " </ol>" + 1.70 + "</div>", 1.71 + data: { 1.72 + errors: errors, 1.73 + manifestURI: manifestURI 1.74 + } 1.75 + }); 1.76 + } 1.77 + }, 1.78 + { 1.79 + name: "appcache clear", 1.80 + description: gcli.lookup("appCacheClearDesc"), 1.81 + manual: gcli.lookup("appCacheClearManual"), 1.82 + exec: function(args, context) { 1.83 + let utils = new AppCacheUtils(args.uri); 1.84 + utils.clearAll(); 1.85 + 1.86 + return gcli.lookup("appCacheClearCleared"); 1.87 + } 1.88 + }, 1.89 + { 1.90 + name: "appcache list", 1.91 + description: gcli.lookup("appCacheListDesc"), 1.92 + manual: gcli.lookup("appCacheListManual"), 1.93 + returnType: "appcacheentries", 1.94 + params: [{ 1.95 + group: "options", 1.96 + params: [ 1.97 + { 1.98 + type: "string", 1.99 + name: "search", 1.100 + description: gcli.lookup("appCacheListSearchDesc"), 1.101 + defaultValue: null, 1.102 + }, 1.103 + ] 1.104 + }], 1.105 + exec: function(args, context) { 1.106 + let utils = new AppCacheUtils(); 1.107 + return utils.listEntries(args.search); 1.108 + } 1.109 + }, 1.110 + { 1.111 + item: "converter", 1.112 + from: "appcacheentries", 1.113 + to: "view", 1.114 + exec: function(entries, context) { 1.115 + return context.createView({ 1.116 + html: "" + 1.117 + "<ul class='gcli-appcache-list'>" + 1.118 + " <li foreach='entry in ${entries}'>" + 1.119 + " <table class='gcli-appcache-detail'>" + 1.120 + " <tr>" + 1.121 + " <td>" + gcli.lookup("appCacheListKey") + "</td>" + 1.122 + " <td>${entry.key}</td>" + 1.123 + " </tr>" + 1.124 + " <tr>" + 1.125 + " <td>" + gcli.lookup("appCacheListFetchCount") + "</td>" + 1.126 + " <td>${entry.fetchCount}</td>" + 1.127 + " </tr>" + 1.128 + " <tr>" + 1.129 + " <td>" + gcli.lookup("appCacheListLastFetched") + "</td>" + 1.130 + " <td>${entry.lastFetched}</td>" + 1.131 + " </tr>" + 1.132 + " <tr>" + 1.133 + " <td>" + gcli.lookup("appCacheListLastModified") + "</td>" + 1.134 + " <td>${entry.lastModified}</td>" + 1.135 + " </tr>" + 1.136 + " <tr>" + 1.137 + " <td>" + gcli.lookup("appCacheListExpirationTime") + "</td>" + 1.138 + " <td>${entry.expirationTime}</td>" + 1.139 + " </tr>" + 1.140 + " <tr>" + 1.141 + " <td>" + gcli.lookup("appCacheListDataSize") + "</td>" + 1.142 + " <td>${entry.dataSize}</td>" + 1.143 + " </tr>" + 1.144 + " <tr>" + 1.145 + " <td>" + gcli.lookup("appCacheListDeviceID") + "</td>" + 1.146 + " <td>${entry.deviceID} <span class='gcli-out-shortcut' " + 1.147 + "onclick='${onclick}' ondblclick='${ondblclick}' " + 1.148 + "data-command='appcache viewentry ${entry.key}'" + 1.149 + ">" + gcli.lookup("appCacheListViewEntry") + "</span>" + 1.150 + " </td>" + 1.151 + " </tr>" + 1.152 + " </table>" + 1.153 + " </li>" + 1.154 + "</ul>", 1.155 + data: { 1.156 + entries: entries, 1.157 + onclick: context.update, 1.158 + ondblclick: context.updateExec 1.159 + } 1.160 + }); 1.161 + } 1.162 + }, 1.163 + { 1.164 + name: "appcache viewentry", 1.165 + description: gcli.lookup("appCacheViewEntryDesc"), 1.166 + manual: gcli.lookup("appCacheViewEntryManual"), 1.167 + params: [ 1.168 + { 1.169 + type: "string", 1.170 + name: "key", 1.171 + description: gcli.lookup("appCacheViewEntryKey"), 1.172 + defaultValue: null, 1.173 + } 1.174 + ], 1.175 + exec: function(args, context) { 1.176 + let utils = new AppCacheUtils(); 1.177 + return utils.viewEntry(args.key); 1.178 + } 1.179 + } 1.180 +];