commit 0020d0dda4af8ef64919d27de5f4b2d0f259f395 Author: Mike Perry mikeperry-git@torproject.org Date: Tue Feb 10 16:25:02 2015 -0800
Bug 9442: Add New Circuit button
This adds a button to utilize the domain isolation to get a new circuit for the current tab only. --- src/chrome/content/popup.xul | 5 +++++ src/chrome/content/torbutton.js | 16 ++++++++++++++++ src/chrome/locale/en/torbutton.dtd | 2 ++ src/components/domain-isolator.js | 20 +++++++++++++++++--- 4 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/src/chrome/content/popup.xul b/src/chrome/content/popup.xul index 4117632..e0c1f74 100644 --- a/src/chrome/content/popup.xul +++ b/src/chrome/content/popup.xul @@ -18,6 +18,11 @@ accesskey="&torbutton.context_menu.new_identity_key;" insertafter="context-stop" oncommand="torbutton_new_identity()"/> + <menuitem id="torbutton-new-circuit" + label="&torbutton.context_menu.new_circuit;" + accesskey="&torbutton.context_menu.new_circuit_key;" + insertafter="context-stop" + oncommand="torbutton_new_circuit()"/> <menuseparator/> <menuitem id="torbutton-cookie-protector" label="&torbutton.context_menu.cookieProtections;" diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js index cd534a7..8ae1d5d 100644 --- a/src/chrome/content/torbutton.js +++ b/src/chrome/content/torbutton.js @@ -1552,6 +1552,22 @@ function torbutton_send_ctrl_cmd(command) { } }
+// Bug 1506 P4: Needed for New IP Address +function torbutton_new_circuit() { + let thirdPartyUtil = Cc["@mozilla.org/thirdpartyutil;1"] + .getService(Ci.mozIThirdPartyUtil); + + let firstPartyDomain = thirdPartyUtil + .getFirstPartyHostForIsolation(gBrowser.currentURI); + + let domainIsolator = Cc["@torproject.org/domain-isolator;1"] + .getService(Ci.nsISupports).wrappedJSObject; + + domainIsolator.newCircuitForDomain(firstPartyDomain); + + gBrowser.reloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE); +} + // Bug 1506 P4: Needed for New Identity. function torbutton_new_identity() { try { diff --git a/src/chrome/locale/en/torbutton.dtd b/src/chrome/locale/en/torbutton.dtd index 1b90d63..15ae1e6 100644 --- a/src/chrome/locale/en/torbutton.dtd +++ b/src/chrome/locale/en/torbutton.dtd @@ -24,6 +24,8 @@ <!ENTITY torbutton.pref_connection_more_info.text "Torbutton is currently enabled. If you would like to change your non-Tor proxy settings, please disable Torbutton and return here. If you would like to change your Tor settings, please use the Torbutton preference window."> <!ENTITY torbutton.context_menu.new_identity "New Identity"> <!ENTITY torbutton.context_menu.new_identity_key "I"> +<!ENTITY torbutton.context_menu.new_circuit "New Tor Circuit for this Site"> +<!ENTITY torbutton.context_menu.new_circuit_key "C"> <!ENTITY torbutton.context_menu.toggle "Toggle Tor status"> <!ENTITY torbutton.context_menu.toggle.key "T"> <!ENTITY torbutton.context_menu.preferences "Privacy and Security Settings…"> diff --git a/src/components/domain-isolator.js b/src/components/domain-isolator.js index e8e6bfa..6e6201e 100644 --- a/src/components/domain-isolator.js +++ b/src/components/domain-isolator.js @@ -108,8 +108,10 @@ const kMODULE_CID = Components.ID("e33fd6d4-270f-475f-a96f-ff3140279f68"); // Import XPCOMUtils object. Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-// DomainIsolator object. Constructor does nothing. -function DomainIsolator() { } +// DomainIsolator object. +function DomainIsolator() { + this.wrappedJSObject = this; +} // Firefox component requirements DomainIsolator.prototype = { QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports, Ci.nsIObserver]), @@ -121,7 +123,19 @@ DomainIsolator.prototype = { logger.eclog(3, "domain isolator: set up isolating circuits by domain"); tor.isolateCircuitsByDomain(); } - } + }, + newCircuitForDomain: function (domain) { + // Check if we already have a nonce. If not, create + // one for this domain. + if (!tor.noncesForDomains.hasOwnProperty(domain)) { + tor.noncesForDomains[domain] = 0; + } else { + tor.noncesForDomains[domain] += 1; + } + logger.eclog(3, "New domain isolation count " +tor.noncesForDomains[domain] + " for " + domain); + }, + + wrappedJSObject: null };
// Assign factory to global object.
tor-commits@lists.torproject.org