Commit fedfb265 authored by Scott Squires's avatar Scott Squires
Browse files

[darcs-to-svn @ tagged 1.0]

Original author: squires@pobox.com
Date: 2006-06-01 18:57:50+00:00

svn:r10249
parent 74cd0da3
TorButton was adapted by Scott Squires from ProxyButton
(proxybutton.mozdev.com), which was written by Oleg Ivanov.
Copyright (c) 2006 Scott Squires, Oleg Ivanov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
content torbutton chrome/content/
overlay chrome://browser/content/browser.xul chrome://torbutton/content/torbutton.xul
locale torbutton en-US chrome/locale/en-US/
skin torbutton classic/1.0 chrome/skin/classic/
style chrome://global/content/customizeToolbar.xul chrome://torbutton/skin/torbutton.css
<?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:torbutton"/>
</RDF:Seq>
<RDF:Description about="urn:mozilla:package:torbutton"
chrome:extension="true"
chrome:name="torbutton" />
</RDF:Description>
<RDF:Seq about="urn:mozilla:overlays">
<RDF:li resource="chrome://browser/content/browser.xul"/>
</RDF:Seq>
<RDF:Seq about="chrome://browser/content/browser.xul">
<RDF:li>chrome://torbutton/content/torbutton.xul</RDF:li>
</RDF:Seq>
</RDF:RDF>
var m_toolbutton = false;
var m_statuspanel = false;
var m_wasinited = false;
var m_commonprefs = false;
var m_stringbundle = false;
var m_tb_logger = false;
function torbutton_toggle() {
torbutton_log(1, 'called toggle()');
if (!m_wasinited) {
torbutton_init();
}
if (!m_toolbutton) {
torbutton_init_toolbutton();
}
var nCurProxyType = m_commonprefs.getIntPref("network.proxy.type");
if (torbutton_check_status()) {
torbutton_disable_tor();
} else {
torbutton_enable_tor();
}
}
function torbutton_init() {
if (!m_tb_logger) {
try {
var logMngr = Components.classes["@mozmonkey.com/debuglogger/manager;1"].getService(Components.interfaces.nsIDebugLoggerManager);
m_tb_logger = logMngr.registerLogger("torbutton");
} catch (exErr) {
m_tb_logger = false;
}
}
if (!m_stringbundle) {
try {
var oBundle = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
m_stringbundle = oBundle.createBundle("chrome://torbutton/locale/torbutton.properties");
} catch(err) { torbutton_log(1, 'caught exception'); }
if (!m_stringbundle) {
torbutton_log(1, 'ERROR (init): failed to find torbutton-bundle');
}
}
torbutton_log(1, 'called init()');
if (!m_commonprefs) {
torbutton_initPrefObjects();
}
if (!m_statuspanel) {
torbutton_log(1, 'looking for statusbar element');
if (document.getElementById("torbutton-panel")) {
m_statuspanel = document.getElementById("torbutton-panel");
} else {
torbutton_log(1, 'ERROR (init): failed to find torbutton-panel');
}
} else {
torbutton_log(1, 'skipping statusbar panel element search');
}
if (!m_wasinited) {
torbutton_log(1, 'initializing observer');
var rObserver = {
observe : function(subject, topic, data) { torbutton_setButtonFromPreference(); }
};
torbutton_log(1, 'getting service');
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
torbutton_log(1, 'getting branch');
var rBranch = prefService.getBranch("network.");
torbutton_log(1, 'quering interface');
var pbi = rBranch.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
torbutton_log(1, 'adding observer');
pbi.addObserver("proxy", rObserver, false);
m_wasinited = true;
} else {
torbutton_log(1, 'skipping observers init');
}
torbutton_log(1, 'setting from prefs');
torbutton_setButtonFromPreference();
torbutton_log(1, 'init completed');
}
function torbutton_init_toolbutton() {
torbutton_log(1, 'called init_toolbutton()');
if (!m_toolbutton) {
torbutton_log(1, 'looking for button element');
if (document.getElementById("torbutton-button")) {
m_toolbutton = document.getElementById("torbutton-button");
} else {
torbutton_log(1, 'ERROR (init): failed to find torbutton-button');
}
} else {
torbutton_log(1, 'skipping button element search');
}
}
function torbutton_initPrefObjects() {
m_commonprefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
}
function torbutton_check_status() {
torbutton_log(1,'checking tor status');
if ( (m_commonprefs.getIntPref("network.proxy.type") == 0) ||
(m_commonprefs.getCharPref("network.proxy.http") != "localhost") ||
(m_commonprefs.getIntPref("network.proxy.http_port") != 8118) ||
(m_commonprefs.getCharPref("network.proxy.ssl") != "localhost") ||
(m_commonprefs.getIntPref("network.proxy.ssl_port") != 8118) ||
(m_commonprefs.getCharPref("network.proxy.ftp") != "localhost") ||
(m_commonprefs.getIntPref("network.proxy.ftp_port") != 8118) ||
(m_commonprefs.getCharPref("network.proxy.gopher") != "localhost") ||
(m_commonprefs.getIntPref("network.proxy.gopher_port") != 8118) ||
(m_commonprefs.getCharPref("network.proxy.socks") != "localhost") ||
(m_commonprefs.getIntPref("network.proxy.socks_port") != 8118) ||
(m_commonprefs.getIntPref("network.proxy.socks_version") != 4) ||
(m_commonprefs.getCharPref("network.proxy.no_proxies_on") != "localhost, 127.0.0.1") ||
(m_commonprefs.getIntPref("network.proxy.type") != 1) )
{
return false;
// torbutton_log(1,'tor is disabled');
// torbutton_update_status(0);
} else {
return true;
// torbutton_log(1,'tor is enabled');
// torbutton_update_status(1);
}
}
function torbutton_setButtonFromPreference() {
if (torbutton_check_status()) {
torbutton_log(1,'tor is enabled');
torbutton_update_status(1);
} else {
torbutton_log(1,'tor is disabled');
torbutton_update_status(0);
}
}
function torbutton_disable_tor() {
torbutton_log(1, 'called disable_tor()');
m_commonprefs.setIntPref("network.proxy.type", 0);
}
function torbutton_enable_tor() {
torbutton_log(1, 'called enable_tor()');
m_commonprefs.setCharPref("network.proxy.http", "localhost");
m_commonprefs.setIntPref("network.proxy.http_port", 8118);
m_commonprefs.setCharPref("network.proxy.ssl", "localhost");
m_commonprefs.setIntPref("network.proxy.ssl_port", 8118);
m_commonprefs.setCharPref("network.proxy.ftp", "localhost");
m_commonprefs.setIntPref("network.proxy.ftp_port", 8118);
m_commonprefs.setCharPref("network.proxy.gopher", "localhost");
m_commonprefs.setIntPref("network.proxy.gopher_port", 8118);
m_commonprefs.setCharPref("network.proxy.socks", "localhost");
m_commonprefs.setIntPref("network.proxy.socks_port", 8118);
m_commonprefs.setIntPref("network.proxy.socks_version", 4);
m_commonprefs.setCharPref("network.proxy.no_proxies_on", "localhost, 127.0.0.1");
m_commonprefs.setIntPref("network.proxy.type", 1);
}
function torbutton_update_status(nMode) {
var sPrefix;
torbutton_log(1, 'called update_status('+nMode+')');
if (nMode == 0) {
if (m_toolbutton) {
m_toolbutton.setAttribute('tbstatus', 'off');
m_toolbutton.setAttribute('tooltiptext', m_stringbundle.GetStringFromName("torbutton.button.tooltip.disabled"));
}
m_statuspanel.style.color = "#F00";
m_statuspanel.setAttribute('label', m_stringbundle.GetStringFromName("torbutton.panel.label.disabled"));
m_statuspanel.setAttribute('tooltiptext', m_stringbundle.GetStringFromName("torbutton.panel.tooltip.disabled"));
} else {
if (m_toolbutton) {
m_toolbutton.setAttribute('tbstatus', 'on');
m_toolbutton.setAttribute('tooltiptext', m_stringbundle.GetStringFromName("torbutton.button.tooltip.disabled"));
}
m_statuspanel.style.color = "#390";
m_statuspanel.setAttribute('label', m_stringbundle.GetStringFromName("torbutton.panel.label.enabled"));
m_statuspanel.setAttribute('tooltiptext', m_stringbundle.GetStringFromName("torbutton.panel.tooltip.enabled"));
}
}
function torbutton_log(nLevel, sMsg) {
if (m_tb_logger) {
var rDate = new Date();
m_tb_logger.log(nLevel, rDate.getTime()+': '+sMsg);
}
}
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://torbutton/skin/torbutton.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://torbutton/locale/torbutton.dtd">
<overlay id="torbutton-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://torbutton/content/torbutton.js" />
<script language="JavaScript">
//onLoad Hander
try{window.addEventListener("load", torbutton_init, false);}catch(e){}
</script>
<stringbundleset id="torbutton-stringbundleset">
<stringbundle id="torbutton-bundle" src="chrome://torbutton/locale/torbutton.properties"/>
</stringbundleset>
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton
id="torbutton-button"
class="toolbarbutton-1"
tooltiptext="&torbuttonTooltip;"
label="&torbuttonButton.label;"
oncommand="torbutton_toggle();" />
</toolbarpalette>
<statusbar id="status-bar">
<statusbarpanel id="torbutton-panel"
label="torbutton"
insertbefore="statusbar-updates"
onclick="torbutton_toggle()" />
</statusbar>
</overlay>
<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<!-- skins supplied by this package -->
<RDF:Seq about="urn:mozilla:locale:root">
<RDF:li resource="urn:mozilla:locale:en-US"/>
</RDF:Seq>
<!-- locale information -->
<RDF:Description about="urn:mozilla:locale:en-US">
<chrome:packages>
<RDF:Seq about="urn:mozilla:locale:en-US:packages">
<RDF:li resource="urn:mozilla:locale:en-US:torbutton"/>
</RDF:Seq>
</chrome:packages>
</RDF:Description>
</RDF:RDF>
<!ENTITY torbuttonButton.label "TorButton">
<!ENTITY torbuttonTooltip "Turn Tor on/off">
torbutton.button.tooltip.disabled = Enable Tor
torbutton.button.tooltip.enabled = Disable Tor
torbutton.panel.tooltip.disabled = Click to enable Tor
torbutton.panel.tooltip.enabled = Click to disable Tor
torbutton.panel.label.disabled = Tor Disabled
torbutton.panel.label.enabled = Tor Enabled
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<Seq about="urn:mozilla:skin:root">
<li resource="urn:mozilla:skin:classic/1.0"/>
</Seq>
<Description about="urn:mozilla:skin:classic/1.0">
<chrome:packages>
<Seq about="urn:mozilla:skin:classic/1.0:packages">
<li resource="urn:mozilla:skin:classic/1.0:torbutton"/>
</Seq>
</chrome:packages>
</Description>
<Seq about="urn:mozilla:stylesheets">
<li resource="chrome://browser/content/browser.xul"/>
<li resource="chrome://global/content/customizeToolbar.xul"/>
</Seq>
<!-- FireFox -->
<Seq about="chrome://browser/content/browser.xul">
<li>chrome://torbutton/skin/torbutton.css</li>
</Seq>
<Seq about="chrome://global/content/customizeToolbar.xul">
<li>chrome://torbutton/skin/torbutton.css</li>
</Seq>
</RDF>
#torbutton-button {
list-style-image: url("chrome://torbutton/skin/bigbutton.png");
}
#torbutton-button[tbstatus="on"] {
list-style-image: url("chrome://torbutton/skin/bigbutton_gr.png");
}
#torbutton-button[tbstatus="off"] {
list-style-image: url("chrome://torbutton/skin/bigbutton.png");
}
toolbar[iconsize="small"] #torbutton-button {
list-style-image: url("chrome://torbutton/skin/smallbutton.png");
}
toolbar[iconsize="small"] #torbutton-button[tbstatus="on"] {
list-style-image: url("chrome://torbutton/skin/smallbutton_gr.png");
}
toolbar[iconsize="small"] #torbutton-button[tbstatus="off"] {
list-style-image: url("chrome://torbutton/skin/smallbutton.png");
}
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:creator>Scott Squires</em:creator>
<em:description>TorButton provides a button to easily enable or disable the tor proxy</em:description>
<em:id>{e0204bd5-9d31-402b-a99d-a6aa8ffebdca}</em:id>
<em:name>TorButton</em:name>
<em:version>1.0</em:version>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>0.9</em:minVersion>
<em:maxVersion>1.5.0.1</em:maxVersion>
</Description>
</em:targetApplication>
<em:file>
<Description about="urn:mozilla:extension:file:torbutton.jar">
<em:package>content/</em:package>
<em:locale>locale/en-US/</em:locale>
<em:skin>skin/classic/</em:skin>
</Description>
</em:file>
<em:file>
<Description resource="urn:mozilla:extension:file:torbutton.jar"/>
</em:file>
</Description>
</RDF>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment