Bug 757646 - Errors in the NSSBridge should throw exceptions. r=rnewman

This commit is contained in:
Wes Johnston 2012-05-24 09:47:52 -07:00
Родитель fdc81de78d
Коммит 045940ddb4
3 изменённых файлов: 37 добавлений и 38 удалений

Просмотреть файл

@ -15,49 +15,37 @@ public class NSSBridge {
private static native String nativeEncrypt(String aDb, String aValue);
private static native String nativeDecrypt(String aDb, String aValue);
static public String encrypt(Context context, String aValue) {
static public String encrypt(Context context, String aValue)
throws Exception {
String resourcePath = context.getPackageResourcePath();
GeckoAppShell.loadNSSLibs(context, resourcePath);
String res = "";
try {
String path = GeckoProfile.get(context).getDir().toString();
res = nativeEncrypt(path, aValue);
} catch(Exception ex) { }
return res;
String path = GeckoProfile.get(context).getDir().toString();
return nativeEncrypt(path, aValue);
}
static public String encrypt(Context context, String profilePath, String aValue) {
static public String encrypt(Context context, String profilePath, String aValue)
throws Exception {
String resourcePath = context.getPackageResourcePath();
GeckoAppShell.loadNSSLibs(context, resourcePath);
String res = "";
try {
res = nativeEncrypt(profilePath, aValue);
} catch(Exception ex) { }
return res;
return nativeEncrypt(profilePath, aValue);
}
static public String decrypt(Context context, String aValue) {
static public String decrypt(Context context, String aValue)
throws Exception {
String resourcePath = context.getPackageResourcePath();
GeckoAppShell.loadNSSLibs(context, resourcePath);
String res = "";
try {
String path = GeckoProfile.get(context).getDir().toString();
res = nativeDecrypt(path, aValue);
} catch(Exception ex) { }
return res;
String path = GeckoProfile.get(context).getDir().toString();
return nativeDecrypt(path, aValue);
}
static public String decrypt(Context context, String profilePath, String aValue) {
static public String decrypt(Context context, String profilePath, String aValue)
throws Exception {
String resourcePath = context.getPackageResourcePath();
GeckoAppShell.loadNSSLibs(context, resourcePath);
String res = "";
try {
res = nativeDecrypt(profilePath, aValue);
} catch(Exception ex) { }
return res;
return nativeDecrypt(profilePath, aValue);
}
}

Просмотреть файл

@ -142,7 +142,6 @@ public abstract class GeckoProvider extends ContentProvider {
// call to Gecko. Gecko will handle building the database file correctly, as well as any
// migrations that are necessary
if (dbNeedsSetup) {
Log.i(mLogTag, "Sending init to gecko");
bridge = null;
initGecko();
}
@ -154,7 +153,6 @@ public abstract class GeckoProvider extends ContentProvider {
private SQLiteBridge getDatabaseForProfile(String profile) {
if (TextUtils.isEmpty(profile)) {
Log.d(mLogTag, "No profile provided, using default");
profile = BrowserContract.DEFAULT_PROFILE;
}
@ -167,7 +165,6 @@ public abstract class GeckoProvider extends ContentProvider {
}
}
Log.d(mLogTag, "Successfully created database helper for profile: " + profile);
return db;
}
@ -181,18 +178,15 @@ public abstract class GeckoProvider extends ContentProvider {
}
}
Log.d(mLogTag, "Successfully created database helper for path: " + profilePath);
return db;
}
private String getDatabasePathForProfile(String profile) {
File profileDir = GeckoProfile.get(mContext, profile).getDir();
if (profileDir == null) {
Log.d(mLogTag, "Couldn't find directory for profile: " + profile);
return null;
}
Log.d(mLogTag, "Using path: " + profileDir.getPath());
String databasePath = new File(profileDir, mDBName).getAbsolutePath();
return databasePath;
}

Просмотреть файл

@ -98,6 +98,12 @@ public class PasswordsProvider extends GeckoProvider {
setLogTag("GeckoPasswordsProvider");
setDBName(DB_FILENAME);
setDBVersion(DB_VERSION);
try {
NSSBridge.encrypt(getContext(), "bacon");
} catch (Exception ex) {
Log.e(getLogTag(), "Error starting crypto for PasswordsProvider", ex);
return false;
}
return super.onCreate();
}
@ -203,12 +209,23 @@ public class PasswordsProvider extends GeckoProvider {
}
String result = "";
if (encrypt) {
if (profilePath != null) result = NSSBridge.encrypt(mContext, profilePath, initialValue);
else result = NSSBridge.encrypt(mContext, initialValue);
} else {
if (profilePath != null) result = NSSBridge.decrypt(mContext, profilePath, initialValue);
else result = NSSBridge.decrypt(mContext, initialValue);
try {
if (encrypt) {
if (profilePath != null) {
result = NSSBridge.encrypt(mContext, profilePath, initialValue);
} else {
result = NSSBridge.encrypt(mContext, initialValue);
}
} else {
if (profilePath != null) {
result = NSSBridge.decrypt(mContext, profilePath, initialValue);
} else {
result = NSSBridge.decrypt(mContext, initialValue);
}
}
} catch (Exception ex) {
Log.e(getLogTag(), "Error in NSSBridge", ex);
throw new RuntimeException(ex);
}
return result;
}