This repository has been archived by the owner on Jul 4, 2022. It is now read-only.
forked from meganz/webclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strg.js
executable file
·112 lines (97 loc) · 3.28 KB
/
strg.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var mIDBPlaceHolder = false;
(function(scope) {
var nsIDOMStorage, nsIDOMSesStorage,
uri = "https://mega.co.nz/",
inPrivateBrowsing,
storageURI,
principal;
try {
const { PrivateBrowsingUtils } = Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm", {});
if ((inPrivateBrowsing = PrivateBrowsingUtils.isWindowPrivate(scope))) {
uri = uri.replace('//','//priv' + (Math.random() * Date.now() & 0x7ffffe).toString(16) + '.');
scope.addEventListener('unload', e => nsIDOMStorage.clear(), false);
}
}
catch(e) {
Cu.reportError(e);
}
storageURI = uri.replace(/[^\w]+/g, '-');
uri = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService)
.newURI(uri, "", null);
principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager)
.getCodebasePrincipal(uri);
try {
nsIDOMStorage = Cc["@mozilla.org/dom/localStorage-manager;1"]
.getService(Ci.nsIDOMStorageManager)
.createStorage(scope, principal, storageURI);
}
catch(e) {
nsIDOMStorage = Cc["@mozilla.org/dom/storagemanager;1"]
.getService(Ci.nsIDOMStorageManager)
.getLocalStorageForPrincipal(principal, storageURI);
}
try {
nsIDOMSesStorage = Cc["@mozilla.org/dom/sessionStorage-manager;1"]
.getService(Ci.nsIDOMStorageManager)
.createStorage(scope, principal, "");
}
catch(e) {}
var nsIDOMStorageProperty = {
value: nsIDOMStorage,
enumerable: true,
configurable: false,
writable: false
};
Object.defineProperty(scope, "localStorage", nsIDOMStorageProperty);
if (nsIDOMSesStorage) {
nsIDOMStorageProperty.value = nsIDOMSesStorage;
}
Object.defineProperty(scope, "sessionStorage", nsIDOMStorageProperty);
Object.defineProperty(scope, "mozIndexedDB", { value : undefined });
function domStorageBridge(aSubject, aTopic, aData) {
if (aTopic === 'dom-storage2-changed'
&& aData === 'localStorage'
&& aSubject.url === storageURI) {
scope.dispatchEvent(aSubject);
}
}
Services.obs.addObserver(domStorageBridge, "dom-storage2-changed", false);
scope.addEventListener('unload', e => Services.obs.removeObserver(domStorageBridge, "dom-storage2-changed"));
if (inPrivateBrowsing) {
scope.Incognito = true;
Object.defineProperty(scope, "indexedDB", { value : undefined });
if (scope.d) console.log('In private browsing mode...', storageURI);
}
else try {
var nsIIDBManager = Cc["@mozilla.org/dom/indexeddb/manager;1"]
.getService(Ci.nsIIndexedDatabaseManager);
mIDBPlaceHolder = {};
nsIIDBManager.initWindowless(mIDBPlaceHolder);
Object.defineProperty(scope, "indexedDB", { value : mIDBPlaceHolder.indexedDB });
Object.defineProperty(scope, "IDBKeyRange", { value : mIDBPlaceHolder.IDBKeyRange });
} catch(e) {
// Bug 921478 - 28.0a1 20131120062258
try {
Cu.importGlobalProperties(['indexedDB']);
} catch(e) {
// Firefox 39.0a1 20150329030238
}
if (typeof indexedDB !== 'undefined') {
try {
Object.defineProperty(scope, "indexedDB",
{
value : {
open: indexedDB.openForPrincipal.bind(indexedDB, principal),
openForPrincipal: indexedDB.openForPrincipal.bind(indexedDB),
deleteDatabase: indexedDB.deleteForPrincipal.bind(indexedDB, principal),
cmp: indexedDB.cmp.bind(indexedDB)
}
});
} catch(e) {
Cu.reportError(e);
}
}
}
})(self);