aboutsummaryrefslogtreecommitdiffstats
path: root/src/chrome/content
diff options
context:
space:
mode:
authorjmccrohan <jmccrohan@gmail.com>2011-04-06 15:29:05 +0100
committerjmccrohan <jmccrohan@gmail.com>2011-04-06 15:29:05 +0100
commit67810a8a0b08fc8697ee8fc8843af3757c12a421 (patch)
treeb9117ba19c4eff31666aa76010a69a9950623457 /src/chrome/content
parentf5d92fb14f7bfc5105700e60fb6fc35fb4e31401 (diff)
downloadMultiproxy-Switch-67810a8a0b08fc8697ee8fc8843af3757c12a421.tar.gz
Initial Commit
Diffstat (limited to 'src/chrome/content')
-rw-r--r--src/chrome/content/about.js97
-rw-r--r--src/chrome/content/contents.rdf50
-rw-r--r--src/chrome/content/datasource.js386
-rw-r--r--src/chrome/content/dialogs/about.xul38
-rw-r--r--src/chrome/content/dialogs/editcommon.js18
-rw-r--r--src/chrome/content/dialogs/editproxy.js311
-rw-r--r--src/chrome/content/dialogs/editproxy.xul119
-rw-r--r--src/chrome/content/dialogs/manager.xul36
-rw-r--r--src/chrome/content/globals.js152
-rw-r--r--src/chrome/content/icons/Thumbs.dbbin0 -> 9216 bytes
-rw-r--r--src/chrome/content/icons/arrow-dn.gifbin0 -> 56 bytes
-rw-r--r--src/chrome/content/icons/check.pngbin0 -> 751 bytes
-rw-r--r--src/chrome/content/icons/cross.pngbin0 -> 951 bytes
-rw-r--r--src/chrome/content/icons/isp.pngbin0 -> 1150 bytes
-rw-r--r--src/chrome/content/icons/new.pngbin0 -> 544 bytes
-rw-r--r--src/chrome/content/icons/options.pngbin0 -> 1150 bytes
-rw-r--r--src/chrome/content/icons/pencil.pngbin0 -> 810 bytes
-rw-r--r--src/chrome/content/options/options.js80
-rw-r--r--src/chrome/content/options/options.xul32
-rw-r--r--src/chrome/content/proxy.js1080
-rw-r--r--src/chrome/content/proxy.xul125
-rw-r--r--src/chrome/content/proxy_moz.xul118
-rw-r--r--src/chrome/content/proxy_thunder.xul60
-rw-r--r--src/chrome/content/tabmanager.js146
24 files changed, 2848 insertions, 0 deletions
diff --git a/src/chrome/content/about.js b/src/chrome/content/about.js
new file mode 100644
index 0000000..f8370b4
--- /dev/null
+++ b/src/chrome/content/about.js
@@ -0,0 +1,97 @@
+
+function open_tab(UrlToGoTo) {
+ if( MPS_isThunderBird() ) {
+ var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance()
+ .QueryInterface(Components.interfaces.nsIMessenger);
+
+ messenger.launchExternalURL(UrlToGoTo);
+ } else {
+ var navWindow;
+
+ // Try to get the most recently used browser window
+ try {
+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ navWindow = wm.getMostRecentWindow("navigator:browser");
+ } catch(ex) {}
+
+ if (navWindow) { // Open the URL in most recently used browser window
+ if ("delayedOpenTab" in navWindow) {
+ navWindow.delayedOpenTab(UrlToGoTo);
+ } else if ("loadURI" in navWindow) {
+ navWindow.loadURI(UrlToGoTo);
+ } else {
+ navWindow._content.location.href = UrlToGoTo;
+ }
+ } else { // If there is no recently used browser window open new browser window with the URL
+ var ass = Components.classes["@mozilla.org/appshell/appShellService;1"]
+ .getService(Components.interfaces.nsIAppShellService);
+ var win = ass.hiddenDOMWindow;
+
+ win.openDialog("chrome://navigator/content/navigator.xul", "",
+ "chrome,all, dialog=no", UrlToGoTo );
+ }
+ }
+ /*
+ var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);
+ uri.spec = aURL;
+ var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"].getService(Components.interfaces.nsIExternalProtocolService);
+ protocolSvc.loadUrl(uri);
+ */
+}
+
+
+const SEAMONKEY_ID = "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}";
+const THUNDERBIRD_ID = "{3550f703-e582-4d05-9a08-453d09bdfdc6}";
+function MPS_isThunderBird() {
+ var id;
+ if("@mozilla.org/xre/app-info;1" in Components.classes) {
+ // running under Mozilla 1.8 or later
+ id = Components.classes["@mozilla.org/xre/app-info;1"]
+ .getService(Components.interfaces.nsIXULAppInfo).ID;
+ } else {
+ try {
+ id = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefBranch)
+ .getCharPref("app.id");
+ } catch(e) {
+ }
+ }
+ if ( id != null && id == THUNDERBIRD_ID ) {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+function MPS_isSunbirdOrLightning() {
+ var id;
+ if("@mozilla.org/xre/app-info;1" in Components.classes) {
+ // running under Mozilla 1.8 or later
+ id = Components.classes["@mozilla.org/xre/app-info;1"]
+ .getService(Components.interfaces.nsIXULAppInfo).ID;
+ } else {
+ try {
+ id = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefBranch)
+ .getCharPref("app.id");
+ } catch(e) {
+ }
+ }
+
+ // check if this is Sunbird
+ if ( id != null && id == "{718e30fb-e89b-41dd-9da7-e25a45638b28}" ) {
+ return true;
+ }
+ else if ( id != null && id == THUNDERBIRD_ID ) {
+ var em = Components.classes["@mozilla.org/extensions/manager;1"]
+ .getService(Components.interfaces.nsIExtensionManager);
+ var addon = em.getItemForID("{e2fda1a4-762b-4020-b5ad-a41df1933103}");
+ // check to see if the version attribute exists (if not, then the addon doesn't exist)
+ if ( addon != null && (addon.version != null && addon.version != "" )) {
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/src/chrome/content/contents.rdf b/src/chrome/content/contents.rdf
new file mode 100644
index 0000000..90450c4
--- /dev/null
+++ b/src/chrome/content/contents.rdf
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+
+<RDF:RDF xmlns:chrome="http://www.mozilla.org/rdf/chrome#"
+ xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+
+ <RDF:Seq about="urn:mozilla:package:root">
+ <RDF:li resource="urn:mozilla:package:mproxy"/>
+ </RDF:Seq>
+
+ <RDF:Description about="urn:mozilla:package:mproxy"
+ chrome:author="Based on SwitchProxy by Jeremy Gillick"
+ chrome:authorURL="http://mcfreds.blogspot.com/"
+ chrome:description="Multiproxy Switch lets you set local proxy in Firefox and Thunderbird, and do more."
+ chrome:displayName="Multiproxy Switch"
+ chrome:extension="true"
+ chrome:name="Multiproxy Switch"
+ chrome:settingsURL="chrome://mproxy/content/options/options.xul"
+ chrome:uninstallFunc="mproxy_uninstall">
+ </RDF:Description>
+
+ <RDF:Seq about="urn:mozilla:overlays">
+ <!-- Firefox -->
+ <RDF:li resource="chrome://browser/content/browser.xul"/>
+
+ <!-- Mozilla -->
+ <RDF:li resource="chrome://navigator/content/navigator.xul"/>
+
+ <!-- Thunderbird -->
+ <RDF:li resource="chrome://messenger/content/mailWindowOverlay.xul"/>
+ <RDF:li resource="chrome://messenger/content/messengercompose/messengercompose.xul"/>
+ </RDF:Seq>
+
+ <!-- Firefox -->
+ <RDF:Seq about="chrome://browser/content/browser.xul">
+ <RDF:li>chrome://mproxy/content/proxy.xul</RDF:li>
+ </RDF:Seq>
+
+ <!-- Mozilla -->
+ <RDF:Seq about="chrome://navigator/content/navigator.xul">
+ <RDF:li>chrome://mproxy/content/proxy_moz.xul</RDF:li>
+ </RDF:Seq>
+
+ <!-- Thunderbird -->
+ <RDF:Seq about="chrome://messenger/content/mailWindowOverlay.xul">
+ <RDF:li>chrome://mproxy/content/proxy_thunder.xul</RDF:li>
+ </RDF:Seq>
+ <RDF:Seq about="chrome://messenger/content/messengercompose/messengercompose.xul">
+ <RDF:li>chrome://mproxy/content/proxy_thunder.xul</RDF:li>
+ </RDF:Seq>
+</RDF:RDF>
diff --git a/src/chrome/content/datasource.js b/src/chrome/content/datasource.js
new file mode 100644
index 0000000..e31a1ec
--- /dev/null
+++ b/src/chrome/content/datasource.js
@@ -0,0 +1,386 @@
+//DataSource
+var gSProxyDs = null;
+var gSProxyRdf = null;
+var gSProxyRdfC = null;
+var gSProxyRDFUtil = null
+
+//Initializes the RDF Datasource components
+function mproxy_ds_initDataSource(){
+ try{
+
+ // Datasource URI
+ if(gSProxyRdfDataSouce == "rdf:local-store"){
+ var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
+ var io = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
+ file = file.get("PrefD", Components.interfaces.nsILocalFile);
+ file.appendRelativePath("multiproxy.rdf");
+
+ io = io.newFileURI(file);
+ gSProxyRdfDataSouce = io.spec;
+ }
+
+ if(gSProxyRdf == null)
+ gSProxyRdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
+ if(gSProxyDs == null)
+ gSProxyDs = gSProxyRdf.GetDataSourceBlocking(gSProxyRdfDataSouce);
+ if(gSProxyRDFUtil == null)
+ gSProxyRDFUtil = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils);
+ if(gSProxyRdfC == null){
+ gSProxyRdfC = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
+
+ //Get or Add Sequence
+ try{
+ gSProxyRdfC.Init(gSProxyDs, gSProxyRdf.GetResource(gSProxyRdfRoot)); //Get
+ }catch(err){
+ gSProxyRdfC = gSProxyRDFUtil.MakeSeq(gSProxyDs, gSProxyRdf.GetResource(gSProxyRdfRoot)); //Create
+ }
+ }
+
+ }catch(err){ throw "(mproxy_ds_initDataSource)\n" + err; }
+}
+
+//Add RDF Observer
+function mproxy_ds_addObserver(oObserver){
+ mproxy_ds_initDataSource();
+
+ try{
+ gSProxyDs.AddObserver(oObserver);
+ }catch(err){throw "(mproxy_ds_addObserver)\n" + err}
+}
+
+//Returns resource for the given uri
+function mproxy_ds_getElement(sUri){
+ mproxy_ds_initDataSource();
+
+ try{
+ return gSProxyRdf.GetResource(sUri);
+ }catch(err){ throw "(mproxy_ds_getElement)\n" + err; }
+}
+
+//Duplicate of mproxy_ds_getElement
+function mproxy_ds_getResource(sAbout){
+ return mproxy_ds_getElement(sAbout)
+}
+
+//Returns array of all mproxy Element URIs
+// array[index] = uri
+function mproxy_ds_getAllElements(){
+ mproxy_ds_initDataSource();
+
+ var aOut = new Array();
+ var aElements = gSProxyRdfC.GetElements();
+ while(aElements.hasMoreElements()){
+ var oRes = aElements.getNext();
+ oRes = oRes.QueryInterface(Components.interfaces.nsIRDFResource);
+
+ aOut[aOut.length] = oRes.Value;
+ }
+
+ return aOut;
+}
+
+//Returns an associative array of properties (attributes) contained in sUri element
+// array[propName] = oRes
+function mproxy_ds_getPropertiesFor(sUri){
+ mproxy_ds_initDataSource();
+
+ var aOut = new Array();
+
+ //Get an array of elements for sAbout
+ try{
+ var oRes = mproxy_ds_getElement(sUri);
+ var oTrgts = gSProxyDs.ArcLabelsOut(oRes);
+ while(oTrgts.hasMoreElements()){
+ var oTrgt = oTrgts.getNext();
+
+ if (oTrgt instanceof Components.interfaces.nsIRDFResource){
+ var sTrgName = oTrgt.Value.substring(gSProxyRdfNodeUriRoot.length + 1); //return node name without URI
+ aOut[sTrgName] = oTrgt;
+ }
+ }
+ }catch(err){throw "(mproxy_ds_getPropertiesFor)\n" + err}
+
+ return aOut;
+}
+
+//Similar to 'mproxy_ds_getPropertiesFor' however returns uri=>literal_object_value
+// array[uri] = oLiteral
+function mproxy_ds_getPropertyValuesFor(sUri){
+ mproxy_ds_initDataSource();
+
+ var aOut = new Array();
+
+ //Get an array of elements for sAbout
+ try{
+ var oRes = mproxy_ds_getElement(sUri);
+ var oTrgts = gSProxyDs.ArcLabelsOut(oRes, true);
+ while(oTrgts.hasMoreElements()){
+ var oTrgt = oTrgts.getNext();
+
+ if (oTrgt instanceof Components.interfaces.nsIRDFResource){
+ aOut[oTrgt.Value] = mproxy_ds_getValueFor(oRes, oTrgt);
+ }
+ }
+ }catch(err){throw "(mproxy_ds_getPropertyValuesFor)\n" + err}
+
+ return aOut;
+}
+
+//Returns element that has this property/value
+function mproxy_ds_getElementForValue(sPropertyUri, sValue){
+ mproxy_ds_initDataSource();
+
+ try{
+ var oValue = gSProxyRdf.GetLiteral(sValue);
+ var oProp = gSProxyRdf.GetResource(sPropertyUri);
+ var oSubject = gSProxyDs.GetSource(oProp, oValue, true);
+
+ return oSubject;
+
+ }catch(err){throw "(mproxy_ds_getElementForValue)\n" + err}
+
+ return null;
+}
+
+// Returns all elements that has this property/value
+function mproxy_ds_getElementsForValue(sPropertyUri, sValue){
+ mproxy_ds_initDataSource();
+
+ var aOut = new Array();
+
+ try{
+ var oValue = gSProxyRdf.GetLiteral(sValue);
+ var oProp = gSProxyRdf.GetResource(sPropertyUri);
+ var aSubject = gSProxyDs.GetSources(oProp, oValue, true);
+ var oSubject = null
+
+ while(aSubject.hasMoreElements()){
+ oSubject = aSubject.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
+ aOut[aOut.length] = oSubject;
+ }
+
+ }catch(err){throw "(mproxy_ds_getElementsForValue)\n" + err}
+
+ return aOut;
+}
+
+//Change element's URI
+function mproxy_ds_changeElementUri(oRes, sNewUri){
+ mproxy_ds_initDataSource();
+
+ try{
+
+ //Get All Properties for element
+ var aProps = mproxy_ds_getPropertyValuesFor(oRes.Value);
+
+ //Remove Element
+ mproxy_ds_removeElement(oRes.Value);
+
+ //Create element again with new URI
+ var newElem = gSProxyRdf.GetResource(sNewUri);
+ gSProxyRdfC.AppendElement(newElem);
+ for(sProp in aProps){
+ gSProxyDs.Assert(newElem, gSProxyRdf.GetResource(sProp), gSProxyRdf.GetLiteral(aProps[sProp]), true);
+ }
+
+ }catch(err){throw "(mproxy_ds_changeElementUri)\n" + err}
+}
+
+//Add element with given sUri, returns added resource
+function mproxy_ds_addElement(sUri){
+ mproxy_ds_initDataSource();
+
+ try{
+
+ return oRes = gSProxyRdfC.AppendElement(gSProxyRdf.GetResource(sUri));
+
+ }catch(err){throw "(mproxy_ds_addElement)\n" + err}
+}
+
+//Remove Element for sUri
+function mproxy_ds_removeElement(sUri){
+ mproxy_ds_initDataSource();
+
+ try{
+ var oRes = gSProxyRdf.GetResource(sUri);
+
+ //Remove All Archs
+ // Loop for duplicates
+ var aArchs = null;
+ var hasArchs = true;
+ while(hasArchs){
+ aArchs = gSProxyDs.ArcLabelsOut(oRes);
+ hasArchs = aArchs.hasMoreElements();
+ while(aArchs.hasMoreElements()){
+ oArch = aArchs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
+
+ //Remove
+ gSProxyDs.Unassert(oRes, oArch, gSProxyDs.GetTarget(oRes, oArch, true));
+ }
+ }
+
+ //Remove Element
+ gSProxyRdfC.RemoveElement(oRes, true);
+ }catch(err){throw "(mproxy_ds_removeElement)\n" + err}
+}
+
+//Remove property (sUri) from oRes
+function mproxy_ds_removeProperty(sUri, oRes, sValue){
+ mproxy_ds_initDataSource();
+
+ try{
+ var oPred = gSProxyRdf.GetResource(sUri);
+ var aValues = mproxy_ds_getValuesFor(oRes, oPred);
+
+ if(typeof(sValue) == 'undefined'){
+ // Make sure to delete all properites of this sUri
+ for(var i = 0; i < aValues.length; i++){
+ gSProxyDs.Unassert(oRes, oPred, gSProxyRdf.GetLiteral(aValues[i]) );
+ }
+ }
+ else{
+ // Only delete the property with this value
+ sValue = gSProxyRdf.GetLiteral(sValue);
+ if(gSProxyDs.HasAssertion(oRes, oPred, sValue, true)){
+ gSProxyDs.Unassert(oRes, oPred, sValue);
+ }
+ }
+
+ }catch(err){throw "(mproxy_ds_removeProperty)\n" + err}
+}
+
+//Does URI Exist
+function mproxy_ds_doesProxyElementExist(sProxyUri){
+ mproxy_ds_initDataSource();
+
+ try{
+ var aElems = mproxy_ds_getAllElements();
+ for(var e = 0; e < aElems.length; e++){
+ if(aElems[e] == sProxyUri)
+ return true;
+ }
+ }catch(err){throw "(mproxy_ds_doesElementExist)\n" + err}
+}
+
+//Get Index of URI
+function mproxy_ds_indexOf(sProxyUri){
+ mproxy_ds_initDataSource();
+
+ try{
+ return gSProxyRdfC.IndexOf(mproxy_ds_getResource(sProxyUri));
+ }catch(err){throw "(mproxy_ds_indexOf)\n" + err}
+}
+
+//Rename oProp's URI to sNewUri
+function mproxy_ds_renamePropertyUri(oRes, oProp, sNewUri){
+ mproxy_ds_initDataSource();
+
+ try{
+ var sValue = gSProxyDs.GetTarget(oRes, oProp, true).QueryInterface(Components.interfaces.nsIRDFLiteral);
+
+ gSProxyDs.Unassert(oRes, oProp, gSProxyDs.GetTarget(oRes, oProp, true));
+ gSProxyDs.Assert(oRes, gSProxyRdf.GetResource(sNewUri), sValue, true);
+
+ }catch(err){throw "(mproxy_ds_renamePropertyUri)\n" + err}
+}
+
+//Add Property oProp to oRes
+function mproxy_ds_addProperty(oRes, oProp, sValue, overwriteExisting){
+ mproxy_ds_initDataSource();
+
+ try{
+ //Don't overwrite it this property exists
+ if(!overwriteExisting && gSProxyDs.hasArcOut(oRes, oProp))
+ return;
+
+ //Add
+ gSProxyDs.Assert(oRes, oProp, gSProxyRdf.GetLiteral(sValue), true);
+ }catch(err){throw "(mproxy_ds_addProperty)\n" + err}
+}
+
+//Change Property value for sPropUri in oRes
+function mproxy_ds_changePropertyValue(oRes, sPropUri, sValue){
+ mproxy_ds_initDataSource();
+
+ try{
+ var oProp = gSProxyRdf.GetResource(sPropUri);
+
+ //Get old value
+ var sOld = mproxy_ds_getValueFor(oRes, oProp);
+
+ //Change
+ gSProxyDs.Change(oRes, oProp, gSProxyRdf.GetLiteral(sOld), gSProxyRdf.GetLiteral(sValue));
+
+ }catch(err){throw "(mproxy_ds_changePropertyValue)\n" + err}
+}
+
+//Get Property Value for Property oProp
+function mproxy_ds_getValueFor(oRes, oProp){
+ mproxy_ds_initDataSource();
+
+ try{
+ oTrgt = gSProxyDs.GetTarget(oRes, oProp, true);
+
+ if(oTrgt instanceof Components.interfaces.nsIRDFLiteral){
+ return oTrgt.Value;
+ }
+
+ }catch(err){throw "(mproxy_ds_getValueFor)\n" + err}
+
+ return null;
+}
+
+//Get All Property Values for Property oProp
+// This is similiar to mproxy_ds_getValueFor
+// except it returns ALL values for oProp in an array
+// array[index] = sValue
+function mproxy_ds_getValuesFor(oRes, oProp){
+ mproxy_ds_initDataSource();
+
+ var aOut = new Array();
+
+ try{
+ var aTrgts = gSProxyDs.GetTargets(oRes, oProp, true)
+ var oTrgt = null;
+
+ while(aTrgts.hasMoreElements()){
+ oTrgt = aTrgts.getNext()
+
+ if(oTrgt instanceof Components.interfaces.nsIRDFLiteral){
+ aOut[aOut.length] = oTrgt.Value;
+ }
+ }
+ }catch(err){throw "(mproxy_ds_getValueFor)\n" + err}
+
+ return aOut;
+}
+
+//Does Property/Value exist in oRes
+function mproxy_ds_doesPropValueExist(oRes, sPropUri, sValue){
+ mproxy_ds_initDataSource();
+
+ try{
+ var oProp = gSProxyRdf.GetResource(sPropUri);
+ var aValues = mproxy_ds_getValuesFor(oRes, oProp);
+
+ //Find in array
+ for(var i = 0; i < aValues.length; i++){
+ if(aValues[i] == sValue)
+ return true;
+ }
+
+ }catch(err){throw "(mproxy_ds_doesPropValueExist)\n" + err}
+
+ return false;
+}
+
+/*
+* GET PROPERTIES
+*/
+
+ //Get RDF Container
+ function mproxy_ds_getRDFContainer(){
+ mproxy_ds_initDataSource();
+ return gSProxyRdf;
+ }
+
diff --git a/src/chrome/content/dialogs/about.xul b/src/chrome/content/dialogs/about.xul
new file mode 100644
index 0000000..3363c81
--- /dev/null
+++ b/src/chrome/content/dialogs/about.xul
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+
+<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
+
+<!DOCTYPE dialog SYSTEM "chrome://mproxy/locale/locale.dtd">
+
+<dialog buttons="accept"
+ id="aboutmproxy"
+ ondialogaccept="return true"
+ title="&about.title;"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="mproxy_setVersion()" >
+
+ <script type="application/x-javascript" src="chrome://mproxy/content/globals.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/about.js"></script>
+ <script language="JavaScript">
+ <![CDATA[
+ function mproxy_setVersion(){
+ var oLabel = document.getElementById("mproxy-version");
+
+ if(oLabel != null && gmproxy_Version != null){
+ oLabel.value += " "+ gmproxy_Version;
+ }
+ }
+ ]]>
+ </script>
+
+ <vbox style="width: 200px;">
+ <hbox>
+ <label value="&common.product.name;" style="font-weight: bold; margin-right: 2px;" />
+ <label value="v" id="mproxy-version" style="margin-left: 2px;" />
+ </hbox>
+ <label value="Based on SwitchProxy by Jeremy Gillick" />
+ <label value="http://multiproxyswitch.blogspot.com"
+ style="color: #0000FF; text-decoration: underline; cursor: pointer;"
+ onclick="open_tab('http://multiproxyswitch.blogspot.com');" />
+ </vbox>
+</dialog> \ No newline at end of file
diff --git a/src/chrome/content/dialogs/editcommon.js b/src/chrome/content/dialogs/editcommon.js
new file mode 100644
index 0000000..c24b619
--- /dev/null
+++ b/src/chrome/content/dialogs/editcommon.js
@@ -0,0 +1,18 @@
+//Has Special Chars
+// + returns true if it only
+// + contains allowed chars
+function mproxy_allowedChars(str){
+ //var regex = new RegExp("[\\s\\.a-zA-Z0-9_]", "g"); //This does not allow utf-8 text!
+ var regex = new RegExp("[(){}\\\[\\\]<>,;:/~`'\"*?^$#&\\t\\n\\r\\\\]", "g");
+ return !regex.test(str);
+}
+
+// Used to test strings
+// + converts space to underscore
+// + and converts to lowercase
+function mproxy_simplify(str){
+ str = str.replace(new RegExp("\\s{2,}", "g"), " ");
+ str = str.replace(new RegExp("\\s", "g"), "_");
+ str = str.toLowerCase();
+ return str;
+} \ No newline at end of file
diff --git a/src/chrome/content/dialogs/editproxy.js b/src/chrome/content/dialogs/editproxy.js
new file mode 100644
index 0000000..3e01c58
--- /dev/null
+++ b/src/chrome/content/dialogs/editproxy.js
@@ -0,0 +1,311 @@
+
+var gIsEdit = false;
+var gList;
+var mproxyURI;
+var mproxy;
+var mproxyConfig;
+var mproxyNameField;
+var gFromProxyManager;
+
+function mproxy_initVals(){
+
+
+ //Set Globals
+ mproxyNameField = document.getElementById("proxy-name");
+
+ //Edit
+ if(window.arguments.length > 1 && window.arguments[0] == "edit" && !mproxy_isEmpty(window.arguments[1])){
+
+ //Proxy URI
+ mproxyURI = window.arguments[1];
+
+ gIsEdit = true;
+ try{
+ mproxy = mproxy_ds_getResource(mproxyURI);
+
+ //Load Fields
+ var mproxyConfig = mproxy_ds_getPropertyValuesFor(mproxyURI);
+ for(key in gmproxy_options){
+ var oField = document.getElementById(key);
+ var sValue = mproxyConfig[gSProxyRdfNodeUriRoot + "#" + key];
+
+ oField.value = sValue;
+ }
+
+ //Label
+ mproxyNameField.value = mproxyConfig[gSProxyRdfNodeName];
+
+ //Set Socks Radio
+ oSocks = document.getElementById("networkProxySOCKSVersion");
+ if(oSocks.value == "4")
+ oSocks.selectedItem = document.getElementById("networkProxySOCKSVersion4");
+ else
+ oSocks.selectedItem = document.getElementById("networkProxySOCKSVersion5");
+
+ //Share one proxy
+ oShare = document.getElementById("networkProxyHTTPShare");
+ if (oShare.value == "true")
+ //oShare.checked = true;
+ document.getElementById("networkProxyHTTPShare").checked = oShare.value;
+
+ else
+ oShare.checked = false;
+
+ //Sharing box
+ //if (document.getElementById("networkProxyHTTPShare").value == "true");
+
+
+
+ }catch(err){ alert(mproxy_getString("error.unknown")); self.close(); }
+ }
+
+ //Enable Fields
+
+ mproxy_enableShareSettingOnStart();
+ mproxy_enableOptions();
+
+ // Thunderbird
+ if(navigator.userAgent.search(/Thunderbird/gi) > -1){
+ document.getElementById("ftp_row").style.display = "none";
+ document.getElementById("gopher_row").style.display = "none";
+ document.getElementById("none_row").style.display = "none";
+ document.getElementById("none_example_row").style.display = "none";
+ }
+}
+
+function mproxy_saveProxy(){
+
+ try{
+
+ /*
+ * Validation
+ */
+ //Empty
+ if(mproxyNameField.value == ""){
+ alert(mproxy_getString("error.add.empty"));
+
+ mproxyNameField.focus();
+ mproxyNameField.setSelectionRange(0, mproxyNameField.textLength);
+
+ return false;
+ }
+ //Special Chars
+ else if(!mproxy_allowedChars(mproxyNameField.value)){
+ alert(mproxy_getString("error.add.invalid"));
+ return false;
+ }
+ //Can't be named 'None' or 'tor'
+ else if(mproxy_simplify(mproxyNameField.value) == mproxy_simplify(mproxy_getString("common.proxy.none"))){
+ alert(mproxy_getString("error.add.duplicate"));
+ return false;
+ }
+ //else if((!gIsEdit) && (mproxy_simplify(mproxyNameField.value) == mproxy_simplify("tor"))){
+ // alert(mproxy_getString("error.add.duplicate"));
+ // return false;
+ // }
+ // else if((!gIsEdit) && (mproxy_simplify(mproxyNameField.value) == mproxy_simplify(mproxy_getString("common.proxy.tor")))){
+ // alert(mproxy_getString("error.add.duplicate"));
+ // return false;
+ // }
+
+ //Is This a Duplicate Label?
+ var oTestProxy = mproxy_ds_getElementForValue(gSProxyRdfNodeName, mproxyNameField.value);
+ if(oTestProxy != null && (!gIsEdit || oTestProxy.Value != mproxy.Value)){
+ alert(mproxy_getString("error.add.duplicate"));
+ return false;
+ }
+
+ //save share setting
+ document.getElementById("networkProxyHTTPShare").value = document.getElementById("networkProxyHTTPShare").checked;
+
+ /*
+ * Edit
+ */
+ if(gIsEdit){
+ //Update RDF Properties
+ for(key in gmproxy_options){
+ mproxy_ds_changePropertyValue(mproxy, (gSProxyRdfNodeUriRoot + "#" + key), document.getElementById(key).value);
+ }
+
+ //Update Name
+ mproxy_ds_changePropertyValue(mproxy, gSProxyRdfNodeName, mproxyNameField.value);
+ }
+ /*
+ * Add
+ */
+ else{
+ var sProxyUri = opener.mproxy_getUniqueProxyUri();
+ var oProxy = mproxy_ds_getResource(sProxyUri);
+
+ //Add Element
+ mproxy_ds_addElement(sProxyUri);
+
+ //Add Properties
+ for(key in gmproxy_options){
+ var oProp = mproxy_ds_getResource(gSProxyRdfNodeUriRoot + "#" + key);
+ mproxy_ds_addProperty(oProxy, oProp, document.getElementById(key).value, true);
+ }
+
+ //Add Name
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeName), mproxyNameField.value, true);
+ }
+ /*
+ * Finish
+ */
+ opener.mproxy_populateList();
+
+ if(gIsEdit){
+
+ //Is this proxy is in use, refresh proxy
+ var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
+ if(oPrefs.prefHasUserValue("mproxy.proxy.current")
+ && oPrefs.getCharPref("mproxy.proxy.current") == mproxy.Value){
+
+ opener.mproxy_doCommand("mproxy_setProxy()");
+ }
+ //If not in use, select proxy
+ else{
+ opener.mproxy_doCommand("mproxy_selectItem('"+ mproxyNameField.value +"')");
+ }
+
+ //alert("Proxy Info Changed");
+ }
+ else{
+ opener.mproxy_doCommand("mproxy_selectItem('"+ mproxyNameField.value +"')");
+ //alert("Proxy Added");
+ }
+
+
+ }catch(e){
+ alert(mproxy_getString("error.unknown") +"\n("+ e +")");
+ return;
+ }
+
+ mproxy_openerFocus()
+ return true;
+}
+
+
+//Enable or disable Manual
+// + config options
+function mproxy_enableOptions(){
+
+ var disable = !(document.getElementById("networkProxyType").value == "1"); //if 1 then manual is selected
+
+ //Set Radios
+ oType = document.getElementById("networkProxyType");
+ if(!disable){
+ oType.selectedItem = document.getElementById("type-manual-radio");
+
+ }
+ else{
+ oType.selectedItem = document.getElementById("type-auto-radio");
+ }
+ if (document.getElementById("networkProxyType").value == "2"){
+
+ //Manual Options
+ document.getElementById("networkProxyHTTP").disabled = true;
+ document.getElementById("networkProxyHTTP_Port").disabled = true;
+ document.getElementById("networkProxyHTTPShare").disabled = true;
+ document.getElementById("networkProxySSL").disabled = true;
+ document.getElementById("networkProxySSL_Port").disabled = true;
+ document.getElementById("networkProxyFTP").disabled = true;
+ document.getElementById("networkProxyFTP_Port").disabled = true;
+ document.getElementById("networkProxyGopher").disabled = true;
+ document.getElementById("networkProxyGopher_Port").disabled = true;
+ document.getElementById("networkProxySOCKS").disabled = true;
+ document.getElementById("networkProxySOCKS_Port").disabled = true;
+ document.getElementById("networkProxySOCKSVersion4").disabled = true;
+ document.getElementById("networkProxySOCKSVersion5").disabled = true;
+ document.getElementById("networkProxyNone").disabled = true;
+
+ //Auto
+ document.getElementById("networkProxyAutoconfigURL").disabled = false;
+
+}
+else{
+//When manual setting is checked
+ mproxy_enableShareSetting();
+ document.getElementById("networkProxyHTTP").disabled = false;
+ document.getElementById("networkProxyHTTP_Port").disabled = false;
+ document.getElementById("networkProxyHTTPShare").disabled = false;
+ document.getElementById("networkProxyNone").disabled = false;
+ document.getElementById("networkProxyAutoconfigURL").disabled = true;
+}
+}
+//Set setting on start-up
+function mproxy_enableShareSettingOnStart(){
+var disabletextbox = (document.getElementById("networkProxyHTTPShare").value == "true");
+
+ document.getElementById("networkProxySSL").disabled = disabletextbox;
+ document.getElementById("networkProxySSL_Port").disabled = disabletextbox;
+ document.getElementById("networkProxyFTP").disabled = disabletextbox;
+ document.getElementById("networkProxyFTP_Port").disabled = disabletextbox;
+ document.getElementById("networkProxyGopher").disabled = disabletextbox;
+ document.getElementById("networkProxyGopher_Port").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKS").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKS_Port").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKSVersion4").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKSVersion5").disabled = disabletextbox;
+
+}
+//Disable below when check sharing setting
+function mproxy_enableShareSetting(){
+var disabletextbox = (document.getElementById("networkProxyHTTPShare").checked == true);
+
+ document.getElementById("networkProxySSL").disabled = disabletextbox;
+ document.getElementById("networkProxySSL_Port").disabled = disabletextbox;
+ document.getElementById("networkProxyFTP").disabled = disabletextbox;
+ document.getElementById("networkProxyFTP_Port").disabled = disabletextbox;
+ document.getElementById("networkProxyGopher").disabled = disabletextbox;
+ document.getElementById("networkProxyGopher_Port").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKS").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKS_Port").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKSVersion4").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKSVersion5").disabled = disabletextbox;
+
+ //if (document.getElementById("networkProxyHTTPShare").value == "true"){
+ //mproxy_copySetting();
+//}
+}
+function mproxy_enableShareSettingSelect(){
+var disabletextbox = (document.getElementById("networkProxyHTTPShare").checked == true);
+
+ document.getElementById("networkProxySSL").disabled = disabletextbox;
+ document.getElementById("networkProxySSL_Port").disabled = disabletextbox;
+ document.getElementById("networkProxyFTP").disabled = disabletextbox;
+ document.getElementById("networkProxyFTP_Port").disabled = disabletextbox;
+ document.getElementById("networkProxyGopher").disabled = disabletextbox;
+ document.getElementById("networkProxyGopher_Port").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKS").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKS_Port").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKSVersion4").disabled = disabletextbox;
+ document.getElementById("networkProxySOCKSVersion5").disabled = disabletextbox;
+
+ //if (document.getElementById("networkProxyHTTPShare").value == "true"){
+ mproxy_copySetting();
+//}
+}
+//Copy http proxy
+function mproxy_copySetting(){
+if (document.getElementById("networkProxyHTTPShare").checked == true){
+ document.getElementById("networkProxySSL").value = document.getElementById("networkProxyHTTP").value;
+ document.getElementById("networkProxySSL_Port").value = document.getElementById("networkProxyHTTP_Port").value;
+ document.getElementById("networkProxyFTP").value = document.getElementById("networkProxyHTTP").value;
+ document.getElementById("networkProxyFTP_Port").value = document.getElementById("networkProxyHTTP_Port").value;
+ document.getElementById("networkProxyGopher").value = document.getElementById("networkProxyHTTP").value;
+ document.getElementById("networkProxyGopher_Port").value = document.getElementById("networkProxyHTTP_Port").value;
+ document.getElementById("networkProxySOCKS").value = document.getElementById("networkProxyHTTP").value;
+ document.getElementById("networkProxySOCKS_Port").value = document.getElementById("networkProxyHTTP_Port").value;
+}
+else{
+ document.getElementById("networkProxySSL").value = "";
+ document.getElementById("networkProxySSL_Port").value = "";
+ document.getElementById("networkProxyFTP").value = "";
+ document.getElementById("networkProxyFTP_Port").value = "";
+ document.getElementById("networkProxyGopher").value = "";
+ document.getElementById("networkProxyGopher_Port").value = "";
+ document.getElementById("networkProxySOCKS").value = "";
+ document.getElementById("networkProxySOCKS_Port").value = "";
+}
+}
diff --git a/src/chrome/content/dialogs/editproxy.xul b/src/chrome/content/dialogs/editproxy.xul
new file mode 100644
index 0000000..1a1cb01
--- /dev/null
+++ b/src/chrome/content/dialogs/editproxy.xul
@@ -0,0 +1,119 @@
+<?xml version="1.0"?>
+
+<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
+
+<!DOCTYPE dialog SYSTEM "chrome://mproxy/locale/locale.dtd">
+
+<dialog buttons="accept, cancel"
+ id="mproxyCookieDialog"
+ ondialogaccept="return mproxy_saveProxy()"
+ ondialogcancel="mproxy_openerFocus(); return true;"
+ onload="mproxy_initVals();"
+ title="&add.title;"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script type="application/x-javascript" src="chrome://mproxy/content/globals.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/datasource.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/dialogs/editcommon.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/dialogs/editproxy.js"></script>
+
+ <hbox>
+ <label value="&add.proxyLabel;" id="proxy-name-label" />
+ <textbox id="proxy-name" size="30" flex="0" />
+ </hbox>
+ <groupbox>
+ <radiogroup id="networkProxyType" value="1" persist="value">
+ <radio value="1" label="&add.option.manual;" oncommand="mproxy_enableOptions();" id="type-manual-radio" />
+
+ <grid class="indent" flex="1">
+ <columns>
+ <column/>
+ <column flex="1"/>
+ </columns>
+
+ <rows>
+ <row align="center">
+ <hbox align="center" pack="end">
+ <label value="&add.http.proxy.label;" accesskey="&add.http.proxy.key;" control="networkProxyHTTP"/>
+ </hbox>
+ <hbox align="center">
+ <textbox id="networkProxyHTTP" flex="1" oninput="mproxy_copySetting();"/>
+ <label value="&add.port.label;" control="networkProxyHTTP_Port"/>
+ <textbox id="networkProxyHTTP_Port" size="5" oninput="mproxy_copySetting();"/>
+ </hbox>
+ </row>
+
+<row align="center">
+<hbox align="center" pack="end">
+<label value=""/>
+</hbox>
+<hbox align="center">
+<checkbox id="networkProxyHTTPShare" label ="&add.sharing.proxy.label;" checked="false" oncommand="mproxy_enableShareSettingSelect();"/>
+</hbox>
+</row>
+
+ <row align="center">
+ <hbox align="center" pack="end">
+ <label value="&add.ssl.proxy.label;" accesskey="&add.ssl.proxy.key;" control="networkProxySSL"/>
+ </hbox>
+ <hbox align="center">
+ <textbox id="networkProxySSL" flex="1"/>
+ <label value="&add.port.label;" control="networkProxySSL_Port"/>
+ <textbox id="networkProxySSL_Port" size="5"/>
+ </hbox>
+ </row>
+ <row align="center" id="ftp_row">
+ <hbox align="center" pack="end">
+ <label value="&add.ftp.proxy.label;" accesskey="&add.ftp.proxy.key;" control="networkProxyFTP"/>
+ </hbox>
+ <hbox align="center">
+ <textbox id="networkProxyFTP" flex="1"/>
+ <label value="&add.port.label;" control="networkProxyFTP_Port"/>
+ <textbox id="networkProxyFTP_Port" size="5"/>
+ </hbox>
+ </row>
+ <row align="center" id="gopher_row">
+ <hbox align="center" pack="end">
+ <label value="&add.gopher.proxy.label;" accesskey="&add.gopher.proxy.key;" control="networkProxyGopher"/>
+ </hbox>
+ <hbox align="center">
+ <textbox id="networkProxyGopher" flex="1"/>
+ <label value="&add.port.label;" control="networkProxyGopher_Port"/>
+ <textbox id="networkProxyGopher_Port" size="5"/>
+ </hbox>
+ </row>
+ <row align="center">
+ <hbox align="center" pack="end">
+ <label value="&add.socks.proxy.label;" accesskey="&add.socks.proxy.key;" control="networkProxySOCKS"/>
+ </hbox>
+ <hbox align="center">
+ <textbox id="networkProxySOCKS" flex="1"/>
+ <label value="&add.port.label;" control="networkProxySOCKS_Port"/>
+ <textbox id="networkProxySOCKS_Port" size="5"/>
+ </hbox>
+ </row>
+ <row>
+ <spacer/>
+ <radiogroup id="networkProxySOCKSVersion" orient="horizontal">
+ <radio id="networkProxySOCKSVersion4" value="4" label="&add.socks.option.v4;" />
+ <radio id="networkProxySOCKSVersion5" value="5" label="&add.socks.option.v5;" />
+ </radiogroup>
+ </row>
+
+ <row align="center" id="none_row">
+ <hbox align="center" pack="end">
+ <label value="&add.none.label;" accesskey="&add.none.key;" control="networkProxyNone"/>
+ </hbox>
+ <textbox id="networkProxyNone" value="localhost, 127.0.0.1" />
+ </row>
+ <row id="none_example_row">
+ <spacer/>
+ <label value="&add.none.example;" control="networkProxyNone"/>
+ </row>
+ </rows>
+ </grid>
+ <radio value="2" label="&add.option.auto;" oncommand="mproxy_enableOptions();" id="type-auto-radio" />
+ <textbox id="networkProxyAutoconfigURL" size="50" flex="0" disabled="true" />
+ </radiogroup>
+ </groupbox>
+</dialog> \ No newline at end of file
diff --git a/src/chrome/content/dialogs/manager.xul b/src/chrome/content/dialogs/manager.xul
new file mode 100644
index 0000000..3cd0cdd
--- /dev/null
+++ b/src/chrome/content/dialogs/manager.xul
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<!DOCTYPE dialog SYSTEM "chrome://mproxy/locale/locale.dtd">
+
+<dialog buttons="accept"
+ id="mproxyCookieDialog"
+ ondialogaccept="mproxy_managerClose(); mproxy_openerFocus(); return true;"
+ ondialogcancel="mproxy_openerFocus(); return true;"
+ onload="mproxy_initProxy();"
+ title="&common.manage.label;" persist="height, width"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script type="application/x-javascript" src="chrome://mproxy/content/globals.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/datasource.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/proxy.js"></script>
+ <script>
+ <![CDATA[
+ function mproxy_managerClose(){
+ try{
+ var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
+ oPrefs.setIntPref("mproxy.proxy.rdf.lastupdate", (new Date()).getTime());
+ } catch(e){ alert(e); }
+ }
+ ]]>
+ </script>
+
+ <hbox align="top" flex="1" style="overflow: auto;">
+ <listbox id="manage-proxy-list" flex="2" rows="10"></listbox>
+ <vbox>
+ <button id="new-button" label=" &common.add.label;" oncommand="mproxy_editProxyDialog(true)" image="chrome://mproxy/content/icons/new.png" />
+ <button id="edit-button" label=" &common.edit.label;" oncommand="mproxy_editProxyDialog(false)" image="chrome://mproxy/content/icons/pencil.png" />
+ <button id="remove-button" label=" &common.remove.label;" oncommand="mproxy_removeProxy(false)" image="chrome://mproxy/content/icons/cross.png" />
+ </vbox>
+ </hbox>
+</dialog> \ No newline at end of file
diff --git a/src/chrome/content/globals.js b/src/chrome/content/globals.js
new file mode 100644
index 0000000..ba46c76
--- /dev/null
+++ b/src/chrome/content/globals.js
@@ -0,0 +1,152 @@
+
+var gSProxyRdfDataSouce = "rdf:local-store";
+const gSProxyRdfRoot = "http://mozilla.org/package/mproxy/rdf/all";
+const gSProxyRdfNodeUriRoot = "http://mozilla.org/package/mproxy/rdf"
+const gSProxyRdfNodeId = gSProxyRdfNodeUriRoot+ "#id";
+const gSProxyRdfNodeName = gSProxyRdfNodeUriRoot+ "#name";
+const gSProxyRdfNodeProxy = gSProxyRdfNodeUriRoot+ "#proxy";
+
+const gmproxy_Version = "1.33";
+const gmproxy_DownloadSite = "http://switchproxy.googlepages.com";
+
+var gSProxyStrBundle = null;
+
+var gmproxy_options = new Array();
+ gmproxy_options['networkProxyType'] = "network.proxy.type";
+ gmproxy_options['networkProxyHTTP'] = "network.proxy.http";
+ gmproxy_options['networkProxyHTTP_Port'] = "network.proxy.http_port";
+ gmproxy_options['networkProxyHTTPShare'] = "network.proxy.share_proxy_settings";
+ gmproxy_options['networkProxySSL'] = "network.proxy.ssl";
+ gmproxy_options['networkProxySSL_Port'] = "network.proxy.ssl_port";
+ gmproxy_options['networkProxyFTP'] = "network.proxy.ftp";
+ gmproxy_options['networkProxyFTP_Port'] = "network.proxy.ftp_port";
+ gmproxy_options['networkProxyGopher'] = "network.proxy.gopher";
+ gmproxy_options['networkProxyGopher_Port'] = "network.proxy.gopher_port";
+ gmproxy_options['networkProxySOCKS'] = "network.proxy.socks";
+ gmproxy_options['networkProxySOCKS_Port'] = "network.proxy.socks_port";
+ gmproxy_options['networkProxySOCKSVersion'] = "network.proxy.socks_version";
+ gmproxy_options['networkProxyNone'] = "network.proxy.no_proxies_on";
+ gmproxy_options['networkProxyAutoconfigURL'] = "network.proxy.autoconfig_url";
+
+var gmproxy_options_defaults = new Array();
+ gmproxy_options_defaults['networkProxyType'] = 1;
+ gmproxy_options_defaults['networkProxyHTTP'] = "";
+ gmproxy_options_defaults['networkProxyHTTP_Port'] = 0;
+ gmproxy_options_defaults['networkProxyHTTPShare'] = false;
+ gmproxy_options_defaults['networkProxySSL'] = "";
+ gmproxy_options_defaults['networkProxySSL_Port'] = 0;
+ gmproxy_options_defaults['networkProxyFTP'] = "";
+ gmproxy_options_defaults['networkProxyFTP_Port'] = 0;
+ gmproxy_options_defaults['networkProxyGopher'] = "";
+ gmproxy_options_defaults['networkProxyGopher_Port'] = 0;
+ gmproxy_options_defaults['networkProxySOCKS'] = "127.0.0.1";
+ gmproxy_options_defaults['networkProxySOCKS_Port'] = 9050;
+ gmproxy_options_defaults['networkProxySOCKSVersion'] = 5;
+ gmproxy_options_defaults['networkProxyNone'] = "localhost, 127.0.0.1";
+ gmproxy_options_defaults['networkProxyAutoconfigURL'] = "";
+
+/*
+* Global Functions
+*/
+ //Get String Bundle
+ function mproxy_getString(sKey){
+ try{
+
+ if(gSProxyStrBundle == null){
+ var oBundle = Components.classes['@mozilla.org/intl/stringbundle;1'].getService(Components.interfaces.nsIStringBundleService);
+ gSProxyStrBundle = oBundle.createBundle('chrome://mproxy/locale/locale.properties');
+ }
+
+ return gSProxyStrBundle.GetStringFromName(sKey);
+
+ }catch(err){}
+
+ return "";
+ }
+
+ // Focus Opener
+ function mproxy_openerFocus(){
+ try{
+ if(opener != null && opener.focus != null){
+ opener.focus();
+ }
+ } catch(err) { }
+ }
+
+ //Is string empty
+ function mproxy_isEmpty(str){
+ var oRegExp = new RegExp("([^\\s])", "g");
+
+ if(str == "")
+ return true;
+
+ return !oRegExp.test(str);
+ }
+
+ // Does this sValue exist in oList
+ function mproxy_existsInList(oList, sValue){
+
+ for(var i = 0; i < oList.getRowCount(); i++){
+ if(oList.getItemAtIndex(i).value == sValue){
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ // Trims space from both sides of str
+ function mproxy_trim(str){
+ str = str.replace(new RegExp("^[\\s\\n\\r]*", "g"), "");
+ str = str.replace(new RegExp("[\\s\\n\\r]*$", "g"), "");
+
+ return str;
+ }
+
+ // Splits a domain or IP from it's port number
+ // returns array[1]
+ // array[0] = (String) Domain or IP
+ // array[1] = (String) Port Number
+ function mproxy_splitDomain(sDomain){
+ var aOut = new Array();
+ var iPort = -1;
+
+ if( (iPort = sDomain.indexOf(":")) > -1){
+ aOut[0] = sDomain.substring(0, iPort);
+ aOut[1] = sDomain.substring(iPort + 1);
+ }
+ else{
+ aOut[0] = sDomain;
+ aOut[1] = "80";
+ }
+
+ return aOut;
+ }
+
+ // Returns if str is valid domain or IP address
+ function mproxy_isValidDomain(str){
+
+ var oValidDomain = new RegExp("^[a-zA-Z0-9][a-zA-Z0-9-\\.:]{0,63}[a-zA-Z0-9]?$", "i");
+
+ return oValidDomain.test(str);
+ }
+
+/*
+* Debug Functions
+*/
+ //Get Properties for an object
+ function mproxy_debug_getProps(obj){
+ var props = "";
+ var i = -1;
+ for(prop in obj){
+ i++;
+ props += prop + " | ";
+
+ if(i > 3){
+ i = -1;
+ props += "\n";
+ }
+ }
+ alert(props);
+ }
+
diff --git a/src/chrome/content/icons/Thumbs.db b/src/chrome/content/icons/Thumbs.db
new file mode 100644
index 0000000..20e4541
--- /dev/null
+++ b/src/chrome/content/icons/Thumbs.db
Binary files differ
diff --git a/src/chrome/content/icons/arrow-dn.gif b/src/chrome/content/icons/arrow-dn.gif
new file mode 100644
index 0000000..62edbfd
--- /dev/null
+++ b/src/chrome/content/icons/arrow-dn.gif
Binary files differ
diff --git a/src/chrome/content/icons/check.png b/src/chrome/content/icons/check.png
new file mode 100644
index 0000000..59b12c3
--- /dev/null
+++ b/src/chrome/content/icons/check.png
Binary files differ
diff --git a/src/chrome/content/icons/cross.png b/src/chrome/content/icons/cross.png
new file mode 100644
index 0000000..ed39e19
--- /dev/null
+++ b/src/chrome/content/icons/cross.png
Binary files differ
diff --git a/src/chrome/content/icons/isp.png b/src/chrome/content/icons/isp.png
new file mode 100644
index 0000000..2ede6f5
--- /dev/null
+++ b/src/chrome/content/icons/isp.png
Binary files differ
diff --git a/src/chrome/content/icons/new.png b/src/chrome/content/icons/new.png
new file mode 100644
index 0000000..acaf5f4
--- /dev/null
+++ b/src/chrome/content/icons/new.png
Binary files differ
diff --git a/src/chrome/content/icons/options.png b/src/chrome/content/icons/options.png
new file mode 100644
index 0000000..9469f4e
--- /dev/null
+++ b/src/chrome/content/icons/options.png
Binary files differ
diff --git a/src/chrome/content/icons/pencil.png b/src/chrome/content/icons/pencil.png
new file mode 100644
index 0000000..7422be2
--- /dev/null
+++ b/src/chrome/content/icons/pencil.png
Binary files differ
diff --git a/src/chrome/content/options/options.js b/src/chrome/content/options/options.js
new file mode 100644
index 0000000..ecd4ea9
--- /dev/null
+++ b/src/chrome/content/options/options.js
@@ -0,0 +1,80 @@
+
+var oMain = null;
+var inMozOptions = false;
+
+function initOptions(){
+ try{
+
+ //Prefs
+ var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
+
+ //Get Opener
+ if(opener.mproxy_menuShowing){
+ oMain = opener;
+ }
+ else if(opener.parent.opener && opener.parent.opener.mproxy_menuShowing){
+ oMain = opener.parent.opener
+ inMozOptions = true;
+ }
+
+ //Prefill
+ if(oPrefs.prefHasUserValue("mproxy.clear.cookies"))
+ document.getElementById("mproxy.clear.cookies").checked = oPrefs.getBoolPref("mproxy.clear.cookies");
+ if(oPrefs.prefHasUserValue("mproxy.reload.tab"))
+ document.getElementById("mproxy.reload.tab").checked = oPrefs.getBoolPref("mproxy.reload.tab");
+ if(oPrefs.prefHasUserValue("mproxy.display.context"))
+ document.getElementById("mproxy.display.context").checked = oPrefs.getBoolPref("mproxy.display.context");
+ if(oPrefs.prefHasUserValue("mproxy.display.statusbar"))
+ document.getElementById("mproxy.display.statusbar").checked = oPrefs.getBoolPref("mproxy.display.statusbar");
+
+ /*if(oPrefs.prefHasUserValue("mproxy.tabs.manager"))
+ document.getElementById("mproxy.tabs.manager").checked = oPrefs.getBoolPref("mproxy.tabs.manager");*/
+
+ //Set menushowing options
+ if(oMain != null){
+ document.getElementById("mproxy.display.toolbar").checked = oMain.mproxy_menuShowing("toolbar");
+ }
+ else{
+ document.getElementById("mproxy.display.toolbar").style.display = "none";
+ }
+
+ // Thunderbird
+ if(navigator.userAgent.search(/Thunderbird/gi) > -1){
+ document.getElementById("mproxy.display.context").style.display = "none";
+ document.getElementById("mproxy.display.toolbar").style.display = "none";
+ }
+
+ }catch(err){ alert(mproxy_getString("error.unknown") +"\n"+ err); }
+}
+
+function saveOptions(){
+
+ try{
+
+ //Save
+ var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
+
+ oPrefs.setBoolPref("mproxy.clear.cookies", document.getElementById("mproxy.clear.cookies").checked);
+ oPrefs.setBoolPref("mproxy.reload.tab", document.getElementById("mproxy.reload.tab").checked);
+ oPrefs.setBoolPref("mproxy.display.statusbar", document.getElementById("mproxy.display.statusbar").checked);
+
+ // Not Thunderbird
+ if(navigator.userAgent.search(/Thunderbird/gi) < 0){
+ oPrefs.setBoolPref("mproxy.display.context", document.getElementById("mproxy.display.context").checked);
+
+ if(oMain != null){
+ oPrefs.setBoolPref("mproxy.display.toolbar", document.getElementById("mproxy.display.toolbar").checked);
+ }
+ }
+
+
+ if(oMain != null)
+ oMain.mproxy_showMenus();
+
+ }catch(err){ alert(mproxy_getString("error.unknown") +"\n"+err); }
+
+ if(oMain != null && !inMozOptions)
+ oMain.focus();
+
+ return true;
+}
diff --git a/src/chrome/content/options/options.xul b/src/chrome/content/options/options.xul
new file mode 100644
index 0000000..f555dd5
--- /dev/null
+++ b/src/chrome/content/options/options.xul
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+
+<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
+
+<!DOCTYPE dialog SYSTEM "chrome://mproxy/locale/locale.dtd">
+
+<dialog buttons="accept"
+ id="mproxy-options-dialog"
+ ondialogaccept="return saveOptions();"
+ onload="initOptions()"
+ title="&prefs.title;"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script type="application/x-javascript" src="chrome://mproxy/content/globals.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/options/options.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/proxy.js"></script>
+
+ <groupbox style="width: 200px;">
+ <caption label="&prefs.general;"/>
+ <checkbox id="mproxy.display.toolbar" label="&prefs.general.toolbar;" checked="false" />
+ <checkbox id="mproxy.display.context" label="&prefs.general.context;" checked="false" />
+ <checkbox id="mproxy.display.statusbar" label="&prefs.general.statusbar;" checked="true" />
+ <!-- <checkbox id="mproxy.tabs.manager" label="Allow the use of different proxies in different tabs & windows." checked="true" /> -->
+ </groupbox>
+
+ <groupbox style="width: 200px;">
+ <caption label="&prefs.switch;"/>
+ <checkbox id="mproxy.clear.cookies" label="&prefs.switch.cookies;" checked="false" />
+ <checkbox id="mproxy.reload.tab" label="&prefs.switch.refresh;" checked="true" />
+ </groupbox>
+
+</dialog>
diff --git a/src/chrome/content/proxy.js b/src/chrome/content/proxy.js
new file mode 100644
index 0000000..8c94d0f
--- /dev/null
+++ b/src/chrome/content/proxy.js
@@ -0,0 +1,1080 @@
+/*
+* 2008
+* Copyright Steve McFred and Jeremy Gillick (author of SwitchProxy)
+*/
+
+/*
+*
+* ERROR CODES
+* 100 - 149: mproxy_setProxy()
+* 150 - 199: mproxy_removeProxy()
+* 200 - 249: mproxy_clearCookies()
+* 250 - 299: mproxy_editProxyDialog()
+* 300 - 349: mproxy_manualUpgradCheck()
+*
+*/
+
+var gSwitchP_List;
+var gSwitchP_ListPopup;
+var gSwitchP_ContextList;
+var gSwitchP_StatusBar;
+var gSwitchP_MenuList;
+var gSwitchP_ManageList;
+var gSwitchP_ElementList;
+var gSwitchP_ElementButton;
+var gSwitchP_LastItem;
+var gSwitchP_ProxyCount = 0;
+var gSwitchP_InManager = false;
+var gSwitchP_Loaded = false;
+var gSwitchP_Cycle = null;
+var gSwitchP_CommandEnd = true;
+var gSwitchP_Prefs = null;
+var gSwitchP_NoneLabel = "None";
+
+var gSwitchPTabMgr = null;
+
+function mproxy_initProxy(event){
+
+ window.removeEventListener("load", mproxy_initProxy, true);
+
+ if(!gSwitchP_Loaded){
+
+ gSwitchP_List = document.getElementById('proxy-list')
+ gSwitchP_ListPopup = document.getElementById('proxy-list-popup');
+ gSwitchP_ManageList = document.getElementById('manage-proxy-list');
+ gSwitchP_ContextList = document.getElementById('context-proxy-list');
+ gSwitchP_StatusBar = document.getElementById('mproxy-status');
+ gSwitchP_MenuList = document.getElementById('mproxy-menu-list');
+ gSwitchP_ElementList = document.getElementById('mproxy-element-list');
+ gSwitchP_ElementButton = document.getElementById('mproxy-element-button');
+ gSwitchP_Prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
+
+ gSwitchP_NoneLabel = mproxy_getString("common.proxy.none");
+
+ //Is in Proxy Manager
+ if(gSwitchP_ManageList != null){
+ gSwitchP_InManager = true;
+ gSwitchP_List = gSwitchP_ManageList;
+ }
+
+ mproxy_showMenus(true);
+
+ //Cleanup RDF File
+ mproxy_cleanupRdf();
+
+ //Populate Proxy List
+ mproxy_populateList();
+
+ //Set Last Proxy Selected
+ if(gSwitchP_List != null)
+ gSwitchP_LastItem = gSwitchP_List.selectedItem;
+
+ //Add Preferences Listener
+ var oProxyObserver = {
+ observe : function(subject, topic, data){ mproxy_populateList(); }
+ };
+ var oMenuObserver = {
+ observe : function(subject, topic, data){ mproxy_showMenus(false); }
+ };
+ //var oPrefBranch = Components.classes["@mozilla.org/preferences-service;1"].createInstance(Components.interfaces.nsIPrefBranchInternal);
+ ////oPrefBranch.addObserver("network.proxy", oPrefObserver, false);
+ //oPrefBranch.addObserver("mproxy.proxy.rdf.lastupdate", oProxyObserver, false);
+ //oPrefBranch.addObserver("mproxy.display", oMenuObserver, false);
+
+ //if(navigator.userAgent.search(/Thunderbird/gi) > -1){
+ // oPrefBranch = Components.classes["@mozilla.org/preferences-service;1"].createInstance(Components.interfaces.nsIPrefBranchInternal);
+ //}
+ //Else{
+oPrefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
+//}
+oPrefBranch.addObserver("mproxy.proxy.rdf.lastupdate", oProxyObserver, false);
+//oPrefBranch.addObserver("mproxy.display", oMenuObserver, false);
+//oPrefBranch.addObserver("network.proxy", oPrefObserver, false);
+
+ //Auto-Update Anonymous Proxy Lists (after 10 minutes)
+ //gAnonUpdateTimout = setTimeout("mproxy_anon_autoUpdateLists()", 600000);
+
+ // Start Anon Rotation
+ //setTimeout("mproxy_anon_nextProxy()", 1000);
+
+ gSwitchP_Loaded = true;
+ }
+}
+
+// Return Tab Manager
+function mproxy_getTabManager(){
+ return gSwitchPTabMgr;
+}
+
+//Used for debugging removed
+
+
+//Displays the context menu based on what
+// the user selects in the options
+function mproxy_showMenus(onStartup){
+ try{
+ //Show/Hide menus
+ var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
+
+ // Status Bar
+ var isHidden = (oPrefs.prefHasUserValue("mproxy.display.statusbar") && !oPrefs.getBoolPref("mproxy.display.statusbar"))
+ document.getElementById("mproxy-status").setAttribute("collapsed", isHidden);
+
+ // If not thunderbird
+ if(navigator.userAgent.search(/Thunderbird/gi) < 0){
+
+ //Context
+ var isHidden = (oPrefs.prefHasUserValue("mproxy.display.context") && !oPrefs.getBoolPref("mproxy.display.context"))
+ document.getElementById("mproxy-context-menu").setAttribute("collapsed", isHidden);
+ document.getElementById("mproxy-context-separator").setAttribute("hidden", isHidden);
+
+ //Toolbar
+ if(onStartup){
+ oPrefs.setBoolPref("mproxy.display.toolbar", (!document.getElementById("proxy-toolbar").getAttribute("collapsed")));
+ }
+ else{
+ var isHidden = (oPrefs.prefHasUserValue("mproxy.display.toolbar") && !oPrefs.getBoolPref("mproxy.display.toolbar"))
+ document.getElementById("proxy-toolbar").setAttribute("collapsed", isHidden);
+ }
+ }
+
+ }catch(err){}
+}
+
+// Show Element List
+function mproxy_showElementList(event){
+
+ var oContext = document.getElementById('context-proxy-list');
+ if(oContext == null){
+ return;
+ }
+
+}
+
+//Returns is the entered menu is currently showing
+// values are 'context' or 'toolbar'
+function mproxy_menuShowing(sMenu){
+ var oObj = null;
+
+ if(sMenu == "context"){
+ oObj = document.getElementById("mproxy-context-menu");
+ }
+ else if(sMenu == "toolbar"){
+ oObj = document.getElementById("proxy-toolbar");
+ }
+
+ if(oObj == null)
+ return false;
+
+ return !eval(oObj.getAttribute("collapsed"));
+}
+
+
+//Clears current Proxy List
+function mproxy_clearList(){
+
+ gSwitchP_ProxyCount = 0;
+
+ //Toolbar List
+ if(!gSwitchP_InManager && gSwitchP_List != null && gSwitchP_List.removeAllItems && !gSwitchP_List.open){
+ gSwitchP_List.removeAllItems();
+ }
+ //Manage Proxy Box
+ if(gSwitchP_InManager && gSwitchP_List != null){
+ aNodes = gSwitchP_List.childNodes;
+ for(var i = aNodes.length-1; i >= 0; i--){
+ gSwitchP_List.removeChild(aNodes[i]);
+ }
+ }
+ //Context List
+ if(gSwitchP_ContextList != null){
+ aNodes = gSwitchP_ContextList.childNodes;
+ for(var i = aNodes.length-1; i >= 0; i--){
+ gSwitchP_ContextList.removeChild(aNodes[i]);
+ }
+ }
+ //Toolbar Element List
+ if(gSwitchP_ElementList != null){
+ aNodes = gSwitchP_ElementList.childNodes;
+ for(var i = aNodes.length-1; i >= 0; i--){
+ if(aNodes[i].getAttribute("class") == "proxy-menu-item")
+ gSwitchP_ElementList.removeChild(aNodes[i]);
+ }
+ }
+ // Tools Menu List
+ if(gSwitchP_MenuList != null){
+ aNodes = gSwitchP_MenuList.childNodes;
+ for(var i = aNodes.length-1; i >= 0; i--){
+ if(aNodes[i].getAttribute("class") == "proxy-menu-item")
+ gSwitchP_MenuList.removeChild(aNodes[i]);
+ }
+ }
+}
+
+//Add Item to lists
+function mproxy_appendToList(sLabel, sValue, isSelected, iType){
+ var oItem = null;
+
+ gSwitchP_ProxyCount++;
+
+ try{
+
+ //Toolbar List
+ if(!gSwitchP_InManager && gSwitchP_List != null && !gSwitchP_List.open){
+ oItem = gSwitchP_List.appendItem(sLabel, sValue);
+ oItem.setAttribute("oncommand", "mproxy_selectProxy();"); //mproxy_anon_stopRotation();
+ oItem.setAttribute("proxyType", iType);
+ }
+
+ //Manage Proxy Box
+ if(gSwitchP_InManager && gSwitchP_List != null && sLabel != gSwitchP_NoneLabel){
+ oItem = gSwitchP_List.appendItem(sLabel, sValue);
+ oItem.setAttribute("proxyType", iType);
+ }
+
+ //Context List
+ if(gSwitchP_ContextList != null){
+ oItem = document.createElement("menuitem");
+ oItem.setAttribute("label", sLabel);
+ oItem.setAttribute("value", sValue);
+ oItem.setAttribute("type", "checkbox");
+ oItem.setAttribute("autocheck", "false");
+ oItem.setAttribute("proxyType", iType);
+ oItem.setAttribute("oncommand", "mproxy_queueSetProxy(this);");
+ gSwitchP_ContextList.appendChild(oItem);
+ }
+
+ //Toolbar Element List
+ if(gSwitchP_ElementList != null){
+ //Get separator, which is after proxy list
+ var oSeparator = document.getElementById("mproxy-element-list-separator");
+ oItem = document.createElement("menuitem");
+ oItem.setAttribute("id", sValue);
+ oItem.setAttribute("label", sLabel);
+ oItem.setAttribute("value", sValue);
+ oItem.setAttribute("type", "checkbox");
+ oItem.setAttribute("autocheck", "false");
+ oItem.setAttribute("proxyType", iType);
+ oItem.setAttribute("class", "proxy-menu-item");
+ oItem.setAttribute("oncommand", "mproxy_queueSetProxy(this);");
+ gSwitchP_ElementList.insertBefore(oItem, oSeparator);
+ }
+
+ // Tools Menu List
+ if(gSwitchP_MenuList != null){
+ //Get separator, which is after proxy list
+ var oSeparator = document.getElementById("mproxy-menu-list-separator");
+ oItem = document.createElement("menuitem");
+ oItem.setAttribute("id", sValue);
+ oItem.setAttribute("label", sLabel);
+ oItem.setAttribute("value", sValue);
+ oItem.setAttribute("type", "checkbox");
+ oItem.setAttribute("autocheck", "false");
+ oItem.setAttribute("proxyType", iType);
+ oItem.setAttribute("class", "proxy-menu-item");
+ oItem.setAttribute("oncommand", "mproxy_queueSetProxy(this);");
+ gSwitchP_MenuList.insertBefore(oItem, oSeparator);
+ }
+
+ //Select
+ if(isSelected)
+ mproxy_selectItem(sLabel);
+
+ }catch(err){}
+}
+
+//Sets List item with labe sLabel, to be selected/checked
+function mproxy_selectItem(sLabel){
+
+ try{
+
+ //Toolbar List
+ if(!gSwitchP_InManager && gSwitchP_List != null){
+ oItem = gSwitchP_List.getElementsByAttribute("label", sLabel);
+ if(oItem != null){
+ oItem = oItem[0];
+ gSwitchP_List.selectedItem = oItem;
+ oItem.setAttribute("selected", true);
+ }
+ }
+
+ //Context
+ if(gSwitchP_ContextList != null){
+ oItem = gSwitchP_ContextList.getElementsByAttribute("label", sLabel);
+ if(oItem != null){
+ //Uncheck Other
+ var aChecked = gSwitchP_ContextList.getElementsByAttribute("checked", "true");
+ for(var c = 0; c < aChecked.length; c++){
+ aChecked[c].setAttribute("checked", false);
+ }
+
+ //Select
+ oItem = oItem[0];
+ gSwitchP_ContextList.selectedItem = oItem;
+ oItem.setAttribute("checked", true);
+ }
+ }
+
+ //Toolbar Element List
+ if(gSwitchP_ElementList != null){
+ oItem = gSwitchP_ElementList.getElementsByAttribute("label", sLabel);
+ if(oItem != null && oItem.length > 0){
+
+ //Uncheck Other
+ var aChecked = gSwitchP_ElementList.getElementsByAttribute("checked", "true");
+ for(var c = 0; c < aChecked.length; c++){
+ aChecked[c].setAttribute("checked", false);
+ }
+
+ //Check Selected
+ oItem = oItem[0];
+ gSwitchP_ElementList.selectedItem = oItem;
+ oItem.setAttribute("selected", true);
+ oItem.setAttribute("checked", true);
+
+ //Change Button Label
+ gSwitchP_ElementButton = document.getElementById('mproxy-element-button');
+ if(gSwitchP_ElementButton != null){
+ gSwitchP_ElementButton.setAttribute("label", sLabel);
+ }
+ }
+ }
+
+ // Tools Menu List
+ if(gSwitchP_MenuList != null){
+ oItem = gSwitchP_MenuList.getElementsByAttribute("label", sLabel);
+ if(oItem != null && oItem.length > 0){
+
+ //Uncheck Other
+ var aChecked = gSwitchP_MenuList.getElementsByAttribute("checked", "true");
+ for(var c = 0; c < aChecked.length; c++){
+ aChecked[c].setAttribute("checked", false);
+ }
+
+ //Check Selected
+ oItem = oItem[0];
+ gSwitchP_MenuList.selectedItem = oItem;
+ oItem.setAttribute("selected", true);
+ oItem.setAttribute("checked", true);
+ }
+ }
+
+ // Status Bar
+ if(gSwitchP_StatusBar != null){
+ gSwitchP_StatusBar.setAttribute("label", mproxy_getString("common.label.proxy")+" "+sLabel);
+ }
+ mproxy_clearTimeout(gSwitchP_Cycle);
+
+ }catch(err){
+ mproxy_debug(err);
+ }
+}
+
+//Return menuitem for the given sUri
+function mproxy_getMenuItem(sUri){
+ var oItem = null;
+
+ //Toolbar
+ oItem = (gSwitchP_List != null) ? gSwitchP_List.getElementsByAttribute("value", sUri) : null;
+ if(oItem != null && oItem[0] != null)
+ return oItem[0];
+
+ //Context
+ oItem = (gSwitchP_List != null) ? gSwitchP_ContextList.getElementsByAttribute("value", sUri) : null;
+ if(oItem != null && oItem[0] != null)
+ return oItem[0];
+
+ //Toolbar Element
+ oItem = (gSwitchP_List != null) ? gSwitchP_ElementList.getElementsByAttribute("value", sUri) : null;
+ if(oItem != null && oItem[0] != null)
+ return oItem[0];
+
+
+ //Default
+ return null;
+}
+
+function mproxy_cycle(sAction){
+ if(gSwitchP_Cycle != null){
+
+ mproxy_clearTimeout(gSwitchP_Cycle);
+ gSwitchP_CommandEnd = true;
+
+ if(sAction == 'change' && gSwitchP_LastItem != null && gSwitchP_List != null && gSwitchP_List.selectedItem.label != gSwitchP_LastItem.label && gSwitchP_List.selectedIndex > 0){
+ gSwitchP_List.label = gSwitchP_LastItem.label;
+ gSwitchP_List.selectedItem = gSwitchP_LastItem;
+ gSwitchP_List.selectedItem.value = gSwitchP_LastItem.value;
+
+ mproxy_setProxy();
+ }
+ else if(sAction == 'select' && gSwitchP_List != null && gSwitchP_List.selectedIndex > -1){
+ mproxy_setStatus(mproxy_getString("toolbar.notApplied"), "#F00");
+ setTimeout("mproxy_setStatus(mproxy_getString('toolbar.loading'))", 3000);
+ setTimeout("mproxy_populateList('"+ gSwitchP_LastItem.label +"');", 4000);
+ setTimeout("mproxy_setProxy();", 4500);
+ }
+
+ }
+}
+
+//When user selects a Proxy from the menu list
+function mproxy_selectProxy(){
+
+ mproxy_clearTimeout(gSwitchP_Cycle);
+ if(gSwitchP_List == null || gSwitchP_List.selectedItem == null || gSwitchP_InManager)
+ return;
+
+ //if(gSwitchP_List.selectedItem.label != gSwitchP_NoneLabel){
+ //document.getElementById('edit-button').disabled = false;
+ //document.getElementById('remove-button').disabled = false;
+ //document.getElementById('edit-button').image = "chrome://mproxy/content/icons/pencil.png";
+ //document.getElementById('remove-button').image = "chrome://mproxy/content/icons/cross.png";
+
+ //}
+ //else{
+ //document.getElementById('edit-button').disabled = true;
+ //document.getElementById('remove-button').disabled = true;
+ //document.getElementById('edit-button').image = "chrome://mproxy/content/icons/pencil_disabled.png";
+ //document.getElementById('remove-button').image = "chrome://mproxy/content/icons/cross_disabled.png";
+ //}
+
+ if(typeof(gSwitchP_List.selectedItem.value) != 'undefined'){
+ //If this item is not being used by the browser,
+ // show a helpful message and cycle
+ var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
+ if((!oPrefs.prefHasUserValue("mproxy.proxy.current") || oPrefs.getCharPref("mproxy.proxy.current") != gSwitchP_List.selectedItem.value) && gSwitchP_LastItem != null && gSwitchP_LastItem != gSwitchP_List.selectedItem){
+ mproxy_setStatus(mproxy_getString("toolbar.clickApply"), "#060");
+
+ //Cycle if user doesn't click 'Apply'
+ //if(gSwitchP_Cycle == null)
+ // gSwitchP_Cycle = setTimeout("mproxy_cycle('select')", 10000);
+ }
+ //If it is being used by the browser
+ else if(oPrefs.prefHasUserValue("mproxy.proxy.current") && oPrefs.getCharPref("mproxy.proxy.current") == gSwitchP_List.selectedItem.value){
+ mproxy_clearTimeout(gSwitchP_Cycle);
+
+ //Anonomous
+ if(gSwitchP_List.selectedItem.getAttribute("proxyType") == "3"){
+ // if(mproxy_anon_getCurrent() == "unknown")
+ // mproxy_setProxy(false);
+ //
+ // mproxy_setStatus(mproxy_getString("toolbar.using") +" "+ gSwitchP_List.selectedItem.label +" ["+ mproxy_anon_getCurrent() +"] ("+ mproxy_anon_getCurrentCount() +")");
+ }
+ //Standard
+ else{
+ mproxy_setStatus(mproxy_getString("toolbar.using") +" "+ gSwitchP_List.selectedItem.label);
+ }
+ }
+ else{
+ mproxy_clearTimeout(gSwitchP_Cycle);
+ mproxy_setStatus(mproxy_getString("toolbar.using.none"));
+ }
+ }
+
+ return true;
+}
+
+//Queue Set Proxy
+function mproxy_queueSetProxy(oMenuItem){
+ mproxy_clearTimeout(gSwitchP_Cycle);
+ setTimeout("mproxy_setProxy(true, true, null, '"+ oMenuItem.label +"', '"+ oMenuItem.getAttribute("value") +"', '"+ oMenuItem.getAttribute("proxyType") +"')", 10);
+}
+
+//Set Proxy
+function mproxy_setProxy(bClean, fromContextMenu, oMenuItem, sLabel, sUri, sType){
+
+ //Start Command
+ gSwitchP_CommandEnd = false;
+ mproxy_clearTimeout(gSwitchP_Cycle);
+ //mproxy_anon_stopRotation();
+
+ //If in Proxy Manager, do nothing
+ if(gSwitchP_InManager){
+ gSwitchP_CommandEnd = true;
+ return;
+ }
+
+ var hasError = false;
+
+ //Set fromContextMenu
+ if(fromContextMenu == null)
+ fromContextMenu = false;
+
+ //Get Proxy URI & Label
+ var sProxyUri = "";
+ var sProxyLabel = "";
+ var sProxyType = 0;
+ if(sUri != null && sLabel != null){
+ sProxyUri = sUri;
+ sProxyLabel = sLabel;
+
+ if(sType) sProxyType = sType;
+ }
+ else if(oMenuItem != null){
+ sProxyUri = oMenuItem.getAttribute("value");
+ sProxyLabel = oMenuItem.getAttribute("label");
+ sProxyType = oMenuItem.getAttribute("proxyType");
+ }
+ else{
+ if(fromContextMenu == true){
+ sProxyUri = gSwitchP_ContextList.selectedItem.value;
+ sProxyLabel = gSwitchP_ContextList.selectedItem.label;
+ sProxyType = gSwitchP_ContextList.selectedItem.getAttribute("proxyType");
+ }
+ else if(gSwitchP_List != null){
+ sProxyUri = gSwitchP_List.selectedItem.value;
+ sProxyLabel = gSwitchP_List.selectedItem.label;
+ sProxyType = gSwitchP_List.selectedItem.getAttribute("proxyType");
+ }
+ }
+
+ //Branch if Anonomous
+ if(sProxyType == "3"){
+ //mproxy_setStatus(mproxy_getString("toolbar.loading"));
+ //mproxy_anon_loadProxy(sProxyUri, true);
+ }
+ else if(sProxyUri != ""){
+ mproxy_setStatus(mproxy_getString("toolbar.loading"));
+ try{
+ //Always clear proxy settings first - this may mess up with selection...
+ //gSwitchP_Prefs.setIntPref("network.proxy.type", 0);
+
+ //Change Browser Preferences
+ var aProps = mproxy_ds_getPropertyValuesFor(sProxyUri);
+
+ for(key in gmproxy_options){
+
+ //Get pref type and update preference
+ var sPrefVal = "";
+ if(typeof(gmproxy_options_defaults[key]) == "number"){
+ gSwitchP_Prefs.setIntPref(gmproxy_options[key], parseInt(aProps[gSProxyRdfNodeUriRoot +"#"+ key]));
+ }
+ else if(typeof(gmproxy_options_defaults[key]) == "boolean"){
+ gSwitchP_Prefs.setBoolPref(gmproxy_options[key], eval(aProps[gSProxyRdfNodeUriRoot +"#"+ key]));
+ }
+ else{ //String
+ gSwitchP_Prefs.setCharPref(gmproxy_options[key], aProps[gSProxyRdfNodeUriRoot +"#"+ key]);
+ }
+ }
+
+ //Get Proxy Label
+ sProxyLabel = aProps[gSProxyRdfNodeName];
+
+ //Update Status
+ mproxy_setStatus(mproxy_getString("toolbar.using") +" "+ sProxyLabel);
+
+ //Update Preference
+ gSwitchP_Prefs.setCharPref("mproxy.proxy.current", sProxyUri);
+ }
+ catch(err){
+ alert("100: "+ mproxy_getString("error.unknown")+ "\n("+ err +")");
+ hasError = true;
+
+ //Cycle back to 'None'
+ //if(gSwitchP_Cycle == null && !fromContextMenu)
+ // gSwitchP_Cycle = setTimeout("mproxy_cycle('change')", 500);
+ }
+ }
+ else{
+ //Turn off proxy pref
+ try{
+ gSwitchP_Prefs.setIntPref("network.proxy.type", 0);
+
+ //Update Status
+ mproxy_setStatus(mproxy_getString("toolbar.using.none"));
+
+
+ //Update Preference
+ gSwitchP_Prefs.setCharPref("mproxy.proxy.current", "");
+
+ }catch(e){
+ alert("101: "+ mproxy_getString("error.unknown"));
+ hasError = true;
+ }
+ }
+
+ // Finalize
+ if(hasError){
+ //Update Status
+ mproxy_setStatus(mproxy_getString("error.proxy.load") +" " + sProxyLabel, "#F00");
+ }
+ else{
+
+ //mproxy_tab_notify(sProxyUri);
+
+ //Select this proxy in all lists
+ mproxy_selectItem(sProxyLabel);
+
+ //Set Last Proxy
+ gSwitchP_LastItem = mproxy_getMenuItem(sProxyUri);
+
+ //Options
+ try{
+ if(bClean){
+ // Clear Cookies
+ if(typeof(gBrowser) != 'undefined' && gSwitchP_Prefs.prefHasUserValue("mproxy.clear.cookies") && gSwitchP_Prefs.getBoolPref("mproxy.clear.cookies")){
+ mproxy_clearCookies();
+ }
+
+ // Reload Page
+ if((typeof(gBrowser) != 'undefined' && (!gSwitchP_Prefs.prefHasUserValue("mproxy.reload.tab") || gSwitchP_Prefs.getBoolPref("mproxy.reload.tab")))){
+ try{
+ var oTab = gBrowser.mCurrentBrowser;
+ oTab.webNavigation.reload(nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE);
+ } catch(err) { }
+ }
+
+ // Set Update Pref
+ gSwitchP_Prefs.setIntPref("mproxy.proxy.rdf.lastupdate", (new Date()).getTime());
+ }
+
+ }catch(err){alert("102: "+ mproxy_getString("error.unknown") + "\n("+err+")");}
+ }
+
+ //End Command
+ gSwitchP_CommandEnd = true;
+
+}
+
+//Test if the RDF Element, oRef, is the current proxy being used
+function mproxy_isSelected(oRef){
+
+ try{
+ var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
+ var aProps = mproxy_ds_getPropertyValuesFor(oRef.Value);
+ var sCurrUri = "";
+ var iType = parseInt(aProps[gSProxyRdfNodeUriRoot + "#networkProxyType"]);
+
+ if(oPrefs.prefHasUserValue("mproxy.proxy.current") && (sCurrUri = oPrefs.getCharPref("mproxy.proxy.current")) == oRef.Value){
+
+ //Verify this is really what's being used in the browser
+ if(iType == oPrefs.getIntPref("network.proxy.type")){
+ if(iType == 1){
+ for(key in gmproxy_options){
+
+ //Skip These Keys
+ if(key == "networkProxyType" || key == "networkProxyAutoconfigURL" || key == "networkProxyHTTPShare" )
+ continue;
+
+ //Skip if RDF has Default Values
+ if( (key == "networkProxySOCKSVersion" && (aProps[gSProxyRdfNodeUriRoot +"#"+ key] == "5" || aProps[gSProxyRdfNodeUriRoot +"#"+ key] == ""))
+ || (key == "networkProxyNone" && aProps[gSProxyRdfNodeUriRoot +"#"+ key] == "localhost, 127.0.0.1")){
+ continue;
+ }
+
+ //If Pref and RDF doesn't have a value for this
+ if(!oPrefs.prefHasUserValue(gmproxy_options[key])
+ && (aProps[gSProxyRdfNodeUriRoot +"#"+ key] == "" || aProps[gSProxyRdfNodeUriRoot +"#"+ key] == "0")){
+ continue;
+ }
+
+ // If pref doesn't have this and the RDF record does
+ // return false
+ if(!oPrefs.prefHasUserValue(gmproxy_options[key])
+ && (aProps[gSProxyRdfNodeUriRoot +"#"+ key] != "" && aProps[gSProxyRdfNodeUriRoot +"#"+ key] != "0")){
+ return false;
+ }
+
+
+ //Get pref and convert to string
+ var sPrefVal = "";
+ if(oPrefs.getPrefType(gmproxy_options[key]) == Components.interfaces.nsIPrefBranch.PREF_INT)
+ sPrefVal = oPrefs.getIntPref(gmproxy_options[key]) + "";
+ if(oPrefs.getPrefType(gmproxy_options[key]) == Components.interfaces.nsIPrefBranch.PREF_BOOL)
+ sPrefVal = oPrefs.getBoolPref(gmproxy_options[key]) + "";
+ if(oPrefs.getPrefType(gmproxy_options[key]) == Components.interfaces.nsIPrefBranch.PREF_STRING)
+ sPrefVal = oPrefs.getCharPref(gmproxy_options[key]);
+
+ //Return false if isn't equal
+ if(sPrefVal != aProps[gSProxyRdfNodeUriRoot +"#"+ key]){
+ return false;
+ }
+ }
+ return true;
+ }
+ //If type is 2 and the PAC url is the same
+ else if(iType == 2 && oPrefs.prefHasUserValue("mproxy.proxy.current")
+ && oPrefs.getCharPref("network.proxy.autoconfig_url") == aProps[gSProxyRdfNodeUriRoot + "#networkProxyAutoconfigURL"]){
+ return true;
+ }
+ }
+ //Anonomous
+ else if(iType == 3 && oPrefs.prefHasUserValue("network.proxy.http") && oPrefs.prefHasUserValue("network.proxy.http_port")){
+ //var sProxy = oPrefs.getCharPref("network.proxy.http") +":"+ oPrefs.getIntPref("network.proxy.http_port");
+
+ //is sProxy in proxy list
+ //oTestRes = mproxy_ds_getElementForValue(gSProxyRdfNodeUriRoot +"#proxy", sProxy);
+
+ //if(oTestRes instanceof Components.interfaces.nsIRDFResource && oTestRes.Value == oRes.Value){
+ //mproxy_anon_loadProxy(oRef.Value, true);
+ //return true;
+ //}
+
+ return false;
+ }
+ }
+
+ }catch(err){}
+
+
+ return false;
+}
+
+function mproxy_removeProxy(){
+ mproxy_clearTimeout(gSwitchP_Cycle);
+ var oItem = gSwitchP_List.selectedItem;
+
+ //Can't delete 'None'
+ if((gSwitchP_List.selectedItem != null) &&
+ (gSwitchP_List.selectedItem.label == gSwitchP_NoneLabel) ){
+ alert("150: "+ mproxy_getString("error.remove.forbidden"));
+ return;
+ }
+
+ if(!confirm(mproxy_getString("confirm.remove")))
+ return;
+
+ try{
+ //RDF
+ //Remove
+ mproxy_ds_removeElement(oItem.value);
+
+ //Cleanup
+ mproxy_cleanupRdf();
+
+ //Update List
+ mproxy_populateList();
+ setTimeout("mproxy_setProxy();", 300);
+ }
+ catch(err){
+ alert("151: "+ mproxy_getString("error.remove") + "\n("+ err +")");
+ }
+}
+
+function mproxy_clearCookies(){
+ try{
+ var oCookies = Components.classes["@mozilla.org/cookiemanager;1"].createInstance(Components.interfaces.nsICookieManager);
+ oCookies.removeAll();
+ }catch(err){
+ alert("200: "+ mproxy_getString("error.cookie"));
+ }
+ return true;
+}
+
+function mproxy_add_proxy(sName, sPort, issocks, toset){
+ try{
+
+ var oTestProxy = mproxy_ds_getElementForValue(gSProxyRdfNodeName, sName);
+ if(oTestProxy != null){
+ return false;
+ }
+
+ var sProxyUri = mproxy_getUniqueProxyUri();
+ var oProxy = mproxy_ds_getResource(sProxyUri);
+ mproxy_ds_addElement(sProxyUri);
+
+ if (issocks) { //socks
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyType"), "1", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTP"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTP_Port"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTPShare"), false, true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySSL"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySSL_Port"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyFTP"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyFTP_Port"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyGopher"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyGopher_Port"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKS"), "127.0.0.1", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKS_Port"), sPort, true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKSVersion"), "5", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyNone"), "localhost, 127.0.0.1", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyAutoconfigURL"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#name"), sName, true);
+ }
+ else { //regular http for all
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyType"), "1", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTP"), "127.0.0.1", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTP_Port"), sPort, true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTPShare"), true, true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySSL"), "127.0.0.1", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySSL_Port"), sPort, true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyFTP"), "127.0.0.1", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyFTP_Port"), sPort, true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyGopher"), "127.0.0.1", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyGopher_Port"), sPort, true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKS"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKS_Port"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKSVersion"), "5", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyNone"), "localhost, 127.0.0.1", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyAutoconfigURL"), "", true);
+ mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#name"), sName, true);
+ }
+ if (toset) {
+ mproxy_setProxy(true, null, null, sName, sProxyUri, 1);
+ mproxy_selectItem(sName);
+ }
+ return true;
+ }catch(e){
+ alert(mproxy_getString("error.unknown") +"\n("+ e +")");
+ return false;
+ }
+}
+
+function mproxy_populateList(sSelectedLabel){
+ mproxy_clearTimeout(gSwitchP_Cycle);
+
+ var sProxyUri = "";
+ var iSelected = (gSwitchP_List != null) ? gSwitchP_List.selectedIndex : -1;
+ var aProxies = new Array();
+
+ //Don't populate if a local command has not finished or if list is open
+ if(!gSwitchP_CommandEnd){
+ gSwitchP_CommandEnd = true; //reset
+ return;
+ }
+ else{ //Start Command
+ gSwitchP_CommandEnd = false;
+ }
+
+ //Load Elements
+ try{
+
+ //Remove List Items & Add 'None'
+ mproxy_clearList();
+ mproxy_appendToList(gSwitchP_NoneLabel, "", true, 0);
+ mproxy_selectItem(gSwitchP_NoneLabel);
+
+ //Add Tor as default proxy, and set proxy to it
+ //mproxy_add_proxy(mproxy_getString("common.proxy.tor"), "9050", true, true);
+
+ //Get and Sort Elements
+ var aProxies = mproxy_ds_getAllElements();
+ aProxies.sort(mproxy_sortProxies);
+
+ //Add to list
+ for(i = 0; i < aProxies.length; i++){
+
+ if(typeof(aProxies[i]) == 'undefined')
+ continue;
+
+ try{
+
+ oRes = mproxy_ds_getResource(aProxies[i]);
+ sProxyName = mproxy_ds_getValueFor(oRes, mproxy_ds_getResource(gSProxyRdfNodeName));
+ sProxyType = mproxy_ds_getValueFor(oRes, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+ "#networkProxyType"));
+
+ if(sProxyName != null){
+ oItem = mproxy_appendToList(sProxyName, aProxies[i], false, sProxyType);
+
+ //Select Item
+ if((sSelectedLabel != null && sSelectedLabel == sProxyName) || (sSelectedLabel == null && mproxy_isSelected(oRes))){
+ mproxy_selectItem(sProxyName);
+ }
+ }
+
+ } catch(err) {}
+ }
+
+ //Finish
+ gSwitchP_CommandEnd = true;
+ setTimeout("mproxy_selectProxy();", 300);
+
+ }catch(err){}
+}
+
+/*
+* Sort Proxy List
+* + oResA and oResB are RDF URIs
+*/
+function mproxy_sortProxies(oResA, oResB){
+ try{
+ //Get Proxy Names
+ sValA = mproxy_ds_getValueFor(mproxy_ds_getResource(oResA), mproxy_ds_getResource(gSProxyRdfNodeName));
+ sValB = mproxy_ds_getValueFor(mproxy_ds_getResource(oResB), mproxy_ds_getResource(gSProxyRdfNodeName));
+
+
+ if (sValA < sValB)
+ return -1;
+ if (sValA == sValB)
+ return 0;
+ if (sValA > sValB)
+ return 1;
+ }
+ catch(e){ return 0; }
+}
+
+/* Cleanup unused mproxy data in RDF
+* + Remove resources that have not been applied or used
+*/
+function mproxy_cleanupRdf(){
+
+ try{
+
+ var aElements = mproxy_ds_getAllElements();
+ for(var e = 0; e < aElements.length; e++){
+ oRes = mproxy_ds_getResource(aElements[e]);
+ aProps = mproxy_ds_getPropertyValuesFor(aElements[e]);
+
+ //If does not have a name property,
+ // then it is not listed -- so it's junk
+ if(aProps[gSProxyRdfNodeName] == null){
+ mproxy_ds_removeElement(aElements[e]);
+ }
+ }
+ }catch(err){}
+}
+
+// Automatic Upgrade
+/*
+* From Version 0.4
+* + Add preference 'mproxy.version'
+* + Add preference 'mproxy.proxy.current'
+* + Change proxy's URI to random number
+* + Convert #proxy to networkProxyAutoconfigURL
+* + Add elements for full manual proxy configuration
+* + view the globals.js gmproxy_options array for full list
+*/
+
+
+//Generates random number for proxy URI
+function mproxy_getUniqueProxyUri(){
+ var sUri = gSProxyRdfRoot + "/mproxy_" + Math.round((Math.random() * 200000));
+
+ if(mproxy_ds_doesProxyElementExist(sUri))
+ return mproxy_getUniqueProxyUri();
+
+ return sUri;
+}
+
+function mproxy_setStatus(sMsg, sColor){
+ if(!sColor)
+ sColor = "#000";
+
+ oStatus = document.getElementById('status-text');
+
+ if(oStatus != null){
+ document.getElementById('status-text').style.color = sColor;
+ document.getElementById('status-text').value = sMsg;
+ }
+}
+
+//Clear Timeout
+function mproxy_clearTimeout(){
+ clearTimeout(gSwitchP_Cycle);
+ gSwitchP_Cycle = null;
+}
+
+//Execute a command when system is ready
+// iCurrCount is for internal use, do not
+// pass this argument
+function mproxy_doCommand(sCommand, iLimitCount){
+
+ if(iLimitCount == null)
+ iLimitCount = 0;
+
+ //Wait for current command to end
+ if(!gSwitchP_CommandEnd && iLimitCount < 10){
+ iLimitCount++
+ setTimeout("mproxy_doCommand('"+ sCommand +"', "+ iCurrCount +")", 100);
+ }
+ else{
+ gSwitchP_CommandEnd = true;
+ setTimeout(sCommand, 100);
+ }
+}
+
+/*
+* Launch Dialogs
+*/
+
+ //Edit Proxy Dialog
+ function mproxy_editProxyDialog(isNew){
+ mproxy_clearTimeout(gSwitchP_Cycle);
+
+ var sAction = null;
+
+ //Nothing Selected
+ var oEditItem = null
+ if(!isNew && (oEditItem = gSwitchP_List.selectedItem) == null){
+ alert("250: "+ mproxy_getString("error.edit.select"));
+ return;
+ }
+
+ //Can't edit 'None'
+ if(!gSwitchP_InManager && !isNew && gSwitchP_List != null && gSwitchP_List.selectedItem != null && gSwitchP_List.selectedItem.label == gSwitchP_NoneLabel){
+ alert("251: "+ mproxy_getString("error.edit.forbidden"));
+ return;
+ }
+
+ //Edit
+ if(!isNew){
+
+ //Anon
+ //if(oEditItem.getAttribute("proxyType") == "3"){
+ // window.openDialog("chrome://mproxy/content/dialogs/editanon.xul","editproxy","centerscreen, chrome", "edit", oEditItem.value);
+ //}
+ //Standard
+ //else{
+ window.openDialog("chrome://mproxy/content/dialogs/editproxy.xul","editproxy","centerscreen, chrome", "edit", oEditItem.value);
+ //}
+ }
+ //Add
+ else{
+ //window.openDialog("chrome://mproxy/content/dialogs/addproxytype.xul","editproxy","centerscreen, chrome", "add");
+ window.openDialog("chrome://mproxy/content/dialogs/editproxy.xul","addproxy","centerscreen, chrome", "add", gSwitchP_InManager);
+ }
+ }
+
+ //Manage Proxy Dialog
+ function mproxy_openProxyManager(){
+ window.openDialog("chrome://mproxy/content/dialogs/manager.xul","manageproxies","centerscreen, chrome, resizable");
+ }
+
+/*
+* Options
+*/
+ function mproxy_openmproxyPrefs(){
+ window.openDialog("chrome://mproxy/content/options/options.xul","mproxyPrefs","centerscreen, chrome");
+ }
+
+ function mproxy_goTomproxySite(fromDialog){
+
+ // If Thunderbird
+ if(navigator.userAgent.search(/Thunderbird/gi) > -1){
+ var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance();
+ messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
+ messenger.launchExternalURL(gmproxy_DownloadSite +"?r=mproxy");
+ }
+ else{
+ opener.gBrowser.selectedTab = opener.getBrowser().addTab(gmproxy_DownloadSite +"?r=mproxy");
+ }
+ self.close();
+ }
+
+ function mproxy_goTomproxyAbout(){
+ window.openDialog("chrome://mproxy/content/dialogs/about.xul","mproxyAbout","centerscreen, chrome, modal");
+ }
+
+/*
+* Automatic Updator
+*/
+
+ //If there is a new version, returns the XPI url, else returns false
+
+ //The user selects to check for updates
+
+/*
+* UNINSTALL
+*/
+ function mproxy_uninstall(oLogger){
+ try{
+ var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
+ oPrefs.deleteBranch("mproxy");
+
+ oLogger.addLog(new window.ExtuninstallLogItem(oLogger.REMOVE_ACTION, oLogger.SUCCESS_STATUS, "Preferences Branch 'mproxy'", null, null));
+ }catch(err){
+ oLogger.addLog(new window.ExtuninstallLogItem(oLogger.REMOVE_ACTION, oLogger.WARN_STATUS, "Preferences Branch 'mproxy'", 1001, err));
+ throw 1001;
+ }
+ }
+
diff --git a/src/chrome/content/proxy.xul b/src/chrome/content/proxy.xul
new file mode 100644
index 0000000..b0cb91a
--- /dev/null
+++ b/src/chrome/content/proxy.xul
@@ -0,0 +1,125 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<!DOCTYPE overlay SYSTEM "chrome://mproxy/locale/locale.dtd" >
+
+<overlay id="mproxyOverlay"
+ title="Multiproxy Switch Overlay"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script type="application/x-javascript" src="chrome://mproxy/content/globals.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/datasource.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/tabmanager.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/proxy.js"></script>
+ <script language="JavaScript">
+ //Window Event Handers
+ try{window.addEventListener("load", mproxy_initProxy, true);}catch(e){}
+ //try{window.addEventListener("focus", mproxy_tab_windowFocus, true);}catch(e){}
+ </script>
+
+ <!-- Toolbar -->
+ <toolbox id="navigator-toolbox" context="toolbar-context-menu">
+ <toolbar id="proxy-toolbar"
+ accesskey="&toolbar.name.key;"
+ context="toolbar-context-menu"
+ customizable="true"
+ iconsize="small"
+ mode="full"
+ collapsed="false" persist="collapsed"
+ toolbarname="&toolbar.name.label;"
+ class="chromeclass">
+
+ <hbox align="center" flex="2">
+ <label value="&toolbar.proxy.label;" style="margin-right: 0;" />
+
+ <menulist id="proxy-list" popup="proxy-list-popup">
+ <menupopup id="proxy-list-popup" position="after_start">
+ <menuitem value="" label="&common.none;" oncommand="mproxy_selectProxy(this)" />
+ </menupopup>
+ </menulist>
+
+ <toolbarbutton id="apply-button" label="&common.apply.label;" default="true" onclick="mproxy_setProxy(true)" image="chrome://mproxy/content/icons/check.png" tooltiptext="&common.apply.tip;" />
+ <spacer width="25" />
+
+ <groupbox orient="horizontal" style="padding: 1px;">
+ <description id="status-label" value="&toolbar.status;" style="font-weight: bold;" />
+ <description id="status-text" value="&toolbar.using.none;" />
+ </groupbox>
+
+ <spacer width="25" />
+ <toolbarbutton id="options-list" label="&common.manage.label;" onclick="mproxy_openProxyManager();" image="chrome://mproxy/content/icons/isp.png" />
+ <spacer width="12" />
+ <toolbarbutton id="options-list" label="&common.preferences.label;" onclick="mproxy_openmproxyPrefs();" image="chrome://mproxy/content/icons/options.png" />
+ </hbox>
+ </toolbar>
+ </toolbox>
+
+ <!-- Toolbar Element -->
+ <toolbarpalette id="BrowserToolbarPalette">
+ <toolbaritem id="mproxy-container" title="&common.product.name;" align="center">
+ <button id="mproxy-element-button" tooltiptext="&toolelement.tip;" label="" popup="mproxy-element-list"
+ image="chrome://mproxy/content/icons/arrow-dn.gif" dir="rtl" />
+ </toolbaritem>
+ </toolbarpalette>
+
+ <!-- Statusbar -->
+ <statusbar id="status-bar" class="chromeclass-status">
+ <statusbarpanel id="mproxy-status"
+ insertbefore="statusbar-updates"
+ label="" collapsed="false"
+ context="mproxy-element-list"
+ popup="mproxy-element-list"
+ tooltiptext="&common.product.name;" />
+
+ </statusbar>
+
+ <!-- Firefox Tools Menu -->
+ <menupopup id="menu_ToolsPopup">
+ <menu id="mproxy-tools-menu" label="&common.product.name;"
+ accesskey="M" class="menuitem-iconic"
+ insertafter="devToolsSeparator">
+ <menupopup id="mproxy-menu-list" position="end_before" onpopupshowing="mproxy_showElementList(event);">
+ <menuitem label="&common.none;" type="checkbox" checked="true" oncommand="mproxy_queueSetProxy(this);" class="proxy-menu-item"/>
+ <menuseparator id="mproxy-menu-list-separator" />
+ <menuitem image="chrome://mproxy/content/icons/isp.png" label="&common.manage.label;" accesskey="&common.manage.key;" oncommand="mproxy_openProxyManager();" />
+ <menuseparator />
+ <menuitem image="chrome://mproxy/content/icons/options.png" label="&common.preferences.label;" accesskey="&common.preferences.key;" oncommand="mproxy_openmproxyPrefs();" />
+
+ <menuitem label="&common.about.label;" accesskey="&common.about.key;" oncommand="mproxy_goTomproxyAbout()" />
+ </menupopup>
+ </menu>
+ </menupopup>
+
+ <!-- Context Menu -->
+ <popup id="contentAreaContextMenu">
+ <menuseparator id="mproxy-context-separator"/>
+ <menu label="&context.label;" id="mproxy-context-menu" accesskey="&context.key;">
+ <menupopup id="mproxy-context-menu-popup;" onpopupshowing="mproxy_showElementList(event);">
+ <menu label="&context.proxies.label;" accesskey="&context.proxies.key;" id="mproxy-context-proxylist">
+ <menupopup id="context-proxy-list">
+ <menuitem label="&common.none;" type="checkbox" checked="true" oncommand="mproxy_setProxy(true, true);" />
+ </menupopup>
+ </menu>
+ <menuseparator />
+ <menuitem label="&common.manage.label;" accesskey="&common.manage.key;" oncommand="mproxy_openProxyManager();" />
+ <menuseparator />
+ <menuitem label="&common.preferences.label;" accesskey="&common.preferences.key;" oncommand="mproxy_openmproxyPrefs();" />
+
+ <menuitem label="&common.about.label;" accesskey="&common.about.key;" oncommand="mproxy_goTomproxyAbout()" />
+ </menupopup>
+ </menu>
+ </popup>
+
+ <!-- Popups -->
+ <popupset id="mainPopupSet">
+ <popup id="mproxy-element-list" position="after_start" onpopupshowing="mproxy_showElementList(event);">
+ <menuitem label="&common.none;" type="checkbox" checked="true" oncommand="mproxy_queueSetProxy(this);" class="proxy-menu-item"/>
+ <menuseparator id="mproxy-element-list-separator" />
+ <menuitem label="&common.manage.label;" accesskey="&common.manage.key;" oncommand="mproxy_openProxyManager();" />
+ <menuseparator />
+ <menuitem label="&common.preferences.label;" accesskey="&common.preferences.key;" oncommand="mproxy_openmproxyPrefs();" />
+
+ <menuitem label="&common.about.label;" accesskey="&common.about.key;" oncommand="mproxy_goTomproxyAbout()" />
+ </popup>
+ </popupset>
+</overlay> \ No newline at end of file
diff --git a/src/chrome/content/proxy_moz.xul b/src/chrome/content/proxy_moz.xul
new file mode 100644
index 0000000..27562bd
--- /dev/null
+++ b/src/chrome/content/proxy_moz.xul
@@ -0,0 +1,118 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<!DOCTYPE overlay SYSTEM "chrome://mproxy/locale/locale.dtd" >
+
+<overlay id="mproxyOverlay"
+ title="Multi-proxy Switch Overlay"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script type="application/x-javascript" src="chrome://mproxy/content/globals.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/datasource.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/tabmanager.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/proxy.js"></script>
+ <script language="JavaScript">
+ //Window Event Handers
+ try{window.addEventListener("load", mproxy_initProxy, true);}catch(e){}
+ //try{window.addEventListener("focus", mproxy_tab_windowFocus, true);}catch(e){}
+ </script>
+
+ <!-- Toolbar -->
+ <toolbox id="navigator-toolbox" context="toolbar-context-menu">
+ <toolbar id="proxy-toolbar"
+ accesskey="&toolbar.name.key;"
+ context="toolbar-context-menu"
+ customizable="true"
+ iconsize="small"
+ mode="full"
+ collapsed="false" persist="collapsed"
+ toolbarname="&toolbar.name.label;"
+ class="chromeclass">
+
+ <hbox align="center" flex="2">
+ <label value="&toolbar.proxy.label;" style="margin-right: 0;" />
+
+ <menulist id="proxy-list" popup="proxy-list-popup">
+ <menupopup id="proxy-list-popup" position="after_start">
+ <menuitem value="" label="&common.none;" oncommand="mproxy_selectProxy(this)" />
+ </menupopup>
+ </menulist>
+
+ <toolbarbutton id="apply-button" label="&common.apply.label;" default="true" onclick="mproxy_setProxy(true)" image="chrome://mproxy/content/icons/check.png" tooltiptext="&common.apply.tip;" />
+
+ <spacer width="25" />
+
+ <groupbox orient="horizontal" style="padding: 1px;">
+ <description id="status-label" value="&toolbar.status;" style="font-weight: bold;" />
+ <description id="status-text" value="&toolbar.using.none;" />
+ </groupbox>
+
+ <spacer width="25" />
+ <toolbarbutton id="options-list" label="&common.manage.label;" onclick="mproxy_openProxyManager();" image="chrome://mproxy/content/icons/isp.png" />
+ <spacer width="12" />
+ <toolbarbutton id="options-list" label="&common.preferences.label;" onclick="mproxy_openmproxyPrefs();" image="chrome://mproxy/content/icons/options.png" />
+ </hbox>
+ </toolbar>
+ </toolbox>
+
+ <!-- Statusbar -->
+ <statusbar id="status-bar" class="chromeclass-status">
+ <statusbarpanel id="mproxy-status"
+ insertbefore="statusbar-updates"
+ label="" collapsed="false"
+ context="mproxy-element-list"
+ popup="mproxy-element-list"
+ tooltiptext="&common.product.name;" />
+
+ </statusbar>
+
+ <!-- Firefox Tools Menu -->
+ <menupopup id="menu_ToolsPopup">
+ <menu id="mproxy-tools-menu" label="&common.product.name;"
+ accesskey="P" class="menuitem-iconic"
+ insertafter="devToolsSeparator">
+ <menupopup id="mproxy-menu-list" position="end_before" onpopupshowing="mproxy_showElementList(event);">
+ <menuitem label="&common.none;" type="checkbox" checked="true" oncommand="mproxy_queueSetProxy(this);" class="proxy-menu-item"/>
+ <menuseparator id="mproxy-menu-list-separator" />
+ <menuitem label="&common.manage.label;" accesskey="&common.manage.key;" oncommand="mproxy_openProxyManager();" />
+ <menuseparator />
+ <menuitem label="&common.preferences.label;" accesskey="&common.preferences.key;" oncommand="mproxy_openmproxyPrefs();" />
+ <menuitem label="&common.updates.label;" accesskey="&common.updates.key;" oncommand="mproxy_manualUpgradCheck()" />
+ <menuitem label="&common.about.label;" accesskey="&common.about.key;" oncommand="mproxy_goTomproxyAbout()" />
+ </menupopup>
+ </menu>
+ </menupopup>
+
+ <!-- Context Menu -->
+ <popup id="contentAreaContextMenu">
+ <menuseparator id="mproxy-context-separator"/>
+ <menu label="&context.label;" id="mproxy-context-menu" accesskey="&context.key;">
+ <menupopup id="mproxy-context-menu-popup;" onpopupshowing="mproxy_showElementList(event);">
+ <menu label="&context.proxies.label;" accesskey="&context.proxies.key;" id="mproxy-context-proxylist">
+ <menupopup id="context-proxy-list">
+ <menuitem label="&common.none;" type="checkbox" checked="true" oncommand="mproxy_setProxy(true, true);" />
+ </menupopup>
+ </menu>
+ <menuseparator />
+ <menuitem label="&common.manage.label;" accesskey="&common.manage.key;" oncommand="mproxy_openProxyManager();" />
+ <menuseparator />
+ <menuitem label="&common.preferences.label;" accesskey="&common.preferences.key;" oncommand="mproxy_openmproxyPrefs();" />
+ <menuitem label="&common.updates.label;" accesskey="&common.updates.key;" oncommand="mproxy_manualUpgradCheck()" />
+ <menuitem label="&common.about.label;" accesskey="&common.about.key;" oncommand="mproxy_goTomproxyAbout()" />
+ </menupopup>
+ </menu>
+ </popup>
+
+ <!-- Popups -->
+ <popupset id="mainPopupSet">
+ <popup id="mproxy-element-list" position="after_start" onpopupshowing="mproxy_showElementList(event);">
+ <menuitem label="&common.none;" type="checkbox" checked="true" oncommand="mproxy_queueSetProxy(this);" class="proxy-menu-item"/>
+ <menuseparator id="mproxy-element-list-separator" />
+ <menuitem label="&common.manage.label;" accesskey="&common.manage.key;" oncommand="mproxy_openProxyManager();" />
+ <menuseparator />
+ <menuitem label="&common.preferences.label;" accesskey="&common.preferences.key;" oncommand="mproxy_openmproxyPrefs();" />
+ <menuitem label="&common.updates.label;" accesskey="&common.updates.key;" oncommand="mproxy_manualUpgradCheck()" />
+ <menuitem label="&common.about.label;" accesskey="&common.about.key;" oncommand="mproxy_goTomproxyAbout()" />
+ </popup>
+ </popupset>
+</overlay> \ No newline at end of file
diff --git a/src/chrome/content/proxy_thunder.xul b/src/chrome/content/proxy_thunder.xul
new file mode 100644
index 0000000..90f8072
--- /dev/null
+++ b/src/chrome/content/proxy_thunder.xul
@@ -0,0 +1,60 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<!DOCTYPE overlay SYSTEM "chrome://mproxy/locale/locale.dtd" >
+
+<overlay id="mproxyOverlay"
+ title="Multi-proxy Switch Overlay"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+ <script type="application/x-javascript" src="chrome://mproxy/content/globals.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/datasource.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/tabmanager.js"></script>
+ <script type="application/x-javascript" src="chrome://mproxy/content/proxy.js"></script>
+ <script language="JavaScript">
+ //Window Event Handers
+ try{window.addEventListener("load", mproxy_initProxy, true);}catch(e){}
+ //try{window.addEventListener("focus", mproxy_tab_windowFocus, true);}catch(e){}
+ </script>
+
+ <!-- Statusbar -->
+ <statusbar id="status-bar" class="chromeclass-status">
+ <statusbarpanel id="mproxy-status"
+ insertbefore="statusbar-updates"
+ label="" collapsed="false"
+ context="mproxy-element-list"
+ popup="mproxy-element-list"
+ tooltiptext="&common.product.name;" />
+
+ </statusbar>
+
+ <!-- Popups -->
+ <popupset id="ContextMenus">
+ <popup id="mproxy-element-list" position="end_before">
+ <menuitem label="&common.none;" type="checkbox" checked="true" oncommand="mproxy_queueSetProxy(this);" class="proxy-menu-item"/>
+ <menuseparator id="mproxy-element-list-separator" />
+ <menuitem label="&common.manage.label;" accesskey="&common.manage.key;" oncommand="mproxy_openProxyManager();" />
+ <menuseparator />
+ <menuitem label="&common.preferences.label;" accesskey="&common.preferences.key;" oncommand="mproxy_openmproxyPrefs();" />
+
+ <menuitem label="&common.about.label;" accesskey="&common.about.key;" oncommand="mproxy_goTomproxyAbout()" />
+ </popup>
+ </popupset>
+
+ <!-- Tools Menu -->
+ <menupopup id="taskPopup">
+ <menu id="mproxy-tools-menu" label="&common.product.name;"
+ accesskey="P" class="menuitem-iconic"
+ insertafter="devToolsSeparator">
+ <menupopup id="mproxy-menu-list" position="end_before">
+ <menuitem label="&common.none;" type="checkbox" checked="true" oncommand="mproxy_queueSetProxy(this);" class="proxy-menu-item"/>
+ <menuseparator id="mproxy-menu-list-separator" />
+ <menuitem label="&common.manage.label;" accesskey="&common.manage.key;" oncommand="mproxy_openProxyManager();" />
+ <menuseparator />
+ <menuitem label="&common.preferences.label;" accesskey="&common.preferences.key;" oncommand="mproxy_openmproxyPrefs();" />
+
+ <menuitem label="&common.about.label;" accesskey="&common.about.key;" oncommand="mproxy_goTomproxyAbout()" />
+ </menupopup>
+ </menu>
+ </menupopup>
+</overlay> \ No newline at end of file
diff --git a/src/chrome/content/tabmanager.js b/src/chrome/content/tabmanager.js
new file mode 100644
index 0000000..297cf9f
--- /dev/null
+++ b/src/chrome/content/tabmanager.js
@@ -0,0 +1,146 @@
+
+/*
+* Tab Manager Object
+*/
+function mproxy_TabManager(){
+ this.manage = false;
+ this.tabs = new Array();
+
+ // Read Preferences (toggle manager on/off)
+ try{
+ var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
+ manage = (oPrefs.prefHasUserValue("mproxy.tabs.manager") && oPrefs.getBoolPref("mproxy.tabs.manager") == true);
+
+ // Add Pref Observer
+ var oTabManagerPrefObserver = {
+ observe : function(subject, topic, data){ if(data == true && manage == false) { manage = true; /*mproxy_setProxy(false)*/; } }
+ };
+ oPrefs = Components.classes["@mozilla.org/preferences-service;1"].createInstance(Components.interfaces.nsIPrefBranchInternal);
+ oPrefs.addObserver("mproxy.tabs.manager", oTabManagerPrefObserver, false);
+ } catch(err){}
+
+
+ this.getTabForBrowser = mproxy_tab_getTabForBrowser;
+ this.getTabForDocument = mproxy_tab_getTabForDocument;
+ this.tabLoading = mproxy_tab_tabLoading;
+}
+
+// Called on new Window/Tab
+function mproxy_tab_tabLoading(){
+
+ try{
+ // Verify all tabs are in list
+ var aBrowsers = gBrowser.browsers;
+ for(var i = 0; i < aBrowsers.length; i++){
+ if(this.getTabForBrowser(aBrowsers[i]) == null){
+ var index = this.tabs.length;
+ this.tabs[index] = new mproxy_Tab(aBrowsers[i], null, index);
+ }
+ }
+ } catch(err) {alert(err)}
+
+}
+
+// Return mproxy_Tab object for oBrowser
+function mproxy_tab_getTabForBrowser(oBrowser){
+ for(var t = 0; t < this.tabs.length; t++){
+ if(this.tabs[t].browser == oBrowser)
+ return this.tabs[t];
+ }
+ return null;
+}
+
+// Return mproxy_Tab object for oDocument
+function mproxy_tab_getTabForDocument(oDocument){
+ for(var t = 0; t < this.tabs.length; t++){
+ if(this.tabs[t].browser.contentDocument == oDocument)
+ return this.tabs[t];
+ }
+ return null;
+}
+
+/*
+* Tab Object
+*/
+function mproxy_Tab(browser, proxy, index){
+ this.browser = browser;
+ this.proxy = proxy;
+ this.title = "";
+ this.index = index;
+
+ //alert(this.browser.contentDocument)
+
+ if(this.browser != null){
+ try{
+ this.browser.addEventListener("focus", mproxy_tab_onfocus, true);
+ this.browser.addEventListener("unload", mproxy_tab_onunload, true);
+ this.browser.addEventListener("load", mproxy_tab_onloaded, true);
+ } catch(err) { alert(err); }
+ }
+
+ this.updateTitle = function(){
+
+ if(this.proxy != null && this.proxy != ""){
+
+ // Get label for proxy uri
+ var oRes = mproxy_ds_getResource(aProxies[i]);
+ var sProxyName = mproxy_ds_getValueFor(oRes, mproxy_ds_getResource(gSProxyRdfNodeName));
+
+ // Set title
+ if(sProxyName != null){
+ this.browser.contentDocument.title = "["+ sProxyName +"] " +this.title;
+ }
+ }
+ }
+}
+
+
+/*
+* Utilities
+*/
+ // Notify current tab of proxy change
+ function mproxy_tab_notify(sUri){
+ var oTab = mproxy_getTabManager().getTabForBrowser(gBrowser.selectedBrowser);
+
+ oTab.proxyUri = sUri;
+ oTab.updateTitle();
+ }
+
+/*
+* Event Handlers
+*/
+
+ // On Tab Focus
+ function mproxy_tab_onfocus(event){
+ try{
+ var oTab = mproxy_getTabManager().getTabForBrowser(gBrowser.selectedBrowser)
+ //oTab.browser.contentDocument.title = oTab.index;
+
+ //mproxy_setProxy();
+ }catch(err) { }
+ }
+
+ // On Window Focus
+ function mproxy_tab_windowFocus(event){
+ try{
+ if(event.target.nodeName = "tabbrowser"){
+
+ }
+ }catch(err) { }
+ }
+
+ // On tab unload
+ function mproxy_tab_onunload(event){
+ try{
+ var oTab = mproxy_getTabManager().getTabForDocument(event.target);
+ //oTab.browser.contentDocument.title = "Refreshing...";
+ }catch(err) { }
+ }
+
+ // On tab load
+ function mproxy_tab_onloaded(event){
+ try{
+ var oTab = mproxy_getTabManager().getTabForDocument(event.target);
+ //oTab.browser.contentDocument.title = "Loaded";
+ }catch(err) { }
+ } \ No newline at end of file