[Bug 729071] Port |Bug 668865 - Store _scheme & _host in _serializeHistoryEntry| to SeaMonkey. r=Neil
authorMisak Khachatryan <misak.bugzilla@gmail.com>
Wed, 22 Feb 2012 09:24:32 +0400
changeset 10910 e9ec2bb36336d6f703eb2a18c1b5a7916892be08
parent 10909 fd98bca81bec47ffb1022edb1163734c6908ff54
child 10911 458e96a21f6046ece81440d7eb46f1ab435c6fbc
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs729071, 668865
[Bug 729071] Port |Bug 668865 - Store _scheme & _host in _serializeHistoryEntry| to SeaMonkey. r=Neil
suite/common/src/nsSessionStore.js
--- a/suite/common/src/nsSessionStore.js
+++ b/suite/common/src/nsSessionStore.js
@@ -111,17 +111,17 @@ XXX keep these in sync with all the attr
 const CAPABILITIES = [
   "Subframes", "Plugins", "Javascript", "MetaRedirects", "Images",
   "DNSPrefetch", "Auth", "WindowControl"
 ];
 
 // These keys are for internal use only - they shouldn't be part of the JSON
 // that gets saved to disk nor part of the strings returned by the API.
 const INTERNAL_KEYS = ["_tabStillLoading", "_hosts", "_formDataSaved",
-                       "_tab", "_browser", "_history"];
+                       "_tab", "_browser", "_history", "_host", "_scheme"];
 
 // These are tab events that we listen to.
 const TAB_EVENTS = ["TabOpen", "TabClose", "TabSelect", "TabShow", "TabHide"];
 
 #ifndef XP_WIN
 #define BROKEN_WM_Z_ORDER
 #endif
 
@@ -1590,16 +1590,24 @@ SessionStoreService.prototype = {
    * @param aIsPinned
    *        the tab is pinned and should be treated differently for privacy
    * @returns object
    */
   _serializeHistoryEntry:
     function sss_serializeHistoryEntry(aEntry, aFullData, aIsPinned) {
     var entry = { url: aEntry.URI.spec };
 
+    try {
+      entry._scheme = aEntry.URI.scheme;
+      entry._host = aEntry.URI.host;
+    }
+    catch (ex) {
+      // We just won't attempt to get cookies for this entry.
+    }
+
     if (aEntry.title && aEntry.title != entry.url) {
       entry.title = aEntry.title;
     }
     if (aEntry.isSubFrame) {
       entry.subframe = true;
     }
     if (!(aEntry instanceof Components.interfaces.nsISHEntry)) {
       return entry;
@@ -2003,31 +2011,30 @@ SessionStoreService.prototype = {
    * @param aCheckPrivacy
    *        should we check the privacy level for https
    * @param aIsPinned
    *        is the entry we're evaluating for a pinned tab; used only if
    *        aCheckPrivacy
    */
   _extractHostsForCookies:
     function sss_extractHostsForCookies(aEntry, aHosts, aCheckPrivacy, aIsPinned) {
-    let match;
-
-    if ((match = /^https?:\/\/(?:[^@\/\s]+@)?([\w.-]+)/.exec(aEntry.url)) != null) {
-      if (!aHosts[match[1]] &&
-          (!aCheckPrivacy ||
-           this._checkPrivacyLevel(this._getURIFromString(aEntry.url).schemeIs("https"),
-                                   aIsPinned))) {
-        // By setting this to true or false, we can determine when looking at
-        // the host in _updateCookies if we should check for privacy.
-        aHosts[match[1]] = aIsPinned;
-      }
+
+    // _host and _scheme may not be set (for about: urls for example), in which
+    // case testing _scheme will be sufficient.
+    if (/https?/.test(aEntry._scheme) && !aHosts[aEntry._host] &&
+        (!aCheckPrivacy ||
+         this._checkPrivacyLevel(aEntry._scheme == "https", aIsPinned))) {
+      // By setting this to true or false, we can determine when looking at
+      // the host in _updateCookies if we should check for privacy.
+      aHosts[aEntry._host] = aIsPinned;
     }
-    else if ((match = /^file:\/\/([^\/]*)/.exec(aEntry.url)) != null) {
-      aHosts[match[1]] = true;
+    else if (aEntry._scheme == "file") {
+      aHosts[aEntry._host] = true;
     }
+
     if (aEntry.children) {
       aEntry.children.forEach(function(entry) {
         this._extractHostsForCookies(entry, aHosts, aCheckPrivacy, aIsPinned);
       }, this);
     }
   },
 
   /**