diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 41a0d13..ced1f89 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -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)); }; diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 286a9eb..76860c9 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -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' ) { diff --git a/src/js/cookies.js b/src/js/cookies.js index 95fb2c3..8ab3168 100644 --- a/src/js/cookies.js +++ b/src/js/cookies.js @@ -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();