1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-14 00:05:08 +12:00
This commit is contained in:
gorhill 2016-02-28 16:15:23 -05:00
parent 0031a47721
commit 65924d1be8
3 changed files with 52 additions and 5 deletions

View file

@ -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));
};

View file

@ -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' ) {

View file

@ -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();