|
63 | 63 | }
|
64 | 64 | }
|
65 | 65 |
|
| 66 | + if (!ns.contextStore) { // it could have been already retrieved by LifeCycle |
| 67 | + let contextStoreData = (await Storage.get("sync", "contextStore")).contextStore; |
| 68 | + if (contextStoreData) { |
| 69 | + ns.contextStore = new ContextStore(contextStoreData); |
| 70 | + await ns.contextStore.updateContainers(); |
| 71 | + } else { |
| 72 | + log("No container data found. Initializing new empty policies.") |
| 73 | + identities = await browser.contextualIdentities.query({}); |
| 74 | + policies = new Object(); |
| 75 | + identities.forEach(({cookieStoreId}) => { |
| 76 | + policies[cookieStoreId] = new Policy(); |
| 77 | + }) |
| 78 | + ns.contextStore = new ContextStore(({policies})); |
| 79 | + await ns.contextStore.updateContainers(); |
| 80 | + await ns.saveContextStore(); |
| 81 | + } |
| 82 | + } |
| 83 | + |
66 | 84 | let {isTorBrowser} = ns.local;
|
67 | 85 | Sites.onionSecure = isTorBrowser;
|
68 | 86 |
|
|
160 | 178 | tabId = -1
|
161 | 179 | }) {
|
162 | 180 | let policy = ns.policy.dry(true);
|
| 181 | + let contextStore = ns.contextStore.dry(true); |
163 | 182 | let seen = tabId !== -1 ? await ns.collectSeen(tabId) : null;
|
164 | 183 | let xssUserChoices = await XSS.getUserChoices();
|
165 | 184 | await Messages.send("settings", {
|
166 | 185 | policy,
|
| 186 | + contextStore, |
167 | 187 | seen,
|
168 | 188 | xssUserChoices,
|
169 | 189 | local: ns.local,
|
|
221 | 241 | var ns = {
|
222 | 242 | running: false,
|
223 | 243 | policy: null,
|
| 244 | + contextStore: null, |
224 | 245 | local: null,
|
225 | 246 | sync: null,
|
226 | 247 | initializing: null,
|
|
233 | 254 | return !this.isEnforced(request.tabId) || this.policy.can(request.url, capability, request.documentURL);
|
234 | 255 | },
|
235 | 256 |
|
| 257 | + getPolicy(cookieStoreId){ |
| 258 | +// debug("get policy", cookieStoreId, ns.policy, ns.contextStore); |
| 259 | + if (ns.contextStore.policies.hasOwnProperty(cookieStoreId)) { |
| 260 | + let currentPolicy = ns.contextStore.policies[cookieStoreId]; |
| 261 | + debug("has cookiestore", cookieStoreId, currentPolicy); |
| 262 | + if (currentPolicy) return currentPolicy; |
| 263 | + } |
| 264 | + debug("default cookiestore", cookieStoreId); |
| 265 | + return ns.policy; |
| 266 | + }, |
| 267 | + |
236 | 268 | computeChildPolicy({url, contextUrl}, sender) {
|
237 | 269 | let {tab, frameId} = sender;
|
238 |
| - let policy = ns.policy; |
| 270 | + let cookieStoreId = (tab)? tab.cookieStoreId : "default"; |
| 271 | + var policy = ns.policy; |
| 272 | + debug("computing policy", cookieStoreId, ns.contextStore); |
| 273 | + if ( |
| 274 | + cookieStoreId && |
| 275 | + !cookieStoreId.toLowerCase().includes("default") && //exclude firefox-default |
| 276 | + ns.contextStore && |
| 277 | + ns.contextStore.policies.hasOwnProperty(cookieStoreId) |
| 278 | + ) { |
| 279 | + policy = ns.contextStore.policies[cookieStoreId]; |
| 280 | + } |
| 281 | + debug("chose policy", policy); |
239 | 282 | let {isTorBrowser} = ns.local;
|
240 | 283 | if (!policy) {
|
241 | 284 | console.log("Policy is null, initializing: %o, sending fallback.", ns.initializing);
|
|
314 | 357 | await Storage.set("sync", {
|
315 | 358 | policy: this.policy.dry()
|
316 | 359 | });
|
317 |
| - await browser.webRequest.handlerBehaviorChanged() |
| 360 | + await browser.webRequest.handlerBehaviorChanged(); |
318 | 361 | }
|
319 | 362 | return this.policy;
|
320 | 363 | },
|
321 | 364 |
|
| 365 | + async saveContextStore() { |
| 366 | + if (this.contextStore) { |
| 367 | + await Storage.set("sync", { |
| 368 | + contextStore: this.contextStore.dry() |
| 369 | + }); |
| 370 | + await browser.webRequest.handlerBehaviorChanged(); |
| 371 | + } |
| 372 | + return this.contextStore; |
| 373 | + }, |
| 374 | + |
322 | 375 |
|
323 | 376 |
|
324 | 377 | async save(obj) {
|
|
0 commit comments