Bug 668865 - Store _scheme & _host in _serializeHistoryEntry [r=dietrich]

Previously we would call NewURI for every shistory entry after we serialized the spec. We now avoid doing that as well as excessive RegExp matching.
This commit is contained in:
Paul O’Shannessy 2011-07-25 14:01:40 -07:00
parent c4c33c7ccf
commit 56d94f19ea

View File

@ -116,7 +116,7 @@ const CAPABILITIES = [
// 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",
"_shouldRestore"];
"_shouldRestore", "_host", "_scheme"];
// These are tab events that we listen to.
const TAB_EVENTS = ["TabOpen", "TabClose", "TabSelect", "TabShow", "TabHide",
@ -1770,7 +1770,15 @@ SessionStoreService.prototype = {
_serializeHistoryEntry:
function sss_serializeHistoryEntry(aEntry, aFullData, aIsPinned) {
var entry = { url: aEntry.URI.spec };
try {
entry._host = aEntry.URI.host;
entry._scheme = aEntry.URI.scheme;
}
catch (ex) {
// We just won't attempt to get cookies for this entry.
}
if (aEntry.title && aEntry.title != entry.url) {
entry.title = aEntry.title;
}
@ -2178,21 +2186,20 @@ SessionStoreService.prototype = {
*/
_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);