Bug 630730 - Let consumers who probably know what they are doing access the database connection
authorShawn Wilsher <me@shawnwilsher.com>
Thu, 03 Feb 2011 14:09:33 -0800
changeset 61907 ab87d34e89fa00423266c8177ee3eb1811e08f61
parent 61879 344de3f6033f1b849a44568fd7ed2188d9e632ac
child 61908 1cb679417a8ba3f4f5e13c7bc880a9c70944f3f8
push id18532
push usersdwilsh@shawnwilsher.com
push dateThu, 03 Feb 2011 22:13:13 +0000
treeherdermozilla-central@aebd2f355859 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs630730
milestone2.0b12pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 630730 - Let consumers who probably know what they are doing access the database connection r=dolske a=Mossop
toolkit/components/passwordmgr/src/nsLoginManager.js
toolkit/components/passwordmgr/src/storage-mozStorage.js
toolkit/components/passwordmgr/test/unit/test_access_db_connection.js
--- a/toolkit/components/passwordmgr/src/nsLoginManager.js
+++ b/toolkit/components/passwordmgr/src/nsLoginManager.js
@@ -45,17 +45,26 @@ Components.utils.import("resource://gre/
 function LoginManager() {
     this.init();
 }
 
 LoginManager.prototype = {
 
     classID: Components.ID("{cb9e0de8-3598-4ed7-857b-827f011ad5d8}"),
     QueryInterface : XPCOMUtils.generateQI([Ci.nsILoginManager,
-                                            Ci.nsISupportsWeakReference]),
+                                            Ci.nsISupportsWeakReference,
+                                            Ci.nsIInterfaceRequestor]),
+    getInterface : function(aIID) {
+      if (aIID.equals(Ci.mozIStorageConnection) && this._storage) {
+        let ir = this._storage.QueryInterface(Ci.nsIInterfaceRequestor);
+        return ir.getInterface(aIID);
+      }
+
+      throw Cr.NS_ERROR_NO_INTERFACE;
+    },
 
 
     /* ---------- private memebers ---------- */
 
 
     __formFillService : null, // FormFillController, for username autocompleting
     get _formFillService() {
         if (!this.__formFillService)
--- a/toolkit/components/passwordmgr/src/storage-mozStorage.js
+++ b/toolkit/components/passwordmgr/src/storage-mozStorage.js
@@ -50,17 +50,25 @@ const ENCTYPE_SDR = 1;
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 function LoginManagerStorage_mozStorage() { };
 
 LoginManagerStorage_mozStorage.prototype = {
 
     classID : Components.ID("{8c2023b9-175c-477e-9761-44ae7b549756}"),
-    QueryInterface : XPCOMUtils.generateQI([Ci.nsILoginManagerStorage]),
+    QueryInterface : XPCOMUtils.generateQI([Ci.nsILoginManagerStorage,
+                                            Ci.nsIInterfaceRequestor]),
+    getInterface : function(aIID) {
+      if (aIID.equals(Ci.mozIStorageConnection)) {
+        return this._dbConnection;
+      }
+
+      throw Cr.NS_ERROR_NO_INTERFACE;
+    },
 
     __crypto : null,  // nsILoginManagerCrypto service
     get _crypto() {
         if (!this.__crypto)
             this.__crypto = Cc["@mozilla.org/login-manager/crypto/SDR;1"].
                             getService(Ci.nsILoginManagerCrypto);
         return this.__crypto;
     },
@@ -1558,15 +1566,16 @@ LoginManagerStorage_mozStorage.prototype
 
         // Finalize all statements to free memory, avoid errors later
         for each (let stmt in this._dbStmts)
             stmt.finalize();
         this._dbStmts = [];
 
         // Close the connection, ignore 'already closed' error
         try { this._dbConnection.close() } catch(e) {}
+        this._dbConnection = null;
         this._signonsFile.remove(false);
     }
 
 }; // end of nsLoginManagerStorage_mozStorage implementation
 
 let component = [LoginManagerStorage_mozStorage];
 var NSGetFactory = XPCOMUtils.generateNSGetFactory(component);
new file mode 100644
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/unit/test_access_db_connection.js
@@ -0,0 +1,23 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const STORAGE_TYPE = "mozStorage";
+
+function run_test()
+{
+  // Make sure that the storage component exposes its database connection.
+  let storage = LoginTest.initStorage(INDIR, "signons-empty.txt", OUTDIR,
+                                      "signons-empty.sqlite");
+  do_check_true(storage instanceof Ci.nsIInterfaceRequestor);
+  let db = storage.getInterface(Ci.mozIStorageConnection);
+  do_check_neq(db, null);
+  do_check_true(db.connectionReady);
+
+  // Make sure that the login manager exposes its the storage component's
+  // database connection.
+  let lm = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
+  do_check_true(lm instanceof Ci.nsIInterfaceRequestor);
+  db = lm.getInterface(Ci.mozIStorageConnection);
+  do_check_neq(db, null);
+  do_check_true(db.connectionReady);
+}