-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
71 lines (63 loc) · 2.59 KB
/
background.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
"use strict";
// The following code creates a new class and assigns it to a variable
!function(e, t, s) {
new class {
constructor(e, t, s) {
// creates a new cache object
const o = new Cache;
// binds the following methods to the class
this._utils = e;
this._onBeforeRequest = this._onBeforeRequest.bind(this);
this._onBeforeSendHeaders = this._onBeforeSendHeaders.bind(this);
this._parseResponse = this._parseResponse.bind(this);
this._prepareResponse = this._prepareResponse.bind(this);
this._validateUrl = this._validateUrl.bind(this);
this._isLocalhostDebug = this._isLocalhostDebug.bind(this);
this._isLocalhost = this._isLocalhost.bind(this);
this._handleBlockpageResponse = this._handleBlockpageResponse.bind(this);
this._handleDebugPageResponse = this._handleDebugPageResponse.bind(this);
this._resolve = this._resolve.bind(this);
this._start = this._start.bind(this);
this._stop = this._stop.bind(this);
// assigns the config variable to the class
this._config = s;
// assigns the serial number to the class
s.deviceSerialNumber.then(e => {
this.serialNo = e;
});
// assigns the _getData method to the class
this._getData = ((e) => this._prepareResponse(this._parseResponse(this._resolve(e.domainName)), e.url));
this._getData = this._getData.bind(this);
this._cache = o.get(this._getData);
this._evictCache = o.evictCache;
this.appId = t.ids[chrome.runtime.id];
// checks the platform the extension is running on
chrome.runtime.getPlatformInfo(e => {
if ("cros" === e.os) {
this.init();
this.start_google_analytics("UA-129271400-1");
} else {
this._updateExtensionIcon(false, () => Logger.info(`Umbrella Chromebook client is not supported for '${e.os}'. DNS protection shall be disabled.`));
}
});
}
// initializes the extension
init() {
Logger.info("Waiting to start the extension.");
chrome.alarms.onAlarm.addListener(e => {
if ("evictCache" === e.name) {
this._evictCache();
}
});
// adds listeners for online and offline events
window.addEventListener("online", e => {
Logger.info("Connected to internet once again.");
this._start();
this._updateExtensionIcon(true);
});
window.addEventListener("offline", e => {
Logger.info("Lost internet connection.");
this._stop();
this._updateExtensionIcon(false);
});
// checks if the appId variable is