rem: torbutton_set_flag(win, "__tb_did_hook"); torbutton_set_flag(doc, "__tb_did_hook");  
context: function torbutton_hookdoc(win, doc) {    torbutton_log(1, "Hooking document: "+doc.location);    if(doc.doctype) {        torbutton_log(2, "Hooking document: "+doc.doctype.name);    }    if (!m_tb_wasinited) {        torbutton_init();    }    var tor_tag = !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");    var js_enabled = m_tb_prefs.getBoolPref("javascript.enabled");       // We can't just tag the document here because it is possible    // to hit reload at just the right point such that the document    // has been cleared but the window remained.    if(torbutton_check_flag(win, "__tb_did_hook")) {        torbutton_log(2, "Already did hook "                 + torbutton_check_flag(win, "__tb_did_hook"));        /* XXX: Remove this once bug #460 is resolved */        /* hrmm.. would doc.isSupported("javascript")          * or doc.implementation.hasFeature() work better? */        if(!tor_tag && doc.contentType.indexOf("text/html") != -1 &&                 torbutton_check_load_state(doc, tor_tag) &&                 !torbutton_check_flag(win.window.wrappedJSObject,                     "__tb_hooks_ran")) {            torbutton_log(5, "FALSE WIN HOOKING. Please report bug+website!");            win.alert("False win hooking. Please report bug+website!");        }        return; // Ran already    }    // We also can't just tag the window either, because it gets    // cleared on back/fwd(!??)    if(torbutton_check_flag(doc, "__tb_did_hook")) {        /* XXX: Remove this once bug #460 is resolved */        torbutton_log(4, "Hrmm.. Partial checked hook: "                + torbutton_check_flag(win, "__tb_did_hook"));        if(!tor_tag && doc.contentType.indexOf("text/html") != -1 &&                 torbutton_check_load_state(doc, tor_tag) &&                 !torbutton_check_flag(win.window.wrappedJSObject, "__tb_hooks_ran")) {            torbutton_log(5, "FALSE DOC HOOKING. Please report bug+website!");            win.alert("False doc hooking. Please report bug+website!");        }         return; // Ran already    }    var browser = getBrowser();    var kill_plugins = m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins");    // TODO: try nsIWindowWatcher.getChromeForWindow()    // Find proper browser for this document.. ugh.    for (var i = 0; i < browser.browsers.length; ++i) {        var b = browser.browsers[i];        if (b && b.contentDocument == doc) {            b.__tb_js_state = tor_tag;            b.docShell.allowPlugins = tor_tag || !kill_plugins;            b.docShell.allowJavascript = js_enabled;        }    }    torbutton_log(1, "JS set to: " + js_enabled);        if(!js_enabled) // XXX: bug #460 hack        win.window.wrappedJSObject.__tb_hooks_ran = true;     // No need to hook js if tor is off    if(!js_enabled             || !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")             || !m_tb_prefs.getBoolPref('extensions.torbutton.kill_bad_js')) {        torbutton_log(2, "Finished non-hook of: " + doc.location);        torbutton_set_flag(win, "__tb_did_hook");        torbutton_set_flag(doc, "__tb_did_hook");        return;    }    // Date Hooking:    /* Q: Do this better with XPCOM?     *    http://www.mozilla.org/projects/xpcom/nsIClassInfo.html     * A: Negatory.. Date() is not an XPCOM component :(     */        // So it looks like the race condition is actually a result of    // the insertion function returning before the injected code is evaluated.    // This code seems to do what we want.    var str2 = "with(window) { window.__tb_set_uagent="+m_tb_prefs.getBoolPref('extensions.torbutton.set_uagent')+";\r\n";    str2 += "window.__tb_oscpu=\""+m_tb_prefs.getCharPref('extensions.torbutton.oscpu_override')+"\";\r\n";    str2 += "window.__tb_platform=\""+m_tb_prefs.getCharPref('extensions.torbutton.platform_override')+"\";\r\n";    str2 += "window.__tb_productSub=\""+m_tb_prefs.getCharPref('extensions.torbutton.productsub_override')+"\";\r\n";    str2 += m_tb_jshooks + "}";    torbutton_log(2, "Document: " + doc.domain);    var s = new Components.utils.Sandbox(win.window.wrappedJSObject);    s.window = win.window.wrappedJSObject;    Components.utils.evalInSandbox(str2, s);    torbutton_set_flag(win, "__tb_did_hook");    torbutton_set_flag(doc, "__tb_did_hook");        torbutton_log(2, "Finished hook: " + doc.location);    return;}
meta: 3444	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/3444/d7fa2ee3fa22d7de4aa431af5e6efb51d42b28f7/torbutton.js/clean/src/chrome/content/torbutton.js