forked from EFForg/https-everywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincognito-cache-clearing.js
More file actions
61 lines (53 loc) · 1.81 KB
/
incognito-cache-clearing.js
File metadata and controls
61 lines (53 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"use strict";
// This file keeps track of incognito sessions, and clears any caches after
// an entire incognito session is closed (i.e. all incognito windows are closed).
let incognito_session_exists = false;
/**
* Detect if an incognito session is created, so we can clear caches when it's destroyed.
*
* @param window: A standard Window object.
*/
function detect_incognito_creation(window) {
if (window.incognito === true) {
incognito_session_exists = true;
}
}
/**
* Clear any caches we have.
* Called if an incognito session is destroyed.
*/
function destroy_caches() {
log(DBUG, "Destroying caches.");
all_rules.cookieHostCache.clear();
all_rules.ruleCache.clear();
}
/**
* Check if any incognito window still exists. If not, destroy caches.
* @param arrayOfWindows: A array of all open Window objects.
*/
function check_for_incognito_session(arrayOfWindows) {
for (let window of arrayOfWindows) {
if (window.incognito === true) {
// An incognito window still exists, so don't destroy caches yet.
return;
}
}
// All incognito windows have been closed.
incognito_session_exists = false;
destroy_caches();
}
/**
* If a window is destroyed, and an incognito session existed, see if it still does.
*
* @param windowId: Ignored.
*/
function detect_incognito_destruction(windowId) {
if (incognito_session_exists) {
// Are any current windows incognito?
chrome.windows.getAll(check_for_incognito_session);
}
}
// Listen to window creation, so we can detect if an incognito window is created
chrome.windows.onCreated.addListener(detect_incognito_creation);
// Listen to window destruction, so we can clear caches if all incognito windows are destroyed
chrome.windows.onRemoved.addListener(detect_incognito_destruction);