diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-03-04 01:35:21 +0100 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-03-04 01:35:21 +0100 |
commit | a53fe8f5c92ceeb091df55ce41b69f49f7d6c6d6 (patch) | |
tree | d9738081fe4e6e3cc3d29eea6e9d71c5c30dcc06 /devtools/server | |
parent | bba13e3d3404473373d9d2122608a90e0aa2ca9f (diff) | |
download | uxp-a53fe8f5c92ceeb091df55ce41b69f49f7d6c6d6.tar.gz |
Bug 1302989: Make storage inspector work with file:// when # is in the URL
Issue #31
Diffstat (limited to 'devtools/server')
5 files changed, 98 insertions, 52 deletions
diff --git a/devtools/server/actors/storage.js b/devtools/server/actors/storage.js index 015d849ee2..a7215b1524 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, { diff --git a/devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js b/devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js index c1cf0aa72a..1cdc8b490e 100644 --- a/devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js +++ b/devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js @@ -11,7 +11,7 @@ const {StorageFront} = require("devtools/shared/fronts/storage"); Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/server/tests/browser/storage-helpers.js", this); const TESTDATA = { - "test1.example.org": [ + "http://test1.example.org": [ { name: "name", value: "value1", diff --git a/devtools/server/tests/browser/browser_storage_dynamic_windows.js b/devtools/server/tests/browser/browser_storage_dynamic_windows.js index 91b4155d98..a8f791f150 100644 --- a/devtools/server/tests/browser/browser_storage_dynamic_windows.js +++ b/devtools/server/tests/browser/browser_storage_dynamic_windows.js @@ -9,8 +9,8 @@ Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtool const beforeReload = { cookies: { - "test1.example.org": ["c1", "cs2", "c3", "uc1"], - "sectest1.example.org": ["uc1", "cs2"] + "http://test1.example.org": ["c1", "cs2", "c3", "uc1"], + "http://sectest1.example.org": ["uc1", "cs2"] }, localStorage: { "http://test1.example.org": ["ls1", "ls2"], @@ -99,7 +99,12 @@ function testAddIframe(front) { "https://sectest1.example.org": ["iframe-s-ss1"] }, cookies: { - "sectest1.example.org": [ + "https://sectest1.example.org": [ + getCookieId("cs2", ".example.org", "/"), + getCookieId("sc1", "sectest1.example.org", + "/browser/devtools/server/tests/browser/") + ], + "http://sectest1.example.org": [ getCookieId("sc1", "sectest1.example.org", "/browser/devtools/server/tests/browser/") ] diff --git a/devtools/server/tests/browser/browser_storage_listings.js b/devtools/server/tests/browser/browser_storage_listings.js index e47a320b83..6c16683212 100644 --- a/devtools/server/tests/browser/browser_storage_listings.js +++ b/devtools/server/tests/browser/browser_storage_listings.js @@ -9,7 +9,7 @@ Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtool const storeMap = { cookies: { - "test1.example.org": [ + "http://test1.example.org": [ { name: "c1", value: "foobar", @@ -38,7 +38,29 @@ const storeMap = { isSecure: true, } ], - "sectest1.example.org": [ + + "http://sectest1.example.org": [ + { + name: "cs2", + value: "sessionCookie", + path: "/", + host: ".example.org", + expires: 0, + isDomain: true, + isSecure: false, + }, + { + name: "sc1", + value: "foobar", + path: "/browser/devtools/server/tests/browser/", + host: "sectest1.example.org", + expires: 0, + isDomain: false, + isSecure: false, + } + ], + + "https://sectest1.example.org": [ { name: "uc1", value: "foobar", @@ -328,7 +350,7 @@ function* testStores(data) { } function testCookies(cookiesActor) { - is(Object.keys(cookiesActor.hosts).length, 2, + is(Object.keys(cookiesActor.hosts).length, 3, "Correct number of host entries for cookies"); return testCookiesObjects(0, cookiesActor.hosts, cookiesActor); } diff --git a/devtools/server/tests/browser/browser_storage_updates.js b/devtools/server/tests/browser/browser_storage_updates.js index 01a35cefca..4a16047871 100644 --- a/devtools/server/tests/browser/browser_storage_updates.js +++ b/devtools/server/tests/browser/browser_storage_updates.js @@ -6,7 +6,7 @@ const {StorageFront} = require("devtools/shared/fronts/storage"); const beforeReload = { - cookies: ["test1.example.org", "sectest1.example.org"], + cookies: ["http://test1.example.org", "https://sectest1.example.org"], localStorage: ["http://test1.example.org", "http://sectest1.example.org"], sessionStorage: ["http://test1.example.org", "http://sectest1.example.org"], }; @@ -27,7 +27,7 @@ const TESTS = [ expected: { added: { cookies: { - "test1.example.org": [ + "http://test1.example.org": [ getCookieId("c1", "test1.example.org", "/browser/devtools/server/tests/browser/"), getCookieId("c2", "test1.example.org", @@ -53,7 +53,7 @@ const TESTS = [ expected: { changed: { cookies: { - "test1.example.org": [ + "http://test1.example.org": [ getCookieId("c1", "test1.example.org", "/browser/devtools/server/tests/browser/"), ] @@ -82,7 +82,7 @@ const TESTS = [ expected: { deleted: { cookies: { - "test1.example.org": [ + "http://test1.example.org": [ getCookieId("c2", "test1.example.org", "/browser/devtools/server/tests/browser/"), ] @@ -123,7 +123,7 @@ const TESTS = [ expected: { added: { cookies: { - "test1.example.org": [ + "http://test1.example.org": [ getCookieId("c3", "test1.example.org", "/browser/devtools/server/tests/browser/"), ] @@ -139,7 +139,7 @@ const TESTS = [ }, deleted: { cookies: { - "test1.example.org": [ + "http://test1.example.org": [ getCookieId("c1", "test1.example.org", "/browser/devtools/server/tests/browser/"), ] @@ -175,7 +175,7 @@ const TESTS = [ expected: { deleted: { cookies: { - "test1.example.org": [ + "http://test1.example.org": [ getCookieId("c3", "test1.example.org", "/browser/devtools/server/tests/browser/"), ] |