Skip to content

Commit d433f38

Browse files
committed
Merge pull request EFForg#4059 from semenko/spanning-incognito
Switch to spanning incognito
2 parents 6f31b33 + 4e63c0f commit d433f38

File tree

2 files changed

+64
-2
lines changed

2 files changed

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

chromium/manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": [
77
"rules.js",
88
"util.js",
9-
"background.js"
9+
"background.js",
10+
"incognito-cache-clearing.js"
1011
]
1112
},
1213
"browser_action": {
@@ -25,7 +26,7 @@
2526
"16": "icon16.png",
2627
"48": "icon48.png"
2728
},
28-
"incognito": "split",
29+
"incognito": "spanning",
2930
"manifest_version": 2,
3031
"minimum_chrome_version": "45",
3132
"name": "__MSG_about_ext_name__",

0 commit comments

Comments
 (0)