[or-cvs] r12518: Seperate hooking code from plugin blocking code. Fix a scope (torbutton/trunk/src/chrome/content)
mikeperry at seul.org
mikeperry at seul.org
Sat Nov 17 02:31:56 UTC 2007
Author: mikeperry
Date: 2007-11-16 21:31:56 -0500 (Fri, 16 Nov 2007)
New Revision: 12518
Modified:
torbutton/trunk/src/chrome/content/jshooks.js
torbutton/trunk/src/chrome/content/torbutton.js
Log:
Seperate hooking code from plugin blocking code. Fix a scope
issue w/ the jshooks.
Modified: torbutton/trunk/src/chrome/content/jshooks.js
===================================================================
--- torbutton/trunk/src/chrome/content/jshooks.js 2007-11-17 02:30:31 UTC (rev 12517)
+++ torbutton/trunk/src/chrome/content/jshooks.js 2007-11-17 02:31:56 UTC (rev 12518)
@@ -14,8 +14,8 @@
var tmp_oscpu = window.__tb_oscpu;
var tmp_platform = window.__tb_platform;
var tmp_productSub = window.__tb_productSub;
- navigator.__defineGetter__("oscpu", function() { return tmp_oscpu;});
- navigator.__defineGetter__("productSub", function() { return tmp_productSub;});
+ window.navigator.__defineGetter__("oscpu", function() { return tmp_oscpu;});
+ window.navigator.__defineGetter__("productSub", function() { return tmp_productSub;});
/*navigator.__defineGetter__("platform", function() { return tmp_platform;});*/
}
@@ -53,8 +53,8 @@
}
}
- var tmp = Date;
- Date = function() {
+ var tmp = window.Date;
+ window.Date = function() {
/* DO NOT make 'd' a member! EvilCode will use it! */
var d;
var a = arguments;
@@ -77,62 +77,62 @@
}
}
- Date.prototype.valueOf=Date.prototype.getTime = /* UTC already */
+ window.Date.prototype.valueOf=window.Date.prototype.getTime = /* UTC already */
function(){return d.getTime();}
- Date.prototype.getFullYear=function(){return d.getUTCFullYear();}
- Date.prototype.getYear=function() {return d.getYear();}
- Date.prototype.getMonth=function(){return d.getUTCMonth();}
- Date.prototype.getDate=function() {return d.getUTCDate();}
- Date.prototype.getDay=function() {return d.getUTCDay();}
- Date.prototype.getHours=function(){return d.getUTCHours();}
- Date.prototype.getMinutes=function(){return d.getUTCMinutes();}
- Date.prototype.getSeconds=function(){return d.getUTCSeconds();}
- Date.prototype.getMilliseconds=function(){return d.getUTCMilliseconds();}
- Date.prototype.getTimezoneOffset=function(){return 0;}
+ window.Date.prototype.getFullYear=function(){return d.getUTCFullYear();}
+ window.Date.prototype.getYear=function() {return d.getYear();}
+ window.Date.prototype.getMonth=function(){return d.getUTCMonth();}
+ window.Date.prototype.getDate=function() {return d.getUTCDate();}
+ window.Date.prototype.getDay=function() {return d.getUTCDay();}
+ window.Date.prototype.getHours=function(){return d.getUTCHours();}
+ window.Date.prototype.getMinutes=function(){return d.getUTCMinutes();}
+ window.Date.prototype.getSeconds=function(){return d.getUTCSeconds();}
+ window.Date.prototype.getMilliseconds=function(){return d.getUTCMilliseconds();}
+ window.Date.prototype.getTimezoneOffset=function(){return 0;}
- Date.prototype.setTime =
+ window.Date.prototype.setTime =
function(x) {return d.setTime(x);}
- Date.prototype.setFullYear=function(x){return d.setUTCFullYear(x);}
- Date.prototype.setYear=function(x){return d.setYear(x);}
- Date.prototype.setMonth=function(x){return d.setUTCMonth(x);}
- Date.prototype.setDate=function(x){return d.setUTCDate(x);}
- Date.prototype.setDay=function(x){return d.setUTCDay(x);}
- Date.prototype.setHours=function(x){return d.setUTCHours(x);}
- Date.prototype.setMinutes=function(x){return d.setUTCMinutes(x);}
- Date.prototype.setSeconds=function(x){return d.setUTCSeconds(x);}
- Date.prototype.setMilliseconds=
+ window.Date.prototype.setFullYear=function(x){return d.setUTCFullYear(x);}
+ window.Date.prototype.setYear=function(x){return d.setYear(x);}
+ window.Date.prototype.setMonth=function(x){return d.setUTCMonth(x);}
+ window.Date.prototype.setDate=function(x){return d.setUTCDate(x);}
+ window.Date.prototype.setDay=function(x){return d.setUTCDay(x);}
+ window.Date.prototype.setHours=function(x){return d.setUTCHours(x);}
+ window.Date.prototype.setMinutes=function(x){return d.setUTCMinutes(x);}
+ window.Date.prototype.setSeconds=function(x){return d.setUTCSeconds(x);}
+ window.Date.prototype.setMilliseconds=
function(x) {return d.setUTCMilliseconds(x);}
- Date.prototype.getUTCFullYear=function(){return d.getUTCFullYear();}
- Date.prototype.getUTCMonth=function(){return d.getUTCMonth();}
- Date.prototype.getUTCDate=function() {return d.getUTCDate();}
- Date.prototype.getUTCDay=function() {return d.getUTCDay();}
- Date.prototype.getUTCHours=function(){return d.getUTCHours();}
- Date.prototype.getUTCMinutes=function(){return d.getUTCMinutes();}
- Date.prototype.getUTCSeconds=function(){return d.getUTCSeconds();}
- Date.prototype.getUTCMilliseconds=
+ window.Date.prototype.getUTCFullYear=function(){return d.getUTCFullYear();}
+ window.Date.prototype.getUTCMonth=function(){return d.getUTCMonth();}
+ window.Date.prototype.getUTCDate=function() {return d.getUTCDate();}
+ window.Date.prototype.getUTCDay=function() {return d.getUTCDay();}
+ window.Date.prototype.getUTCHours=function(){return d.getUTCHours();}
+ window.Date.prototype.getUTCMinutes=function(){return d.getUTCMinutes();}
+ window.Date.prototype.getUTCSeconds=function(){return d.getUTCSeconds();}
+ window.Date.prototype.getUTCMilliseconds=
function(){return d.getUTCMilliseconds();}
- Date.prototype.setUTCFullYear=function(x){return d.setUTCFullYear(x);}
- Date.prototype.setUTCMonth=function(x){return d.setUTCMonth(x);}
- Date.prototype.setUTCDate=function(x){return d.setUTCDate(x);}
- Date.prototype.setUTCDay=function(x){return d.setUTCDay(x);}
- Date.prototype.setUTCHours=function(x){return d.setUTCHours(x);}
- Date.prototype.setUTCMinutes=function(x){return d.setUTCMinutes(x);}
- Date.prototype.setUTCSeconds=function(x){return d.setUTCSeconds(x);}
- Date.prototype.setUTCMilliseconds=
+ window.Date.prototype.setUTCFullYear=function(x){return d.setUTCFullYear(x);}
+ window.Date.prototype.setUTCMonth=function(x){return d.setUTCMonth(x);}
+ window.Date.prototype.setUTCDate=function(x){return d.setUTCDate(x);}
+ window.Date.prototype.setUTCDay=function(x){return d.setUTCDay(x);}
+ window.Date.prototype.setUTCHours=function(x){return d.setUTCHours(x);}
+ window.Date.prototype.setUTCMinutes=function(x){return d.setUTCMinutes(x);}
+ window.Date.prototype.setUTCSeconds=function(x){return d.setUTCSeconds(x);}
+ window.Date.prototype.setUTCMilliseconds=
function(x) {return d.setUTCMilliseconds(x);}
- Date.prototype.toUTCString=function(){return d.toUTCString();}
- Date.prototype.toGMTString=function(){return d.toGMTString();}
- Date.prototype.toString=function(){return d.toUTCString();}
- Date.prototype.toLocaleString=function(){return d.toUTCString();}
+ window.Date.prototype.toUTCString=function(){return d.toUTCString();}
+ window.Date.prototype.toGMTString=function(){return d.toGMTString();}
+ window.Date.prototype.toString=function(){return d.toUTCString();}
+ window.Date.prototype.toLocaleString=function(){return d.toUTCString();}
/* Fuck 'em if they can't take a joke: */
- Date.prototype.toLocaleTimeString=function(){return d.toUTCString();}
- Date.prototype.toLocaleDateString=function(){return d.toUTCString();}
- Date.prototype.toDateString=function(){return d.toUTCString();}
- Date.prototype.toTimeString=function(){return d.toUTCString();}
+ window.Date.prototype.toLocaleTimeString=function(){return d.toUTCString();}
+ window.Date.prototype.toLocaleDateString=function(){return d.toUTCString();}
+ window.Date.prototype.toDateString=function(){return d.toUTCString();}
+ window.Date.prototype.toTimeString=function(){return d.toUTCString();}
/* Hack to solve the problem of multiple date objects
* all sharing the same lexically scoped d every time a new one is
@@ -143,29 +143,26 @@
* this function we modified Date.prototype to create the new methods
* with the lexically scoped d reference.
*/
- Date.prototype = new Object.prototype.toSource();
+ window.Date.prototype = new Object.prototype.toSource();
return d.toUTCString();
}
- Date.parse=function(s) {
+ window.Date.parse=function(s) {
var d = new tmp(s);
if(typeof(s) == "string") reparseDate(d, s);
return d.getTime();
}
- Date.now=function(){return tmp.now();}
- Date.UTC=function(){return tmp.apply(tmp, arguments); }
+ window.Date.now=function(){return tmp.now();}
+ window.Date.UTC=function(){return tmp.apply(tmp, arguments); }
return true;
}
if (typeof(window.__HookObjects) != "undefined") {
- // XXX: Woah.. scope issues with this var if it
- // has the same name as a div id?? That doesn't make
- // any sense..
- var __tb_res = 23;
+ var res = 23;
if(!window.__HookObjects()) {
- __tb_res = 13;
+ res = 13;
}
window.__HookObjects = undefined;
@@ -178,7 +175,7 @@
window.__tb_hooks_ran = true;
- __tb_res; // Secret result code.
+ res; // Secret result code.
} else {
42;
}
Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js 2007-11-17 02:30:31 UTC (rev 12517)
+++ torbutton/trunk/src/chrome/content/torbutton.js 2007-11-17 02:31:56 UTC (rev 12518)
@@ -816,6 +816,7 @@
kill_plugins) {
var browser = win.getBrowser();
var browsers = browser.browsers;
+ torbutton_log(1, "Toggle window plugins");
for (var i = 0; i < browsers.length; ++i) {
var b = browser.browsers[i];
@@ -839,7 +840,7 @@
// This is an ugly beast.. But unfortunately it has to be so..
// Looping over all tabs twice is not somethign we wanna do..
function torbutton_toggle_jsplugins(tor_enabled, isolate_dyn, kill_plugins) {
- torbutton_log(1, "Tor state: "+tor_enabled);
+ torbutton_log(1, "Toggle plugins for: "+tor_enabled);
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var enumerator = wm.getEnumerator("navigator:browser");
@@ -1122,6 +1123,44 @@
}
}
+function torbutton_update_tags(win) {
+ torbutton_eclog(2, "Updating tags.");
+ if(typeof(win.wrappedJSObject) == 'undefined') {
+ torbutton_eclog(3, "No JSObject: "+win.location);
+ return;
+ }
+
+ var wm = Components.classes["@torproject.org/content-window-mapper;1"]
+ .getService(Components.interfaces.nsISupports)
+ .wrappedJSObject;
+
+ // Expire the cache on page loads. FIXME: Do a timer instead..
+ if(win == win.top) wm.expireOldCache();
+
+ var browser = wm.getBrowserForContentWindow(win.top);
+ if(!browser) {
+ torbutton_log(5, "No window found!1");
+ return;
+ //win.alert("No window found!");
+ }
+ torbutton_log(2, "Got browser "+browser.contentDocument.location+" for: "
+ + win.location);
+
+ var tor_tag = !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");
+ var js_enabled = m_tb_prefs.getBoolPref("javascript.enabled");
+ var kill_plugins = m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins");
+
+ if (!torbutton_check_flag(win.top, "__tb_did_tag")) {
+ torbutton_log(2, "Tagging browser for: " + win.location);
+ torbutton_set_flag(win.top, "__tb_did_tag");
+ browser.__tb_tor_fetched = !tor_tag;
+ browser.docShell.allowPlugins = tor_tag || !kill_plugins;
+ browser.docShell.allowJavascript = js_enabled;
+ }
+
+ torbutton_log(2, "Tags updated.");
+}
+
// XXX: Same-origin policy may prevent our hooks from applying
// to inner iframes.. Test with frames, iframes, and
// popups. Test these extensively:
@@ -1139,46 +1178,18 @@
// - pure javascript pages/non-text/html pages
// - Messing with variables/existing hooks
function torbutton_hookdoc(win, doc) {
- if (!m_tb_wasinited) {
- torbutton_init();
- }
-
if(typeof(win.wrappedJSObject) == 'undefined') {
- torbutton_log(3, "No JSObject: "+doc.location);
+ torbutton_eclog(3, "No JSObject: "+win.location);
return;
}
- torbutton_log(2, "Hooking document: "+doc.location);
+ torbutton_log(2, "Hooking document: "+win.location);
if(doc.doctype) {
torbutton_log(2, "Type: "+doc.doctype.name);
}
-
- var wm = Components.classes["@torproject.org/content-window-mapper;1"]
- .getService(Components.interfaces.nsISupports)
- .wrappedJSObject;
+
+ var js_enabled = m_tb_prefs.getBoolPref("javascript.enabled");
- // Expire the cache on page loads. FIXME: Do a timer instead..
- if(win == win.top) wm.expireOldCache();
-
- var browser = wm.getBrowserForContentWindow(win.top);
- if(!browser) win.alert("No window found!");
- torbutton_log(2, "Got browser "+browser.contentDocument.location+" for: "
- + doc.location);
-
- var tor_tag = !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");
- var js_enabled = m_tb_prefs.getBoolPref("javascript.enabled");
- var kill_plugins = m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins");
-
- if (!torbutton_check_flag(win.top, "__tb_did_hook")) {
- torbutton_log(2, "Tagging browser for: " + doc.location);
- torbutton_set_flag(win.top, "__tb_did_hook");
- browser.__tb_tor_fetched = !tor_tag;
- browser.docShell.allowPlugins = tor_tag || !kill_plugins;
- browser.docShell.allowJavascript = js_enabled;
- }
-
- torbutton_log(1, "JS set to: " + js_enabled);
-
if(!js_enabled) // XXX: bug #460 hack
win.wrappedJSObject.__tb_hooks_ran = true;
@@ -1186,7 +1197,7 @@
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_log(2, "Finished non-hook of: " + win.location);
return;
}
@@ -1201,42 +1212,45 @@
// 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";
+ var str2 = "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 + "}";
+ str2 += m_tb_jshooks;
try {
- torbutton_log(2, "Tupe of window: " + typeof(win));
+ torbutton_log(2, "Type of window: " + typeof(win));
torbutton_log(2, "Type of wrapped window: " + typeof(win.wrappedJSObject));
var s = new Components.utils.Sandbox(win.wrappedJSObject);
s.window = win.wrappedJSObject;
var result = Components.utils.evalInSandbox(str2, s);
if(result === 23) { // secret confirmation result code.
- torbutton_log(3, "Javascript hooks applied successfully at: " + doc.location);
+ torbutton_log(3, "Javascript hooks applied successfully at: " + win.location);
} else if(result === 13) {
- torbutton_log(3, "Double-hook at: " + doc.location);
+ torbutton_log(3, "Double-hook at: " + win.location);
} else {
win.alert("Sandbox evaluation failed. Date hooks not applied!");
- torbutton_log(5, "Hook evaluation failure at " + doc.location);
+ torbutton_log(5, "Hook evaluation failure at " + win.location);
}
} catch (e) {
win.alert("Exception in sandbox evaluation. Date hooks not applied:\n"+e);
- torbutton_log(5, "Hook exception at: "+doc.location+", "+e);
+ torbutton_log(5, "Hook exception at: "+win.location+", "+e);
}
- torbutton_log(2, "Finished hook: " + doc.location);
+ torbutton_log(2, "Finished hook: " + win.location);
return;
}
function torbutton_check_progress(aProgress, aRequest) {
+ if (!m_tb_wasinited) {
+ torbutton_init();
+ }
+
// This noise is a workaround for the fact that docShell.allowPlugins
// is ignored when you directly click on a link
try {
var chanreq = aRequest.QueryInterface(Components.interfaces.nsIChannel);
- // XXX: do we need to QI this bastard?
if(chanreq
&& chanreq instanceof Components.interfaces.nsIChannel
&& aRequest.isPending()
@@ -1244,8 +1258,6 @@
&& m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins")) {
torbutton_eclog(2, 'LocChange: '+aRequest.contentType);
- // XXX: This still does not work for pdfs :(
- // NoScript manages to make it work though...
if (aRequest.contentType in m_tb_plugin_mimetypes) {
aRequest.cancel(0x804b0002);
if(aProgress) {
@@ -1280,8 +1292,10 @@
if(aProgress) {
var doc = aProgress.DOMWindow.document;
try {
- if(doc && doc.domain)
+ if(doc && doc.domain) {
+ torbutton_update_tags(aProgress.DOMWindow.window);
torbutton_hookdoc(aProgress.DOMWindow.window, doc);
+ }
} catch(e) {
torbutton_eclog(3, "Hit about:plugins? "+doc.location);
}
More information about the tor-commits
mailing list