Bug 1302989: Make storage inspector work with file:// when # is in the URL

Issue #31
This commit is contained in:
janekptacijarabaci 2018-03-04 01:35:21 +01:00 committed by Roy Tam
commit b95939dd3c
16 changed files with 271 additions and 84 deletions

View file

@ -129,7 +129,11 @@ StorageActors.defaults = function (typeName, observationTopic) {
get hosts() {
let hosts = new Set();
for (let {location} of this.storageActor.windows) {
hosts.add(this.getHostName(location));
let host = this.getHostName(location);
if (host) {
hosts.add(host);
}
}
return hosts;
},
@ -143,13 +147,35 @@ StorageActors.defaults = function (typeName, observationTopic) {
},
/**
* Converts the window.location object into host.
* Converts the window.location object into a URL (e.g. http://domain.com).
*/
getHostName(location) {
if (location.protocol === "chrome:") {
return location.href;
if (!location) {
// Debugging a legacy Firefox extension... no hostname available and no
// storage possible.
return null;
}
switch (location.protocol) {
case "data:":
// data: URLs do not support storage of any type.
return null;
case "about:":
// Fallthrough.
case "chrome:":
// Fallthrough.
case "file:":
return location.protocol + location.pathname;
case "resource:":
return location.origin + location.pathname;
case "moz-extension:":
return location.origin;
case "javascript:":
return location.href;
default:
// http: or unknown protocol.
return `${location.protocol}//${location.host}`;
}
return location.hostname || location.href;
},
initialize(storageActor) {
@ -202,7 +228,7 @@ StorageActors.defaults = function (typeName, observationTopic) {
*/
onWindowReady: Task.async(function* (window) {
let host = this.getHostName(window.location);
if (!this.hostVsStores.has(host)) {
if (host && !this.hostVsStores.has(host)) {
yield this.populateStoresForHost(host, window);
let data = {};
data[host] = this.getNamesForHost(host);
@ -223,7 +249,7 @@ StorageActors.defaults = function (typeName, observationTopic) {
return;
}
let host = this.getHostName(window.location);
if (!this.hosts.has(host)) {
if (host && !this.hosts.has(host)) {
this.hostVsStores.delete(host);
let data = {};
data[host] = [];
@ -467,6 +493,9 @@ StorageActors.createActor({
if (cookie.host == null) {
return host == null;
}
host = trimHttpHttps(host);
if (cookie.host.startsWith(".")) {
return ("." + host).endsWith(cookie.host);
}
@ -732,6 +761,8 @@ var cookieHelpers = {
host = "";
}
host = trimHttpHttps(host);
let cookies = Services.cookies.getCookiesFromHost(host, originAttributes);
let store = [];
@ -866,6 +897,8 @@ var cookieHelpers = {
opts.path = split[2];
}
host = trimHttpHttps(host);
function hostMatches(cookieHost, matchHost) {
if (cookieHost == null) {
return matchHost == null;
@ -1089,16 +1122,6 @@ function getObjectForLocalOrSessionStorage(type) {
}));
},
getHostName(location) {
if (!location.host) {
return location.href;
}
if (location.protocol === "chrome:") {
return location.href;
}
return location.protocol + "//" + location.host;
},
populateStoresForHost(host, window) {
try {
this.hostVsStores.set(host, window[type]);
@ -1110,7 +1133,10 @@ function getObjectForLocalOrSessionStorage(type) {
populateStoresForHosts() {
this.hostVsStores = new Map();
for (let window of this.windows) {
this.populateStoresForHost(this.getHostName(window.location), window);
let host = this.getHostName(window.location);
if (host) {
this.populateStoresForHost(host, window);
}
}
},
@ -1315,16 +1341,6 @@ StorageActors.createActor({
];
}),
getHostName(location) {
if (!location.host) {
return location.href;
}
if (location.protocol === "chrome:") {
return location.href;
}
return location.protocol + "//" + location.host;
},
populateStoresForHost: Task.async(function* (host) {
let storeMap = new Map();
let caches = yield this.getCachesForHost(host);
@ -1596,16 +1612,6 @@ StorageActors.createActor({
this.removeDBRecord(host, principal, db, store, id);
}),
getHostName(location) {
if (!location.host) {
return location.href;
}
if (location.protocol === "chrome:") {
return location.href;
}
return location.protocol + "//" + location.host;
},
/**
* This method is overriden and left blank as for indexedDB, this operation
* cannot be performed synchronously. Thus, the preListStores method exists to
@ -2443,6 +2449,19 @@ exports.setupParentProcessForIndexedDB = function ({ mm, prefix }) {
};
};
/**
* General helpers
*/
function trimHttpHttps(url) {
if (url.startsWith("http://")) {
return url.substr(7);
}
if (url.startsWith("https://")) {
return url.substr(8);
}
return url;
}
/**
* The main Storage Actor.
*/