summaryrefslogtreecommitdiffstats
path: root/devtools/server/actors/storage.js
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/server/actors/storage.js')
-rw-r--r--devtools/server/actors/storage.js95
1 files changed, 57 insertions, 38 deletions
diff --git a/devtools/server/actors/storage.js b/devtools/server/actors/storage.js
index 015d849ee..a7215b152 100644
--- a/devtools/server/actors/storage.js
+++ b/devtools/server/actors/storage.js
@@ -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
@@ -2444,6 +2450,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.
*/
let StorageActor = protocol.ActorClassWithSpec(specs.storageSpec, {