Bug 1555861 - Make devtools storage.js module use storage principal; r=miker
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 11 Jul 2019 17:50:32 +0000
changeset 482441 f9a6c7aa2f763cd6cee6d566d647ff2b7b1c15df
parent 482440 9ad1135a16091c040fbafe390767ce7f5eecc867
child 482442 66f52bda7e14e26235bd0a43bb68ad11775046e4
push id36282
push userdvarga@mozilla.com
push dateFri, 12 Jul 2019 09:56:21 +0000
treeherdermozilla-central@cb2d564879e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmiker
bugs1555861, 1549587
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1555861 - Make devtools storage.js module use storage principal; r=miker Storage principal is the principal used for the storage area of a document, as well as when trying to communicate to other same-origin document instances. Right now the default is for the storage principal to be equal to the node principal for all documents, but in the dynamic FPI feature (bug 1549587) the storage principal for third-party documents will have a member of its origin attributes set to the eTLD+1 of the domain of the top-level document in order to 'partition' third-party data across top-level documents from different sites. This patch moves the devtools storage actor to use the storage principal so that when dynamic FPI is enabled, devtools uses the correct principal. Differential Revision: https://phabricator.services.mozilla.com/D37664
devtools/server/actors/storage.js
--- a/devtools/server/actors/storage.js
+++ b/devtools/server/actors/storage.js
@@ -423,17 +423,17 @@ StorageActors.defaults = function(typeNa
         toReturn.data = sliced.map(a => this.toStoreObject(a));
       }
 
       return toReturn;
     },
 
     getPrincipal(win) {
       if (win) {
-        return win.document.nodePrincipal;
+        return win.document.effectiveStoragePrincipal;
       }
       // We are running in the browser toolbox and viewing system DBs so we
       // need to use system principal.
       return Cc["@mozilla.org/systemprincipal;1"].createInstance(
         Ci.nsIPrincipal
       );
     },
   };
@@ -594,17 +594,17 @@ StorageActors.createActor(
     },
 
     populateStoresForHost(host) {
       this.hostVsStores.set(host, new Map());
       const doc = this.storageActor.document;
 
       const cookies = this.getCookiesFromHost(
         host,
-        doc.nodePrincipal.originAttributes
+        doc.effectiveStoragePrincipal.originAttributes
       );
 
       for (const cookie of cookies) {
         if (this.isCookieAtHost(cookie, host)) {
           const uniqueKey =
             `${cookie.name}${SEPARATOR_GUID}${cookie.host}` +
             `${SEPARATOR_GUID}${cookie.path}`;
 
@@ -718,44 +718,52 @@ StorageActors.createActor(
     /**
      * Pass the editItem command from the content to the chrome process.
      *
      * @param {Object} data
      *        See editCookie() for format details.
      */
     async editItem(data) {
       const doc = this.storageActor.document;
-      data.originAttributes = doc.nodePrincipal.originAttributes;
+      data.originAttributes = doc.effectiveStoragePrincipal.originAttributes;
       this.editCookie(data);
     },
 
     async addItem(guid) {
       const doc = this.storageActor.document;
       const time = new Date().getTime();
       const expiry = new Date(time + 3600 * 24 * 1000).toGMTString();
 
       doc.cookie = `${guid}=${DEFAULT_VALUE};expires=${expiry}`;
     },
 
     async removeItem(host, name) {
       const doc = this.storageActor.document;
-      this.removeCookie(host, name, doc.nodePrincipal.originAttributes);
+      this.removeCookie(
+        host,
+        name,
+        doc.effectiveStoragePrincipal.originAttributes
+      );
     },
 
     async removeAll(host, domain) {
       const doc = this.storageActor.document;
-      this.removeAllCookies(host, domain, doc.nodePrincipal.originAttributes);
+      this.removeAllCookies(
+        host,
+        domain,
+        doc.effectiveStoragePrincipal.originAttributes
+      );
     },
 
     async removeAllSessionCookies(host, domain) {
       const doc = this.storageActor.document;
       this.removeAllSessionCookies(
         host,
         domain,
-        doc.nodePrincipal.originAttributes
+        doc.effectiveStoragePrincipal.originAttributes
       );
     },
 
     maybeSetupChildProcess() {
       cookieHelpers.onCookieChanged = this.onCookieChanged.bind(this);
 
       if (!DebuggerServer.isInChildProcess) {
         this.getCookiesFromHost = cookieHelpers.getCookiesFromHost.bind(
@@ -1380,17 +1388,18 @@ StorageActors.createActor(
 
 StorageActors.createActor(
   {
     typeName: "Cache",
   },
   {
     async getCachesForHost(host) {
       const uri = Services.io.newURI(host);
-      const attrs = this.storageActor.document.nodePrincipal.originAttributes;
+      const attrs = this.storageActor.document.effectiveStoragePrincipal
+        .originAttributes;
       const principal = Services.scriptSecurityManager.createContentPrincipal(
         uri,
         attrs
       );
 
       // 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
@@ -1731,41 +1740,41 @@ StorageActors.createActor(
      * Remove an indexedDB database from given host with a given name.
      */
     async removeDatabase(host, name) {
       const win = this.storageActor.getWindowFromHost(host);
       if (!win) {
         return { error: `Window for host ${host} not found` };
       }
 
-      const principal = win.document.nodePrincipal;
+      const principal = win.document.effectiveStoragePrincipal;
       return this.removeDB(host, principal, name);
     },
 
     async removeAll(host, name) {
       const [db, store] = JSON.parse(name);
 
       const win = this.storageActor.getWindowFromHost(host);
       if (!win) {
         return;
       }
 
-      const principal = win.document.nodePrincipal;
+      const principal = win.document.effectiveStoragePrincipal;
       this.clearDBStore(host, principal, db, store);
     },
 
     async removeItem(host, name) {
       const [db, store, id] = JSON.parse(name);
 
       const win = this.storageActor.getWindowFromHost(host);
       if (!win) {
         return;
       }
 
-      const principal = win.document.nodePrincipal;
+      const principal = win.document.effectiveStoragePrincipal;
       this.removeDBRecord(host, principal, db, store, id);
     },
 
     /**
      * This method is overriden and left blank as for indexedDB, this operation
      * cannot be performed synchronously. Thus, the preListStores method exists to
      * do the same task asynchronously.
      */