Skip to content

Bring back proxy preferences, cleanup code #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 60 additions & 50 deletions modules/webconvergerModule.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,79 @@ const Cr = Components.results;

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

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

var timeout = 0;

var idleObserver = {
observe: function(subject, topic, data) {
idleService.removeIdleObserver(idleObserver, timeout);
var nsIAppStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
nsIAppStartup.quit(nsIAppStartup.eForceQuit);
}
observe: function(subject, topic, data) {
idleService.removeIdleObserver(idleObserver, timeout);
Services.startup.quit(Services.startup.eForceQuit);
}
};

var gProxyUsername = null;
var gProxyPassword = null;
var gForceSafeSearch = false;

try {
timeout = gPrefBranch.getIntPref("extensions.webconverger.kioskresetstation");
if (timeout > 0) {
idleService.addIdleObserver(idleObserver, timeout); // timeout is in minutes
}
timeout = Services.prefs.getIntPref("extensions.webconverger.kioskresetstation");
if (timeout > 0) {
idleService.addIdleObserver(idleObserver, timeout); // timeout is in minutes
}
} catch (ex) {}

var HTTPObserver = {
observe: function observe(subject, topic, data) {
switch (topic) {
case "http-on-modify-request":
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
if (/.*\.google\..*/.test(httpChannel.URI.host)) {
if (/^(\/custom|\/search|\/images\/complete)/.test(httpChannel.URI.path)) {
if (httpChannel.URI.spec.indexOf("safe=strict") == -1) {
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&safe=strict", null, null));
}
}
return;
}
if (/.*\.yahoo\.com/.test(httpChannel.URI.host)) {
if (/^(\/search)/.test(httpChannel.URI.path)) {
if (httpChannel.URI.spec.indexOf("vm=r") == -1) {
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&vm=r", null, null));
}
}
return;
}
if (/.*\.bing\.com/.test(httpChannel.URI.host)) {
if (/^(\/search|\/videos|\/images|\/news)/.test(httpChannel.URI.path)) {
if (httpChannel.URI.spec.indexOf("adlt=strict") == -1) {
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&adlt=strict", null, null));
}
}
return;
}
if (httpChannel.URI.host == "duckduckgo.com") {
if (httpChannel.URI.spec.indexOf("kp=1") == -1) {
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&kp=1", null, null));
}
return;
}
}
}
observe: function observe(subject, topic, data) {
switch (topic) {
case "http-on-modify-request":
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
if (gProxyUsername && gProxyPassword) {
httpChannel.setRequestHeader("Proxy-Authorization", "Basic "+ btoa(gProxyUsername + ":" + gProxyPassword), false);
}
if (!gForceSafeSearch) {
return;
}
if (/.*\.google\..*/.test(httpChannel.URI.host)) {
if (/^(\/custom|\/search|\/images\/complete)/.test(httpChannel.URI.path)) {
if (httpChannel.URI.spec.indexOf("safe=strict") == -1) {
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&safe=strict", null, null));
}
}
return;
}
if (/.*\.yahoo\.com/.test(httpChannel.URI.host)) {
if (/^(\/search)/.test(httpChannel.URI.path)) {
if (httpChannel.URI.spec.indexOf("vm=r") == -1) {
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&vm=r", null, null));
}
}
return;
}
if (/.*\.bing\.com/.test(httpChannel.URI.host)) {
if (/^(\/search|\/videos|\/images|\/news)/.test(httpChannel.URI.path)) {
if (httpChannel.URI.spec.indexOf("adlt=strict") == -1) {
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&adlt=strict", null, null));
}
}
return;
}
if (httpChannel.URI.host == "duckduckgo.com") {
if (httpChannel.URI.spec.indexOf("kp=1") == -1) {
httpChannel.redirectTo(Services.io.newURI(httpChannel.URI.spec + "&kp=1", null, null));
}
return;
}
}
}
}

try {
if (gPrefBranch.getBoolPref("extensions.webconverger.forcesafesearch")) {
Services.obs.addObserver(HTTPObserver, "http-on-modify-request", false);
}
gProxyUsername = Services.prefs.getCharPref("extensions.webconverger.proxyusername");
gProxyPassword = Services.prefs.getCharPref("extensions.webconverger.proxypassword");
} catch (e) {}
try {
gForceSafeSearch = Services.prefs.getBoolPref("extensions.webconverger.forcesafesearch");
} catch (ex) {}

Services.obs.addObserver(HTTPObserver, "http-on-modify-request", false);