Bug 1248563 - eslint cleanup of storage inspector code r=pbrosset

This commit is contained in:
Michael Ratcliffe 2016-02-16 16:12:55 +00:00
parent e68bfd0534
commit 19f8e208a9
8 changed files with 149 additions and 138 deletions

View File

@ -92,7 +92,7 @@
// rule is a better rule to check this.
"max-depth": 0,
// Maximum length of a line.
"max-len": [1, 80, 2, {"ignoreUrls": true, "ignorePattern": "\\s*require\\s*\\(|^\\s*loader\\.lazy"}],
"max-len": [1, 80, 2, {"ignoreUrls": true, "ignorePattern": "\\s*require\\s*\\(|^\\s*loader\\.lazy|-\\*-"}],
// Maximum depth callbacks can be nested.
"max-nested-callbacks": [2, 3],
// Don't limit the number of parameters that can be used in a function.

View File

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const {Cc, Ci, Cu} = require("chrome");
const {Ci, Cu} = require("chrome");
const EventEmitter = require("devtools/shared/event-emitter");
loader.lazyImporter(this, "setNamedTimeout",
"resource://devtools/client/shared/widgets/ViewHelpers.jsm");
@ -14,15 +14,16 @@ const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const HTML_NS = "http://www.w3.org/1999/xhtml";
const AFTER_SCROLL_DELAY = 100;
// Different types of events emitted by the Various components of the TableWidget
// Different types of events emitted by the Various components of the
// TableWidget.
const EVENTS = {
TABLE_CLEARED: "table-cleared",
CELL_EDIT: "cell-edit",
COLUMN_SORTED: "column-sorted",
COLUMN_TOGGLED: "column-toggled",
ROW_SELECTED: "row-selected",
ROW_UPDATED: "row-updated",
HEADER_CONTEXT_MENU: "header-context-menu",
ROW_CONTEXT_MENU: "row-context-menu",
ROW_SELECTED: "row-selected",
ROW_UPDATED: "row-updated",
SCROLL_END: "scroll-end"
};
Object.defineProperty(this, "EVENTS", {
@ -31,8 +32,8 @@ Object.defineProperty(this, "EVENTS", {
writable: false
});
// Maximum number of character visible in any cell in the table. This is to avoid
// making the cell take up all the space in a row.
// Maximum number of character visible in any cell in the table. This is to
// avoid making the cell take up all the space in a row.
const MAX_VISIBLE_STRING_SIZE = 100;
/**
@ -52,7 +53,7 @@ const MAX_VISIBLE_STRING_SIZE = 100;
* the context menu in the headers will not appear.
* - firstColumn: key of the first column that should appear.
*/
function TableWidget(node, options={}) {
function TableWidget(node, options = {}) {
EventEmitter.decorate(this);
this.document = node.ownerDocument;
@ -83,9 +84,10 @@ function TableWidget(node, options={}) {
this.items = new Map();
this.columns = new Map();
// Setup the column headers context menu to allow users to hide columns at will
// Setup the column headers context menu to allow users to hide columns at
// will.
if (this.removableColumns) {
this.onPopupCommand = this.onPopupCommand.bind(this)
this.onPopupCommand = this.onPopupCommand.bind(this);
this.setupHeadersContextMenu();
}
@ -99,7 +101,7 @@ function TableWidget(node, options={}) {
this.selectedRow = id;
};
this.on(EVENTS.ROW_SELECTED, this.bindSelectedRow);
};
}
TableWidget.prototype = {
@ -162,9 +164,9 @@ TableWidget.prototype = {
},
/**
* Prepares the context menu for the headers of the table columns. This context
* menu allows users to toggle various columns, only with an exception of the
* unique columns and when only two columns are visible in the table.
* Prepares the context menu for the headers of the table columns. This
* context menu allows users to toggle various columns, only with an exception
* of the unique columns and when only two columns are visible in the table.
*/
setupHeadersContextMenu: function() {
let popupset = this.document.getElementsByTagName("popupset")[0];
@ -308,7 +310,8 @@ TableWidget.prototype = {
},
/**
* Selects the previous row. Cycles over to the last row if first row is selected
* Selects the previous row. Cycles over to the last row if first row is
* selected.
*/
selectPreviousRow: function() {
for (let column of this.columns.values()) {
@ -430,9 +433,9 @@ TableWidget.prototype = {
}
let sortedItems = this.columns.get(column).sort([...this.items.values()]);
for (let [id, column] of this.columns) {
if (id != column) {
column.sort(sortedItems);
for (let [id, col] of this.columns) {
if (id != col) {
col.sort(sortedItems);
}
}
},
@ -673,8 +676,8 @@ Column.prototype = {
/**
* Pushes the `item` object into the column. If this column is sorted on,
* then inserts the object at the right position based on the column's id key's
* value.
* then inserts the object at the right position based on the column's id
* key's value.
*
* @returns {number}
* The index of the currently pushed item.
@ -856,7 +859,7 @@ Column.prototype = {
}
if (event.button == 0 && event.originalTarget == this.header) {
return this.table.sortBy(this.id);
this.table.sortBy(this.id);
}
},
@ -970,7 +973,7 @@ Cell.prototype = {
if (!(value instanceof Ci.nsIDOMNode) &&
value.length > MAX_VISIBLE_STRING_SIZE) {
value = value .substr(0, MAX_VISIBLE_STRING_SIZE) + "\u2026"; // …
value = value .substr(0, MAX_VISIBLE_STRING_SIZE) + "\u2026";
}
if (value instanceof Ci.nsIDOMNode) {
@ -1001,7 +1004,7 @@ Cell.prototype = {
flash: function() {
this.label.classList.remove("flash-out");
// Cause a reflow so that the animation retriggers on adding back the class
let a = this.label.parentNode.offsetWidth;
let a = this.label.parentNode.offsetWidth; // eslint-disable-line
this.label.classList.add("flash-out");
},
@ -1013,4 +1016,4 @@ Cell.prototype = {
this.label.remove();
this.label = null;
}
}
};

View File

@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const Services = require("Services")
const HTML_NS = "http://www.w3.org/1999/xhtml";
const EventEmitter = require("devtools/shared/event-emitter");
@ -17,11 +16,12 @@ const EventEmitter = require("devtools/shared/event-emitter");
* The container element for the tree widget.
* @param {Object} options
* - emptyText {string}: text to display when no entries in the table.
* - defaultType {string}: The default type of the tree items. For ex. 'js'
* - defaultType {string}: The default type of the tree items. For ex.
* 'js'
* - sorted {boolean}: Defaults to true. If true, tree items are kept in
* lexical order. If false, items will be kept in insertion order.
*/
function TreeWidget(node, options={}) {
function TreeWidget(node, options = {}) {
EventEmitter.decorate(this);
this.document = node.ownerDocument;
@ -43,7 +43,7 @@ function TreeWidget(node, options={}) {
}
// A map to hold all the passed attachment to each leaf in the tree.
this.attachments = new Map();
};
}
TreeWidget.prototype = {
@ -220,7 +220,8 @@ TreeWidget.prototype = {
/**
* Adds an item in the tree. The item can be added as a child to any node in
* the tree. The method will also create any subnode not present in the process.
* the tree. The method will also create any subnode not present in the
* process.
*
* @param {[string|object]} items
* An array of either string or objects where each increasing index
@ -266,7 +267,7 @@ TreeWidget.prototype = {
* The array of ids leading up to the item.
*/
remove: function(item) {
this.root.remove(item)
this.root.remove(item);
this.attachments.delete(JSON.stringify(item));
// Display the empty tree text
if (this.root.items.size == 0 && this.emptyText) {
@ -337,7 +338,7 @@ TreeWidget.prototype = {
*/
onKeypress: function(event) {
let currentSelected = this._selectedLabel;
switch(event.keyCode) {
switch (event.keyCode) {
case event.DOM_VK_UP:
this.selectPreviousItem();
break;
@ -404,7 +405,7 @@ module.exports.TreeWidget = TreeWidget;
* The type of the current node. For ex. "js"
*/
function TreeItem(document, parent, label, type) {
this.document = document
this.document = document;
this.node = this.document.createElementNS(HTML_NS, "li");
this.node.setAttribute("tabindex", "0");
this.isRoot = !parent;
@ -412,7 +413,7 @@ function TreeItem(document, parent, label, type) {
if (this.parent) {
this.level = this.parent.level + 1;
}
if (!!label) {
if (label) {
this.label = this.document.createElementNS(HTML_NS, "div");
this.label.setAttribute("empty", "true");
this.label.setAttribute("level", this.level);
@ -421,7 +422,7 @@ function TreeItem(document, parent, label, type) {
this.label.setAttribute("type", type);
}
if (typeof label == "string") {
this.label.textContent = label
this.label.textContent = label;
} else {
this.label.appendChild(label);
}
@ -454,8 +455,8 @@ TreeItem.prototype = {
level: 0,
/**
* Adds the item to the sub tree contained by this node. The item to be inserted
* can be a direct child of this node, or further down the tree.
* Adds the item to the sub tree contained by this node. The item to be
* inserted can be a direct child of this node, or further down the tree.
*
* @param {array} items
* Same as TreeWidget.add method's argument
@ -473,16 +474,18 @@ TreeItem.prototype = {
// Get the id and label corresponding to this level inside the tree.
let id = items[this.level].id || items[this.level];
if (this.items.has(id)) {
// An item with same id already exists, thus calling the add method of that
// child to add the passed node at correct position.
// An item with same id already exists, thus calling the add method of
// that child to add the passed node at correct position.
this.items.get(id).add(items, defaultType, sorted);
return;
}
// No item with the id `id` exists, so we create one and call the add
// method of that item.
// The display string of the item can be the label, the id, or the item itself
// if its a plain string.
let label = items[this.level].label || items[this.level].id || items[this.level];
// The display string of the item can be the label, the id, or the item
// itself if its a plain string.
let label = items[this.level].label ||
items[this.level].id ||
items[this.level];
let node = items[this.level].node;
if (node) {
// The item is supposed to be a DOMNode, so we fetch the textContent in

View File

@ -6,7 +6,6 @@
"use strict";
const {Cu} = require("chrome");
const EventEmitter = require("devtools/shared/event-emitter");
loader.lazyRequireGetter(this, "StorageFront",

View File

@ -62,8 +62,8 @@ const testCases = [
[["indexedDB", "https://sectest1.example.org", "idb-s2", "obj-s2"],
[16]],
[["Cache", "http://test1.example.org", "plop"],
[MAIN_DOMAIN + "404_cached_file.js", MAIN_DOMAIN + "browser_storage_basic.js"]],
[MAIN_DOMAIN + "404_cached_file.js",
MAIN_DOMAIN + "browser_storage_basic.js"]],
];
/**

View File

@ -4,7 +4,8 @@
"use strict";
var { console } = Cu.import("resource://gre/modules/Console.jsm", {});
/* eslint no-unused-vars: [2, {"vars": "local"}] */
var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
var { TargetFactory } = require("devtools/client/framework/target");
var promise = require("promise");
@ -92,13 +93,13 @@ function* openTabAndSetupStorage(url) {
// Setup the async storages in main window and for all its iframes
let callSetup = function*(win) {
if (typeof(win.setup) == "function") {
if (typeof (win.setup) == "function") {
yield win.setup();
}
for(var i = 0; i < win.frames.length; i++) {
for (let i = 0; i < win.frames.length; i++) {
yield callSetup(win.frames[i]);
}
}
};
yield callSetup(gWindow);
// open storage inspector
@ -254,7 +255,7 @@ function* click(node) {
/**
* Recursively expand the variables view up to a given property.
*
* @param aOptions
* @param options
* Options for view expansion:
* - rootVariable: start from the given scope/variable/property.
* - expandTo: string made up of property names you want to expand.
@ -266,14 +267,14 @@ function* click(node) {
* last property - |nextSibling| in the example above. Rejection is
* always the last property that was found.
*/
function variablesViewExpandTo(aOptions) {
let root = aOptions.rootVariable;
let expandTo = aOptions.expandTo.split(".");
function variablesViewExpandTo(options) {
let root = options.rootVariable;
let expandTo = options.expandTo.split(".");
let lastDeferred = promise.defer();
function getNext(aProp) {
function getNext(prop) {
let name = expandTo.shift();
let newProp = aProp.get(name);
let newProp = prop.get(name);
if (expandTo.length > 0) {
ok(newProp, "found property " + name);
@ -281,19 +282,15 @@ function variablesViewExpandTo(aOptions) {
newProp.expand();
getNext(newProp);
} else {
lastDeferred.reject(aProp);
lastDeferred.reject(prop);
}
} else if (newProp) {
lastDeferred.resolve(newProp);
} else {
lastDeferred.reject(aProp);
lastDeferred.reject(prop);
}
}
function fetchError(aProp) {
lastDeferred.reject(aProp);
}
if (root && root.expand) {
root.expand();
getNext(root);
@ -307,12 +304,12 @@ function variablesViewExpandTo(aOptions) {
/**
* Find variables or properties in a VariablesView instance.
*
* @param array aRules
* @param array ruleArray
* The array of rules you want to match. Each rule is an object with:
* - name (string|regexp): property name to match.
* - value (string|regexp): property value to match.
* - dontMatch (boolean): make sure the rule doesn't match any property.
* @param boolean aParsed
* @param boolean parsed
* true if we want to test the rules in the parse value section of the
* storage sidebar
* @return object
@ -323,23 +320,23 @@ function variablesViewExpandTo(aOptions) {
* VariablesView. If the rule did not match, then |matchedProp| is
* undefined.
*/
function findVariableViewProperties(aRules, aParsed) {
function findVariableViewProperties(ruleArray, parsed) {
// Initialize the search.
function init() {
// If aParsed is true, we are checking rules in the parsed value section of
// If parsed is true, we are checking rules in the parsed value section of
// the storage sidebar. That scope uses a blank variable as a placeholder
// Thus, adding a blank parent to each name
if (aParsed) {
aRules = aRules.map(({name, value, dontMatch}) => {
if (parsed) {
ruleArray = ruleArray.map(({name, value, dontMatch}) => {
return {name: "." + name, value, dontMatch};
});
}
// Separate out the rules that require expanding properties throughout the
// view.
let expandRules = [];
let rules = aRules.filter((aRule) => {
if (typeof aRule.name == "string" && aRule.name.indexOf(".") > -1) {
expandRules.push(aRule);
let rules = ruleArray.filter(rule => {
if (typeof rule.name == "string" && rule.name.indexOf(".") > -1) {
expandRules.push(rule);
return false;
}
return true;
@ -355,24 +352,24 @@ function findVariableViewProperties(aRules, aParsed) {
// Process the rules that need to expand properties.
let lastStep = processExpandRules.bind(null, expandRules);
// Return the results - a promise resolved to hold the updated aRules array.
let returnResults = onAllRulesMatched.bind(null, aRules);
// Return the results - a promise resolved to hold the updated ruleArray.
let returnResults = onAllRulesMatched.bind(null, ruleArray);
return promise.all(outstanding).then(lastStep).then(returnResults);
}
function onMatch(aProp, aRule, aMatched) {
if (aMatched && !aRule.matchedProp) {
aRule.matchedProp = aProp;
function onMatch(prop, rule, matched) {
if (matched && !rule.matchedProp) {
rule.matchedProp = prop;
}
}
function finder(rules, aView, aPromises) {
for (let scope of aView) {
function finder(rules, view, promises) {
for (let scope of view) {
for (let [, prop] of scope) {
for (let rule of rules) {
let matcher = matchVariablesViewProperty(prop, rule);
aPromises.push(matcher.then(onMatch.bind(null, prop, rule)));
promises.push(matcher.then(onMatch.bind(null, prop, rule)));
}
}
}
@ -386,17 +383,17 @@ function findVariableViewProperties(aRules, aParsed) {
let deferred = promise.defer();
let expandOptions = {
rootVariable: gUI.view.getScopeAtIndex(aParsed ? 1 : 0),
rootVariable: gUI.view.getScopeAtIndex(parsed ? 1 : 0),
expandTo: rule.name
};
variablesViewExpandTo(expandOptions).then(function onSuccess(aProp) {
variablesViewExpandTo(expandOptions).then(function onSuccess(prop) {
let name = rule.name;
let lastName = name.split(".").pop();
rule.name = lastName;
let matched = matchVariablesViewProperty(aProp, rule);
return matched.then(onMatch.bind(null, aProp, rule)).then(function() {
let matched = matchVariablesViewProperty(prop, rule);
return matched.then(onMatch.bind(null, prop, rule)).then(function() {
rule.name = name;
});
}, function onFailure() {
@ -430,9 +427,9 @@ function findVariableViewProperties(aRules, aParsed) {
* Check if a given Property object from the variables view matches the given
* rule.
*
* @param object aProp
* @param object prop
* The variable's view Property instance.
* @param object aRule
* @param object rule
* Rules for matching the property. See findVariableViewProperties() for
* details.
* @return object
@ -440,36 +437,36 @@ function findVariableViewProperties(aRules, aParsed) {
* result is a boolean that tells your promise callback the match
* result: true or false.
*/
function matchVariablesViewProperty(aProp, aRule) {
function resolve(aResult) {
return promise.resolve(aResult);
function matchVariablesViewProperty(prop, rule) {
function resolve(result) {
return promise.resolve(result);
}
if (!aProp) {
if (!prop) {
return resolve(false);
}
if (aRule.name) {
let match = aRule.name instanceof RegExp ?
aRule.name.test(aProp.name) :
aProp.name == aRule.name;
if (rule.name) {
let match = rule.name instanceof RegExp ?
rule.name.test(prop.name) :
prop.name == rule.name;
if (!match) {
return resolve(false);
}
}
if ("value" in aRule) {
let displayValue = aProp.displayValue;
if (aProp.displayValueClassName == "token-string") {
if ("value" in rule) {
let displayValue = prop.displayValue;
if (prop.displayValueClassName == "token-string") {
displayValue = displayValue.substring(1, displayValue.length - 1);
}
let match = aRule.value instanceof RegExp ?
aRule.value.test(displayValue) :
displayValue == aRule.value;
let match = rule.value instanceof RegExp ?
rule.value.test(displayValue) :
displayValue == rule.value;
if (!match) {
info("rule " + aRule.name + " did not match value, expected '" +
aRule.value + "', found '" + displayValue + "'");
info("rule " + rule.name + " did not match value, expected '" +
rule.value + "', found '" + displayValue + "'");
return resolve(false);
}
}
@ -521,7 +518,7 @@ function* selectTableItem(id) {
* @param {Boolean} [useCapture] for addEventListener/removeEventListener
* @return A promise that resolves when the event has been handled
*/
function once(target, eventName, useCapture=false) {
function once(target, eventName, useCapture = false) {
info("Waiting for event: '" + eventName + "' on " + target + ".");
let deferred = promise.defer();

View File

@ -69,6 +69,7 @@ var StorageUI = this.StorageUI = function StorageUI(front, target, panelWin) {
emptyText: L10N.getStr("table.emptyText"),
highlightUpdated: true,
});
this.displayObjectSidebar = this.displayObjectSidebar.bind(this);
this.table.on(TableWidget.EVENTS.ROW_SELECTED, this.displayObjectSidebar);
@ -150,7 +151,7 @@ StorageUI.prototype = {
* An object containing which storage types were cleared
*/
onCleared: function(response) {
let [type, host, db, objectStore] = this.tree.selectedItem;
let [type, host] = this.tree.selectedItem;
if (response.hasOwnProperty(type) && response[type].indexOf(host) > -1) {
this.table.clear();
this.hideSidebar();
@ -219,7 +220,7 @@ StorageUI.prototype = {
this.tree.selectedItem = [type, host, name[0], name[1]];
this.fetchStorageObjects(type, host, [JSON.stringify(name)], 1);
}
} catch(ex) {
} catch (ex) {
// Do nothing
}
}
@ -317,7 +318,9 @@ StorageUI.prototype = {
fetchStorageObjects: function(type, host, names, reason) {
let fetchOpts = reason === 3 ? {offset: this.itemOffset}
: {};
this.storageTypes[type].getStoreObjects(host, names, fetchOpts).then(({data}) => {
let storageType = this.storageTypes[type];
storageType.getStoreObjects(host, names, fetchOpts).then(({data}) => {
if (!data.length) {
this.emit("store-objects-updated");
return;
@ -341,14 +344,15 @@ StorageUI.prototype = {
populateStorageTree: function(storageTypes) {
this.storageTypes = {};
for (let type in storageTypes) {
// Ignore `from` field, which is just a protocol.js implementation artifact
// Ignore `from` field, which is just a protocol.js implementation
// artifact.
if (type === "from") {
continue;
}
let typeLabel = type;
try {
typeLabel = L10N.getStr("tree.labels." + type);
} catch(e) {
} catch (e) {
console.error("Unable to localize tree label type:" + type);
}
this.tree.add([{id: type, label: typeLabel, type: "store"}]);
@ -366,7 +370,7 @@ StorageUI.prototype = {
this.tree.selectedItem = [type, host, names[0], names[1]];
this.fetchStorageObjects(type, host, [name], 0);
}
} catch(ex) {
} catch (ex) {
// Do Nothing
}
}
@ -576,8 +580,9 @@ StorageUI.prototype = {
columns[key] = key;
try {
columns[key] = L10N.getStr("table.headers." + type + "." + key);
} catch(e) {
console.error("Unable to localize table header type:" + type + " key:" + key);
} catch (e) {
console.error("Unable to localize table header type:" + type +
" key:" + key);
}
}
this.table.setColumns(columns, null, HIDDEN_COLUMNS);
@ -643,12 +648,14 @@ StorageUI.prototype = {
* Handles endless scrolling for the table
*/
handleScrollEnd: function() {
if (!this.shouldLoadMoreItems) return;
if (!this.shouldLoadMoreItems) {
return;
}
this.shouldLoadMoreItems = false;
this.itemOffset += 50;
let item = this.tree.selectedItem;
let [type, host, db, objectStore] = item;
let [type, host] = item;
let names = null;
if (item.length > 2) {
names = [JSON.stringify(item.slice(2))];

View File

@ -716,7 +716,7 @@ var cookieHelpers = {
case "cookie-changed":
let cookie = subject.QueryInterface(Ci.nsICookie2);
cookieHelpers.onCookieChanged(cookie, topic, data);
break;
break;
}
},
@ -726,7 +726,7 @@ var cookieHelpers = {
let [cookie, topic, data] = msg.data.args;
cookie = JSON.parse(cookie);
cookieHelpers.onCookieChanged(cookie, topic, data);
break;
break;
}
},
@ -764,9 +764,9 @@ exports.setupParentProcessForCookies = function({mm, prefix}) {
gTrackedMessageManager.set("cookies", mm);
function handleMessageManagerDisconnected(evt, { mm: disconnected_mm }) {
function handleMessageManagerDisconnected(evt, { mm: disconnectedMm }) {
// filter out not subscribed message managers
if (disconnected_mm !== mm || !gTrackedMessageManager.has("cookies")) {
if (disconnectedMm !== mm || !gTrackedMessageManager.has("cookies")) {
return;
}
@ -794,7 +794,7 @@ exports.setupParentProcessForCookies = function({mm, prefix}) {
method: methodName,
args: args
});
} catch(e) {
} catch (e) {
// We may receive a NS_ERROR_NOT_INITIALIZED if the target window has
// been closed. This can legitimately happen in between test runs.
}
@ -837,7 +837,7 @@ function getObjectForLocalOrSessionStorage(type) {
populateStoresForHost: function(host, window) {
try {
this.hostVsStores.set(host, window[type]);
} catch(ex) {
} catch (ex) {
// Exceptions happen when local or session storage is inaccessible
}
return null;
@ -850,7 +850,7 @@ function getObjectForLocalOrSessionStorage(type) {
this.hostVsStores.set(this.getHostName(window.location),
window[type]);
}
} catch(ex) {
} catch (ex) {
// Exceptions happen when local or session storage is inaccessible
}
return null;
@ -922,11 +922,6 @@ StorageActors.createActor({
storeObjectType: "storagestoreobject"
}, getObjectForLocalOrSessionStorage("sessionStorage"));
let CacheAttributes = [
"url",
"status",
];
types.addDictType("cacheobject", {
"url": "string",
"status": "string"
@ -945,13 +940,15 @@ StorageActors.createActor({
}, {
getCachesForHost: Task.async(function*(host) {
let uri = Services.io.newURI(host, null, null);
let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
let principal =
Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
// The first argument tells if you want to get |content| cache or |chrome| cache.
// The first argument tells if you want to get |content| cache or |chrome|
// cache.
// The |content| cache is the cache explicitely named by the web content
// (service worker or web page).
// The |chrome| cache is the cache implicitely cached by the platform, hosting the
// source file of the service worker.
// The |chrome| cache is the cache implicitely cached by the platform,
// hosting the source file of the service worker.
let { CacheStorage } = this.storageActor.window;
let cache = new CacheStorage("content", principal);
return cache;
@ -981,18 +978,22 @@ StorageActors.createActor({
getNamesForHost: function(host) {
// UI code expect each name to be a JSON string of an array :/
return [...this.hostVsStores.get(host).keys()].map(a => JSON.stringify([a]));
return [...this.hostVsStores.get(host).keys()].map(a => {
return JSON.stringify([a]);
});
},
getValuesForHost: Task.async(function*(host, name) {
if (!name) return [];
if (!name) {
return [];
}
// UI is weird and expect a JSON stringified array... and pass it back :/
name = JSON.parse(name)[0];
let cache = this.hostVsStores.get(host).get(name);
let requests = yield cache.keys();
let results = [];
for(let request of requests) {
for (let request of requests) {
let response = yield cache.match(request);
// Unwrap the response to get access to all its properties if the
// response happen to be 'opaque', when it is a Cross Origin Request.
@ -1016,7 +1017,7 @@ StorageActors.createActor({
return location.protocol + "//" + location.host;
},
populateStoresForHost: Task.async(function*(host, window) {
populateStoresForHost: Task.async(function*(host) {
let storeMap = new Map();
let caches = yield this.getCachesForHost(host);
for (let name of (yield caches.keys())) {
@ -1381,7 +1382,7 @@ StorageActors.createActor({
unresolvedPromises.delete(func);
deferred.resolve(msg.json.args[0]);
}
break;
break;
}
});
@ -1449,7 +1450,8 @@ var indexedDBHelpers = {
principal = Services.scriptSecurityManager.getSystemPrincipal();
} else {
let uri = Services.io.newURI(host, null, null);
principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
principal = Services.scriptSecurityManager
.createCodebasePrincipal(uri, {});
}
return require("indexedDB").openForPrincipal(principal, name);
@ -1733,9 +1735,9 @@ exports.setupParentProcessForIndexedDB = function({mm, prefix}) {
gTrackedMessageManager.set("indexedDB", mm);
function handleMessageManagerDisconnected(evt, { mm: disconnected_mm }) {
function handleMessageManagerDisconnected(evt, { mm: disconnectedMm }) {
// filter out not subscribed message managers
if (disconnected_mm !== mm || !gTrackedMessageManager.has("indexedDB")) {
if (disconnectedMm !== mm || !gTrackedMessageManager.has("indexedDB")) {
return;
}
@ -1802,8 +1804,8 @@ var StorageActor = exports.StorageActor = protocol.ActorClass({
this.fetchChildWindows(this.parentActor.docShell);
// Initialize the registered store types
for (let [store, actor] of storageTypePool) {
this.childActorPool.set(store, new actor(this));
for (let [store, ActorConstructor] of storageTypePool) {
this.childActorPool.set(store, new ActorConstructor(this));
}
// Notifications that help us keep track of newly added windows and windows
@ -2089,7 +2091,7 @@ var StorageActor = exports.StorageActor = protocol.ActorClass({
/**
* Front for the Storage Actor.
*/
var StorageFront = exports.StorageFront = protocol.FrontClass(StorageActor, {
exports.StorageFront = protocol.FrontClass(StorageActor, {
initialize: function(client, tabForm) {
protocol.Front.prototype.initialize.call(this, client);
this.actorID = tabForm.storageActor;