Bug 1283709 - Map SessionCookies by origin attributes. r=mikedeboer
authorJonathan Hao <jhao@mozilla.com>
Wed, 06 Jul 2016 01:45:00 +0800
changeset 304007 7df4e14a35ea30cf39fc2372fcfd62447b9a28ae
parent 304006 00c32030641b728ffb7a1ea4779f3340ad40650d
child 304008 51cc2f61dad67a7abae005a494b6c1502481c0ed
push id19899
push usercbook@mozilla.com
push dateThu, 07 Jul 2016 09:43:39 +0000
treeherderfx-team@4a8d8898e507 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1283709
milestone50.0a1
Bug 1283709 - Map SessionCookies by origin attributes. r=mikedeboer MozReview-Commit-ID: IAuKZdVWgNl
browser/components/sessionstore/SessionCookies.jsm
--- a/browser/components/sessionstore/SessionCookies.jsm
+++ b/browser/components/sessionstore/SessionCookies.jsm
@@ -364,17 +364,19 @@ var CookieStore = {
     let cookies = [];
 
     let appendCookiesForHost = host => {
       if (!this._hosts.has(host)) {
         return;
       }
 
       for (let pathToNamesMap of this._hosts.get(host).values()) {
-        cookies.push(...pathToNamesMap.values());
+        for (let nameToCookiesMap of pathToNamesMap.values()) {
+          cookies.push(...nameToCookiesMap.values());
+        }
       }
     }
 
     // Try to find cookies for the given host, e.g. <www.example.com>.
     // The full hostname will be in the map if the Set-Cookie header did not
     // have a domain= attribute, i.e. the cookie will only be stored for the
     // request domain. Also, try to find cookies for subdomains, e.g.
     // <.example.com>. We will find those variants with a leading dot in the
@@ -450,17 +452,24 @@ var CookieStore = {
    * @return The newly created Map instance mapping cookie names to
    *         internal jscookies, in the given path of the given host.
    */
   _ensureMap: function (cookie) {
     if (!this._hosts.has(cookie.host)) {
       this._hosts.set(cookie.host, new Map());
     }
 
-    let pathToNamesMap = this._hosts.get(cookie.host);
+    let originAttributesMap = this._hosts.get(cookie.host);
+    // If cookie.originAttributes is null, originAttributes will be an empty string.
+    let originAttributes = ChromeUtils.originAttributesToSuffix(cookie.originAttributes);
+    if (!originAttributesMap.has(originAttributes)) {
+      originAttributesMap.set(originAttributes, new Map());
+    }
+
+    let pathToNamesMap = originAttributesMap.get(originAttributes);
 
     if (!pathToNamesMap.has(cookie.path)) {
       pathToNamesMap.set(cookie.path, new Map());
     }
 
     return pathToNamesMap.get(cookie.path);
   }
 };