summaryrefslogtreecommitdiffstats
path: root/devtools/server/actors/storage.js
diff options
context:
space:
mode:
authorMoonchild <mcwerewolf@gmail.com>2018-03-04 10:28:35 +0100
committerGitHub <noreply@github.com>2018-03-04 10:28:35 +0100
commitf6e7a511bc39106c1bb0f9461d1eb23564c10c8b (patch)
treeea591de8f3a91755421f7416c0b574271a8a6ea6 /devtools/server/actors/storage.js
parenteb7399a0ab12c320ffcd8ea54a4f7d521150daa3 (diff)
parente78a87b4188fd266d6ec9662c95ef147dbbd92cd (diff)
downloadUXP-f6e7a511bc39106c1bb0f9461d1eb23564c10c8b.tar
UXP-f6e7a511bc39106c1bb0f9461d1eb23564c10c8b.tar.gz
UXP-f6e7a511bc39106c1bb0f9461d1eb23564c10c8b.tar.lz
UXP-f6e7a511bc39106c1bb0f9461d1eb23564c10c8b.tar.xz
UXP-f6e7a511bc39106c1bb0f9461d1eb23564c10c8b.zip
Merge pull request #40 from janekptacijarabaci/devtools_import-from-moebius_3
Port across devtools enhancements - 3
Diffstat (limited to 'devtools/server/actors/storage.js')
-rw-r--r--devtools/server/actors/storage.js100
1 files changed, 62 insertions, 38 deletions
diff --git a/devtools/server/actors/storage.js b/devtools/server/actors/storage.js
index 015d849ee..c702e8145 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 = trimHttpHttpsPort(host);
+
if (cookie.host.startsWith(".")) {
return ("." + host).endsWith(cookie.host);
}
@@ -732,6 +761,8 @@ var cookieHelpers = {
host = "";
}
+ host = trimHttpHttpsPort(host);
+
let cookies = Services.cookies.getCookiesFromHost(host, originAttributes);
let store = [];
@@ -866,6 +897,8 @@ var cookieHelpers = {
opts.path = split[2];
}
+ host = trimHttpHttpsPort(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,24 @@ exports.setupParentProcessForIndexedDB = function ({ mm, prefix }) {
};
/**
+ * General helpers
+ */
+function trimHttpHttpsPort(url) {
+ let match = url.match(/(.+):\d+$/);
+
+ if (match) {
+ url = match[1];
+ }
+ 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, {