pull/2/head
gorhill 8 years ago
parent 0031a47721
commit 65924d1be8

@ -840,13 +840,24 @@ vAPI.cookies = {};
/******************************************************************************/
vAPI.cookies.start = function() {
var reallyRemoved = {
'evicted': true,
'expired': true,
'explicit': true
};
var onChanged = function(changeInfo) {
var handler = changeInfo.removed ? this.onRemoved : this.onChanged;
if ( typeof handler !== 'function' ) {
if ( changeInfo.removed ) {
if ( reallyRemoved[changeInfo.cause] && typeof this.onRemoved === 'function' ) {
this.onRemoved(changeInfo.cookie);
}
return;
}
handler(changeInfo.cookie);
if ( typeof this.onChanged === 'function' ) {
this.onChanged(changeInfo.cookie);
}
};
chrome.cookies.onChanged.addListener(onChanged.bind(this));
};

@ -3294,7 +3294,21 @@ vAPI.cookies.observe = function(subject, topic, reason) {
//if ( topic !== 'cookie-changed' && topic !== 'private-cookie-changed' ) {
// return;
//}
if ( reason === 'deleted' || subject instanceof Ci.nsICookie2 === false ) {
//
if ( reason === 'cleared' && typeof this.onAllRemoved === 'function' ) {
this.onAllRemoved();
return;
}
if ( subject === null ) {
return;
}
if ( subject instanceof Ci.nsICookie2 === false ) {
subject = subject.QueryInterface(Ci.nsICookie2);
}
if ( reason === 'deleted' ) {
if ( typeof this.onRemoved === 'function' ) {
this.onRemoved(new this.CookieEntry(subject));
}
return;
}
if ( typeof this.onChanged === 'function' ) {

@ -119,7 +119,6 @@ var removeCookieFromDict = function(cookieKey) {
if ( cookieEntryJunkyard.length < 25 ) {
cookieEntryJunkyard.push(cookieEntry.unset());
}
// console.log('cookies.js/removeCookieFromDict()> removed cookie key "%s"', cookieKey);
return true;
};
@ -530,6 +529,29 @@ vAPI.cookies.onChanged = function(cookie) {
/******************************************************************************/
// Listen to any change in cookieland, we will update page stats accordingly.
vAPI.cookies.onRemoved = function(cookie) {
var cookieKey = cookieKeyFromCookie(cookie);
if ( removeCookieFromDict(cookieKey) ) {
µm.logger.writeOne('', 'info', 'cookie', i18nCookieDeleteSuccess.replace('{{value}}', cookieKey));
}
};
/******************************************************************************/
// Listen to any change in cookieland, we will update page stats accordingly.
vAPI.cookies.onAllRemoved = function() {
for ( var cookieKey in cookieDict ) {
if ( cookieDict.hasOwnProperty(cookieKey) && removeCookieFromDict(cookieKey) ) {
µm.logger.writeOne('', 'info', 'cookie', i18nCookieDeleteSuccess.replace('{{value}}', cookieKey));
}
}
};
/******************************************************************************/
vAPI.cookies.getAll(addCookiesToDict);
vAPI.cookies.start();

Loading…
Cancel
Save