From 6c3eefe6f9400dc7a676c8e835f6d2ddc9cf6c91 Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 17 May 2011 23:40:03 +0800 Subject: [PATCH] Issue #85: window.openDatabase throws DOM Exception 18 on Android 3.1 Instead of checking the userAgent catch the exception. If we do get an exception it will setup our version of Droid Db. --- framework/assets/js/storage.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/framework/assets/js/storage.js b/framework/assets/js/storage.js index 6915a366..125c78c5 100755 --- a/framework/assets/js/storage.js +++ b/framework/assets/js/storage.js @@ -397,17 +397,29 @@ PhoneGap.addConstructor(function() { navigator.openDatabase = window.openDatabase = DroidDB_openDatabase; window.droiddb = new DroidDB(); } - if ((typeof window.openDatabase === "undefined") || (navigator.userAgent.indexOf("Android 3.") != -1)) { + if (typeof window.openDatabase === "undefined") { setupDroidDB(); } else { window.openDatabase_orig = window.openDatabase; - window.openDatabase = function(name, version, desc, size) { - var db = window.openDatabase_orig(name, version, desc, size); - if (db == null) { - setupDroidDB(); - return DroidDB_openDatabase(name, version, desc, size); - } else return db; - } + window.openDatabase = function(name, version, desc, size){ + // Some versions of Android will throw a SECURITY_ERR so we need + // to catch the exception and seutp our own DB handling. + var db = null; + try { + db = window.openDatabase_orig(name, version, desc, size); + } + catch (ex) { + db = null; + } + + if (db == null) { + setupDroidDB(); + return DroidDB_openDatabase(name, version, desc, size); + } + else { + return db; + } + } } if (typeof window.localStorage === "undefined") {