[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r15634: Patch from arno to restore cookie jar functionality in FF3. (in torbutton/trunk/src: . chrome/content components)
Author: mikeperry
Date: 2008-07-03 20:53:50 -0400 (Thu, 03 Jul 2008)
New Revision: 15634
Modified:
torbutton/trunk/src/chrome/content/torbutton.js
torbutton/trunk/src/components/cookie-jar-selector.js
torbutton/trunk/src/install.rdf
Log:
Patch from arno to restore cookie jar functionality in FF3.
Thanks arno!
Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js 2008-07-03 21:55:47 UTC (rev 15633)
+++ torbutton/trunk/src/chrome/content/torbutton.js 2008-07-04 00:53:50 UTC (rev 15634)
@@ -1248,12 +1248,13 @@
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
+ /*
if(m_tb_ff3) {
var o_stringbundle = torbutton_get_stringbundle();
var warning = o_stringbundle.GetStringFromName("torbutton.popup.ff3.cookie_warning");
window.alert(warning);
return;
- }
+ }*/
if(mode) {
selector.saveCookies("nontor");
Modified: torbutton/trunk/src/components/cookie-jar-selector.js
===================================================================
--- torbutton/trunk/src/components/cookie-jar-selector.js 2008-07-03 21:55:47 UTC (rev 15633)
+++ torbutton/trunk/src/components/cookie-jar-selector.js 2008-07-04 00:53:50 UTC (rev 15634)
@@ -67,6 +67,42 @@
}
};
+ var loadCookiesFromFile = function(aFile) {
+ var storageService = Cc["@mozilla.org/storage/service;1"]
+ .getService(Ci.mozIStorageService);
+ try {
+ var mDBConn = storageService.openDatabase(aFile);
+ } catch(e) {
+ this.logger.log(5, "Cookie file open exception: "+e);
+ return;
+ }
+ if (!mDBConn.tableExists("moz_cookies")) { // Should not happen
+ this.logger.log(5, "No cookies table!");
+ return;
+ }
+ if (mDBConn.schemaVersion != 2) { // Should not happen
+ this.logger.log(5, "Cookies table version mismatch");
+ return;
+ }
+
+ var cookieManager = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
+
+ var stmt = mDBConn.createStatement("SELECT id, name, value, host, path, expiry, lastAccessed, isSecure, isHttpOnly FROM moz_cookies");
+
+ while (stmt.executeStep()) {
+ var name = stmt.getUTF8String(1);
+ var value = stmt.getUTF8String(2);
+ var host = stmt.getUTF8String(3);
+ var path = stmt.getUTF8String(4);
+ var expiry = stmt.getInt64(5);
+ var lastAccessed = stmt.getInt64(6);
+ var isSecure = (stmt.getInt32(7) != 0);
+ var isHttpOnly = (stmt.getInt32(8) != 0);
+ cookieManager.QueryInterface(Ci.nsICookieManager2).add(host, path, name, value, isSecure, isHttpOnly, false, expiry);
+ }
+ stmt.reset();
+ };
+
this.clearCookies = function() {
Cc["@mozilla.org/cookiemanager;1"]
.getService(Ci.nsICookieManager)
@@ -90,19 +126,36 @@
this.loadCookies = function(name, deleteSavedCookieJar) {
var cookieManager =
Cc["@mozilla.org/cookiemanager;1"]
- .getService(Ci.nsICookieManager);
- cookieManager.QueryInterface(Ci.nsIObserver);
+ .getService(Ci.nsIObserver);
// Tell the cookie manager to unload cookies from memory and disk
var context = "shutdown-cleanse";
cookieManager.observe(this, "profile-before-change", context);
- // Replace the cookies.txt file with the loaded data
var fn = deleteSavedCookieJar ? moveProfileFile : copyProfileFile;
- fn("cookies-"+name+this.extn, "cookies"+this.extn);
// Tell the cookie manager to reload cookies from disk
- cookieManager.observe(this, "profile-do-change", context);
+ if (this.is_ff3) {
+ var cookieFile = getProfileFile("cookies-"+name+this.extn);
+ // Workaround for Firefox bug 439384:
+ loadCookiesFromFile(cookieFile);
+ // Tell the cookie manager to unload cookies from memory
+ // and sync to disk.
+ cookieManager.observe(this, "profile-before-change", "");
+ // Tell the cookie manager to reload cookies from disk
+ cookieManager.observe(this, "profile-do-change", "");
+
+ // Following fails b/c of FF Bug 439384. It is the alternative
+ // to the above lines.
+ // Replace the cookies.sqlite file with the loaded data
+ // fn("cookies-"+name+this.extn, "cookies"+this.extn);
+ // still notify cookieManager to call initDB, and reset mDBConn
+ //cookieManager.observe(this, "profile-do-change", context);
+ } else {
+ // Replace the cookies.txt file with the loaded data
+ fn("cookies-"+name+this.extn, "cookies"+this.extn);
+ cookieManager.observe(this, "profile-do-change", context);
+ }
this.logger.log(2, "Cookies reloaded");
};
Modified: torbutton/trunk/src/install.rdf
===================================================================
--- torbutton/trunk/src/install.rdf 2008-07-03 21:55:47 UTC (rev 15633)
+++ torbutton/trunk/src/install.rdf 2008-07-04 00:53:50 UTC (rev 15634)
@@ -6,7 +6,7 @@
<em:name>Torbutton</em:name>
<em:creator>Mike Perry & Scott Squires</em:creator>
<em:id>{e0204bd5-9d31-402b-a99d-a6aa8ffebdca}</em:id>
- <em:version>1.2.0rc4</em:version>
+ <em:version>1.2.0rc4-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>