Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 30504: fix new identity console errors and replace Services.qms.c…
…lear()
  • Loading branch information
acatarineu committed Oct 7, 2019
1 parent 2abe720 commit baf673f
Showing 1 changed file with 50 additions and 20 deletions.
70 changes: 50 additions & 20 deletions chrome/content/torbutton.js
Expand Up @@ -50,6 +50,20 @@ var m_tb_control_desc = null; // For logging.

var m_tb_domWindowUtils = window.windowUtils;

async function clearData(flags) {
return new Promise((resolve, reject) => {
Services.clearData.deleteData(flags, {
onDataDeleted(code) {
if (code === Cr.NS_OK) {
resolve();
} else {
reject(new Error(`Error deleting data with flags ${flags}: ${code}`));
}
},
});
});
}

// Bug 1506 P1: This object is only for updating the UI for toggling and style
var torbutton_window_pref_observer =
{
Expand Down Expand Up @@ -861,7 +875,7 @@ function torbutton_new_circuit() {
}

// Bug 1506 P4: Needed for New Identity.
function torbutton_new_identity() {
async function torbutton_new_identity() {
try {
// Make sure that we can only click once on New Identiy to avoid race
// conditions leading to failures (see bug 11783 for an example).
Expand All @@ -888,15 +902,15 @@ function torbutton_new_identity() {
m_tb_prefs.setBoolPref("extensions.torbutton.confirm_newnym", !askAgain.value);

if (confirmed) {
torbutton_do_new_identity();
await torbutton_do_new_identity();
} else {
// TODO: Remove the Torbutton menu entry again once we have done our
// security control redesign.
document.getElementById("menu_newIdentity").disabled = false;
document.getElementById("appMenuNewIdentity").disabled = false;
}
} else {
torbutton_do_new_identity();
await torbutton_do_new_identity();
}
} catch(e) {
// If something went wrong make sure we have the New Identity button
Expand Down Expand Up @@ -924,15 +938,18 @@ function torbutton_new_identity() {
* i. clear content prefs
* j. permissions
* k. site security settings (e.g. HSTS)
* l. IndexedDB and asmjscache storage
* l. IndexedDB and other DOM storage
* m. plugin data
* n. media devices
* o. predictor network data
* 3. Sends tor the NEWNYM signal to get a new circuit
* 4. Opens a new window with the default homepage
* 5. Closes this window
*
* XXX: intermediate SSL certificates are not cleared.
*/
// Bug 1506 P4: Needed for New Identity.
function torbutton_do_new_identity() {
async function torbutton_do_new_identity() {
var obsSvc = Services.obs;
torbutton_log(3, "New Identity: Disabling JS");
torbutton_disable_all_js();
Expand Down Expand Up @@ -1074,18 +1091,16 @@ function torbutton_do_new_identity() {
}

torbutton_log(3, "New Identity: Clearing storage");
torbutton_log(3, "New Identity: Clearing plugin data");
torbutton_log(3, "New Identity: Clearing media devices");
torbutton_log(3, "New Identity: Clearing predictor network data");

let orig_quota_test = m_tb_prefs.getBoolPref("dom.quotaManager.testing");
try {
// This works only by setting the pref to `true` otherwise we get an
// exception and nothing is happening.
m_tb_prefs.setBoolPref("dom.quotaManager.testing", true);
Services.qms.clear();
} catch (e) {
torbutton_log(5, "Exception on storage clearing: " + e);
} finally {
m_tb_prefs.setBoolPref("dom.quotaManager.testing", orig_quota_test);
}
await clearData(
Services.clearData.CLEAR_DOM_STORAGES |
Services.clearData.CLEAR_PLUGIN_DATA |
Services.clearData.CLEAR_MEDIA_DEVICES |
Services.clearData.CLEAR_PREDICTOR_NETWORK_DATA
);

torbutton_log(3, "New Identity: Clearing Cookies and DOM Storage");

Expand Down Expand Up @@ -1156,7 +1171,25 @@ function torbutton_do_new_identity() {
// Open a new window with the TBB check homepage
// In Firefox >=19, can pass {private: true} but we do not need it because
// we have browser.privatebrowsing.autostart = true
OpenBrowserWindow();
let newWindow = OpenBrowserWindow();
let onWindowOpened = function(subject, topic, data) {
if (subject != newWindow) {
return;
}

Services.obs.removeObserver(
onWindowOpened,
"browser-delayed-startup-finished"
);

// Close the current window for added safety
window.close();
};

Services.obs.addObserver(
onWindowOpened,
"browser-delayed-startup-finished"
);

torbutton_log(3, "New identity successful");

Expand Down Expand Up @@ -1192,9 +1225,6 @@ function torbutton_do_new_identity() {

torbutton_log(3, "Completed New Identity GC pass");
});

// Close the current window for added safety
window.close();
}

function torbutton_clear_image_caches()
Expand Down

0 comments on commit baf673f

Please sign in to comment.