[or-cvs] r13846: Migrate history hooks to nsISHistoryListeners. (in torbutton/trunk/src: . chrome/content)
mikeperry at seul.org
mikeperry at seul.org
Tue Mar 4 07:19:00 UTC 2008
Author: mikeperry
Date: 2008-03-04 02:19:00 -0500 (Tue, 04 Mar 2008)
New Revision: 13846
Modified:
torbutton/trunk/src/chrome/content/jshooks.js
torbutton/trunk/src/chrome/content/torbutton.js
torbutton/trunk/src/install.rdf
Log:
Migrate history hooks to nsISHistoryListeners.
Modified: torbutton/trunk/src/chrome/content/jshooks.js
===================================================================
--- torbutton/trunk/src/chrome/content/jshooks.js 2008-03-04 03:44:52 UTC (rev 13845)
+++ torbutton/trunk/src/chrome/content/jshooks.js 2008-03-04 07:19:00 UTC (rev 13846)
@@ -81,38 +81,6 @@
}
}
- // This can potentially be done by hooking shistory;1 component, but
- // this is simpler and less code.
- if(window.__tb_block_js_history===true) {
- var hold = window.history;
- var hmine = new Object();
- var ran = 0;
-
- hmine.__defineGetter__("length", function() { return 0; });
- var window_alert = window.alert; // save reference to avoid code injection
- var f = function() {
- if(!ran) {
- ran = 1;
- // XXX: Also needs localization
- window_alert("Torbutton blocked Javascript history manipulation.\n\nSee history settings to allow.\n\n");
- }
- }
- hmine.back = f;
- hmine.forward = f;
- hmine.go = f;
-
- window.__defineGetter__("history", function() { return hmine; });
- window.__defineSetter__("history", function(a) { return; });
- window.__proto__.__defineGetter__("history", function() { return hmine; });
-
- // Needed for Firefox bug 418983:
- with(window) {
- var history = hmine;
- }
-
- }
-
-
/* Timezone fix for http://gemal.dk/browserspy/css.html */
var reparseDate = function(d, str) {
/* Rules:
Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js 2008-03-04 03:44:52 UTC (rev 13845)
+++ torbutton/trunk/src/chrome/content/torbutton.js 2008-03-04 07:19:00 UTC (rev 13846)
@@ -978,6 +978,39 @@
}
}
+function tbHistoryListener(browser) {
+ this.browser = browser;
+
+ this.f1 = function() {
+ if(this.browser.__tb_tor_fetched != m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")) {
+ torbutton_log(3, "Blocking history manipulation");
+ window.alert("Torbutton blocked changed-state history manipulation.\n\nSee history settings to allow.\n\n");
+ return false;
+ } else {
+ return true;
+ }
+ };
+}
+
+tbHistoryListener.prototype = {
+ QueryInterface: function(iid) {
+ // XXX: Is this the right way to handle weak references from JS?
+ if(iid.equals(Components.interfaces.nsISHistoryListener) ||
+ iid.equals(Components.interfaces.nsISupports) ||
+ iid.equals(Components.interfaces.nsISupportsWeakReference))
+ return this;
+ else
+ return null;
+ },
+
+ OnHistoryGoBack: function(url) { return this.f1(); },
+ OnHistoryGoForward: function(url) { return this.f1(); },
+ OnHistoryGotoIndex: function(idx, url) { return this.f1(); },
+ OnHistoryNewEntry: function(url) { return true; },
+ OnHistoryPurge: function(ents) { return true; },
+ OnHistoryReload: function(uri,flags) { return this.f1(); }
+};
+
function torbutton_tag_new_browser(browser, tor_tag, no_plugins) {
if (!tor_tag && no_plugins) {
browser.docShell.allowPlugins = tor_tag;
@@ -987,6 +1020,17 @@
if (typeof(browser.__tb_tor_fetched) == 'undefined') {
torbutton_log(3, "Tagging new window: "+tor_tag);
browser.__tb_tor_fetched = !tor_tag;
+
+ /*
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+ */
+
+ // XXX: Do we need to remove this listener on tab close?
+ var hlisten = new tbHistoryListener(browser);
+ browser.webNavigation.sessionHistory.addSHistoryListener(hlisten);
+ browser.__tb_hlistener = hlisten;
+ torbutton_log(2, "Added history listener");
}
}
@@ -1200,6 +1244,7 @@
}
}
+
function torbutton_new_tab(event)
{
// listening for new tabs
@@ -1399,6 +1444,7 @@
}
}
+
function torbutton_update_tags(win) {
torbutton_eclog(2, "Updating tags.");
if(typeof(win.wrappedJSObject) == 'undefined') {
@@ -1429,6 +1475,35 @@
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");
+
+ if(typeof(browser.__tb_tor_fetched) == "undefined") {
+ torbutton_log(5, "Untagged browser at: "+win.location);
+ } else if(browser.__tb_tor_fetched != !tor_tag) {
+ // Purge session history every time we fetch a new doc
+ // in a new tor state
+ torbutton_log(2, "Purging session history");
+ if(browser.webNavigation.sessionHistory.count > 1) {
+ // XXX: This isn't quite right.. For some reason
+ // this breaks in some cases..
+ /*
+ var current = browser.webNavigation
+ .QueryInterface(Components.interfaces.nsIDocShellHistory)
+ .getChildSHEntry(0).clone(); // XXX: Use index??
+ */
+ var current = browser.webNavigation.contentViewer.historyEntry;
+
+ browser.webNavigation.sessionHistory.PurgeHistory(
+ browser.webNavigation.sessionHistory.count);
+
+ if(current) {
+ // Add current page back in
+ browser.webNavigation
+ .QueryInterface(Components.interfaces.nsISHistoryInternal)
+ .addChildSHEntry(current, true);
+ }
+ }
+ }
+
browser.__tb_tor_fetched = !tor_tag;
browser.docShell.allowPlugins = tor_tag || !kill_plugins;
browser.docShell.allowJavascript = js_enabled;
Modified: torbutton/trunk/src/install.rdf
===================================================================
--- torbutton/trunk/src/install.rdf 2008-03-04 03:44:52 UTC (rev 13845)
+++ torbutton/trunk/src/install.rdf 2008-03-04 07:19:00 UTC (rev 13846)
@@ -6,7 +6,7 @@
<em:name>Torbutton</em:name>
<em:creator>Scott Squires & Mike Perry</em:creator>
<em:id>{e0204bd5-9d31-402b-a99d-a6aa8ffebdca}</em:id>
- <em:version>1.1.16-alpha</em:version>
+ <em:version>1.1.16-alpha-dev</em:version>
<em:homepageURL>https://torbutton.torproject.org/dev/</em:homepageURL>
<em:optionsURL>chrome://torbutton/content/preferences.xul</em:optionsURL>
<em:iconURL>chrome://torbutton/skin/tor.png</em:iconURL>
More information about the tor-commits
mailing list