Skip to content

Commit b6b5923

Browse files
mkaplykaihendry
authored andcommitted
Bring back proxy preferences, cleanup code, closes #49
1 parent 13cc129 commit b6b5923

File tree

1 file changed

+60
-50
lines changed

1 file changed

+60
-50
lines changed

modules/webconvergerModule.jsm

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,69 +6,79 @@ const Cr = Components.results;
66

77
Components.utils.import("resource://gre/modules/Services.jsm");
88

9-
const gPrefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
10-
const gPrefBranch = gPrefService.getBranch(null).QueryInterface(Ci.nsIPrefBranch2);
119
const idleService = Cc["@mozilla.org/widget/idleservice;1"].getService(Ci.nsIIdleService)
1210

1311
var timeout = 0;
1412

1513
var idleObserver = {
16-
observe: function(subject, topic, data) {
17-
idleService.removeIdleObserver(idleObserver, timeout);
18-
var nsIAppStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
19-
nsIAppStartup.quit(nsIAppStartup.eForceQuit);
20-
}
14+
observe: function(subject, topic, data) {
15+
idleService.removeIdleObserver(idleObserver, timeout);
16+
Services.startup.quit(Services.startup.eForceQuit);
17+
}
2118
};
2219

20+
var gProxyUsername = null;
21+
var gProxyPassword = null;
22+
var gForceSafeSearch = false;
2323

2424
try {
25-
timeout = gPrefBranch.getIntPref("extensions.webconverger.kioskresetstation");
26-
if (timeout > 0) {
27-
idleService.addIdleObserver(idleObserver, timeout); // timeout is in minutes
28-
}
25+
timeout = Services.prefs.getIntPref("extensions.webconverger.kioskresetstation");
26+
if (timeout > 0) {
27+
idleService.addIdleObserver(idleObserver, timeout); // timeout is in minutes
28+
}
2929
} catch (ex) {}
3030

3131
var HTTPObserver = {
32-
observe: function observe(subject, topic, data) {
33-
switch (topic) {
34-
case "http-on-modify-request":
35-
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
36-
if (/.*\.google\..*/.test(httpChannel.URI.host)) {
37-
if (/^(\/custom|\/search|\/images\/complete)/.test(httpChannel.URI.path)) {
38-
if (httpChannel.URI.spec.indexOf("safe=strict") == -1) {
39-
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&safe=strict", null, null));
40-
}
41-
}
42-
return;
43-
}
44-
if (/.*\.yahoo\.com/.test(httpChannel.URI.host)) {
45-
if (/^(\/search)/.test(httpChannel.URI.path)) {
46-
if (httpChannel.URI.spec.indexOf("vm=r") == -1) {
47-
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&vm=r", null, null));
48-
}
49-
}
50-
return;
51-
}
52-
if (/.*\.bing\.com/.test(httpChannel.URI.host)) {
53-
if (/^(\/search|\/videos|\/images|\/news)/.test(httpChannel.URI.path)) {
54-
if (httpChannel.URI.spec.indexOf("adlt=strict") == -1) {
55-
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&adlt=strict", null, null));
56-
}
57-
}
58-
return;
59-
}
60-
if (httpChannel.URI.host == "duckduckgo.com") {
61-
if (httpChannel.URI.spec.indexOf("kp=1") == -1) {
62-
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&kp=1", null, null));
63-
}
64-
return;
65-
}
66-
}
67-
}
32+
observe: function observe(subject, topic, data) {
33+
switch (topic) {
34+
case "http-on-modify-request":
35+
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
36+
if (gProxyUsername && gProxyPassword) {
37+
httpChannel.setRequestHeader("Proxy-Authorization", "Basic "+ btoa(gProxyUsername + ":" + gProxyPassword), false);
38+
}
39+
if (!gForceSafeSearch) {
40+
return;
41+
}
42+
if (/.*\.google\..*/.test(httpChannel.URI.host)) {
43+
if (/^(\/custom|\/search|\/images\/complete)/.test(httpChannel.URI.path)) {
44+
if (httpChannel.URI.spec.indexOf("safe=strict") == -1) {
45+
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&safe=strict", null, null));
46+
}
47+
}
48+
return;
49+
}
50+
if (/.*\.yahoo\.com/.test(httpChannel.URI.host)) {
51+
if (/^(\/search)/.test(httpChannel.URI.path)) {
52+
if (httpChannel.URI.spec.indexOf("vm=r") == -1) {
53+
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&vm=r", null, null));
54+
}
55+
}
56+
return;
57+
}
58+
if (/.*\.bing\.com/.test(httpChannel.URI.host)) {
59+
if (/^(\/search|\/videos|\/images|\/news)/.test(httpChannel.URI.path)) {
60+
if (httpChannel.URI.spec.indexOf("adlt=strict") == -1) {
61+
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&adlt=strict", null, null));
62+
}
63+
}
64+
return;
65+
}
66+
if (httpChannel.URI.host == "duckduckgo.com") {
67+
if (httpChannel.URI.spec.indexOf("kp=1") == -1) {
68+
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&kp=1", null, null));
69+
}
70+
return;
71+
}
72+
}
73+
}
6874
}
6975

7076
try {
71-
if (gPrefBranch.getBoolPref("extensions.webconverger.forcesafesearch")) {
72-
Services.obs.addObserver(HTTPObserver, "http-on-modify-request", false);
73-
}
77+
gProxyUsername = Services.prefs.getCharPref("extensions.webconverger.proxyusername");
78+
gProxyPassword = Services.prefs.getCharPref("extensions.webconverger.proxypassword");
79+
} catch (e) {}
80+
try {
81+
gForceSafeSearch = Services.prefs.getBoolPref("extensions.webconverger.forcesafesearch");
7482
} catch (ex) {}
83+
84+
Services.obs.addObserver(HTTPObserver, "http-on-modify-request", false);

0 commit comments

Comments
 (0)