From 8d812655b71b271d3581167dee2a6d22b863e370 Mon Sep 17 00:00:00 2001 From: Alex Pakhotin Date: Tue, 26 Jul 2011 18:14:52 -0700 Subject: [PATCH] Bug 673969 - System preference for "visible passwords" not followed. r=blassey --- dom/ipc/ContentParent.cpp | 13 ++++++++++++ dom/ipc/ContentParent.h | 1 + dom/ipc/PContent.ipdl | 3 +++ embedding/android/GeckoAppShell.java | 13 ++++++++++++ widget/src/android/AndroidBridge.cpp | 9 ++++++++- widget/src/android/AndroidBridge.h | 3 +++ widget/src/android/nsLookAndFeel.cpp | 30 +++++++++++++++++++++++----- widget/src/android/nsLookAndFeel.h | 5 ++++- 8 files changed, 70 insertions(+), 7 deletions(-) diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index db4d68cf768e..5173be7a7c34 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -599,6 +599,19 @@ ContentParent::RecvGetIconForExtension(const nsCString& aFileExt, const PRUint32 return true; } +bool +ContentParent::RecvGetShowPasswordSetting(PRBool* showPassword) +{ + // default behavior is to show the last password character + *showPassword = PR_TRUE; +#ifdef ANDROID + NS_ASSERTION(AndroidBridge::Bridge() != nsnull, "AndroidBridge is not available"); + if (AndroidBridge::Bridge() != nsnull) + *showPassword = AndroidBridge::Bridge()->GetShowPasswordSetting(); +#endif + return true; +} + NS_IMPL_THREADSAFE_ISUPPORTS4(ContentParent, nsIObserver, nsIThreadObserver, diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index f7f9c4798a79..9498fa815611 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -167,6 +167,7 @@ private: virtual bool RecvGetSystemColors(const PRUint32& colorsCount, InfallibleTArray* colors); virtual bool RecvGetIconForExtension(const nsCString& aFileExt, const PRUint32& aIconSize, InfallibleTArray* bits); + virtual bool RecvGetShowPasswordSetting(PRBool* showPassword); virtual bool RecvStartVisitedQuery(const IPC::URI& uri); diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index f158b72911e7..13281e49a501 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -205,6 +205,9 @@ parent: sync GetIconForExtension(nsCString aFileExt, PRUint32 aIconSize) returns (PRUint8[] bits); + sync GetShowPasswordSetting() + returns (PRBool showPassword); + both: AsyncMessage(nsString aMessage, nsString aJSON); diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index bd03aded95f0..33f998ae1546 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -62,6 +62,7 @@ import android.telephony.*; import android.webkit.MimeTypeMap; import android.media.MediaScannerConnection; import android.media.MediaScannerConnection.MediaScannerConnectionClient; +import android.provider.Settings; import android.util.*; import android.net.Uri; @@ -1366,4 +1367,16 @@ public class GeckoAppShell return activityInfo.loadIcon(pm); } + + public static boolean getShowPasswordSetting() { + try { + int showPassword = + Settings.System.getInt(GeckoApp.mAppContext.getContentResolver(), + Settings.System.TEXT_SHOW_PASSWORD); + return (showPassword > 0); + } + catch (Exception e) { + return false; + } + } } diff --git a/widget/src/android/AndroidBridge.cpp b/widget/src/android/AndroidBridge.cpp index 1d8fc9f445e2..77dcfdd84136 100644 --- a/widget/src/android/AndroidBridge.cpp +++ b/widget/src/android/AndroidBridge.cpp @@ -148,6 +148,7 @@ AndroidBridge::Init(JNIEnv *jEnv, jGetSystemColors = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getSystemColors", "()[I"); jGetIconForExtension = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getIconForExtension", "(Ljava/lang/String;I)[B"); jCreateShortcut = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "createShortcut", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + jGetShowPasswordSetting = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getShowPasswordSetting", "()Z"); jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext")); jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10")); @@ -755,6 +756,13 @@ AndroidBridge::GetIconForExtension(const nsACString& aFileExt, PRUint32 aIconSiz mJNIEnv->ReleaseByteArrayElements(arr, elements, 0); } +bool +AndroidBridge::GetShowPasswordSetting() +{ + ALOG_BRIDGE("AndroidBridge::GetShowPasswordSetting"); + return mJNIEnv->CallStaticBooleanMethod(mGeckoAppShellClass, jGetShowPasswordSetting); +} + void AndroidBridge::SetSurfaceView(jobject obj) { @@ -998,4 +1006,3 @@ AndroidBridge::UnlockBitmap(jobject bitmap) if ((err = AndroidBitmap_unlockPixels(JNI(), bitmap)) != 0) ALOG_BRIDGE("AndroidBitmap_unlockPixels failed! (error %d)", err); } - diff --git a/widget/src/android/AndroidBridge.h b/widget/src/android/AndroidBridge.h index 522257323e10..dc9c3798e31f 100644 --- a/widget/src/android/AndroidBridge.h +++ b/widget/src/android/AndroidBridge.h @@ -212,6 +212,8 @@ public: void GetIconForExtension(const nsACString& aFileExt, PRUint32 aIconSize, PRUint8 * const aBuf); + bool GetShowPasswordSetting(); + struct AutoLocalJNIFrame { AutoLocalJNIFrame(int nEntries = 128) : mEntries(nEntries) { // Make sure there is enough space to store a local ref to the @@ -322,6 +324,7 @@ protected: jmethodID jGetSystemColors; jmethodID jGetIconForExtension; jmethodID jCreateShortcut; + jmethodID jGetShowPasswordSetting; // stuff we need for CallEglCreateWindowSurface jclass jEGLSurfaceImplClass; diff --git a/widget/src/android/nsLookAndFeel.cpp b/widget/src/android/nsLookAndFeel.cpp index abc8237e4d92..779d3a72a2d6 100644 --- a/widget/src/android/nsLookAndFeel.cpp +++ b/widget/src/android/nsLookAndFeel.cpp @@ -45,9 +45,12 @@ using namespace mozilla; using mozilla::dom::ContentChild; -PRBool nsLookAndFeel::mInitialized = PR_FALSE; +PRBool nsLookAndFeel::mInitializedSystemColors = PR_FALSE; AndroidSystemColors nsLookAndFeel::mSystemColors; +PRBool nsLookAndFeel::mInitializedShowPassword = PR_FALSE; +PRBool nsLookAndFeel::mShowPassword = PR_TRUE; + nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() { @@ -68,7 +71,7 @@ nsLookAndFeel::~nsLookAndFeel() nsresult nsLookAndFeel::GetSystemColors() { - if (mInitialized) + if (mInitializedSystemColors) return NS_OK; if (!AndroidBridge::Bridge()) @@ -76,7 +79,7 @@ nsLookAndFeel::GetSystemColors() AndroidBridge::Bridge()->GetSystemColors(&mSystemColors); - mInitialized = PR_TRUE; + mInitializedSystemColors = PR_TRUE; return NS_OK; } @@ -102,7 +105,7 @@ nsLookAndFeel::CallRemoteGetSystemColors() // so just copy the memory block memcpy(&mSystemColors, colors.Elements(), sizeof(nscolor) * colorsCount); - mInitialized = PR_TRUE; + mInitializedSystemColors = PR_TRUE; return NS_OK; } @@ -112,7 +115,7 @@ nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor &aColor) { nsresult rv = NS_OK; - if (!mInitialized) { + if (!mInitializedSystemColors) { if (XRE_GetProcessType() == GeckoProcessType_Default) rv = GetSystemColors(); else @@ -460,3 +463,20 @@ nsLookAndFeel::GetMetric(const nsMetricFloatID aID, } return rv; } + +/*virtual*/ +PRBool nsLookAndFeel::GetEchoPassword() +{ + if (!mInitializedShowPassword) { + if (XRE_GetProcessType() == GeckoProcessType_Default) { + if (AndroidBridge::Bridge()) + mShowPassword = AndroidBridge::Bridge()->GetShowPasswordSetting(); + else + NS_ASSERTION(AndroidBridge::Bridge() != nsnull, "AndroidBridge is not available!"); + } else { + ContentChild::GetSingleton()->SendGetShowPasswordSetting(&mShowPassword); + } + mInitializedShowPassword = PR_TRUE; + } + return mShowPassword; +} diff --git a/widget/src/android/nsLookAndFeel.h b/widget/src/android/nsLookAndFeel.h index 0f095b044bca..05d637bce2fe 100644 --- a/widget/src/android/nsLookAndFeel.h +++ b/widget/src/android/nsLookAndFeel.h @@ -51,10 +51,13 @@ public: nsresult NativeGetColor(const nsColorID aID, nscolor &aColor); NS_IMETHOD GetMetric(const nsMetricID aID, PRInt32 & aMetric); NS_IMETHOD GetMetric(const nsMetricFloatID aID, float & aMetric); + virtual PRBool GetEchoPassword(); protected: - static PRBool mInitialized; + static PRBool mInitializedSystemColors; static mozilla::AndroidSystemColors mSystemColors; + static PRBool mInitializedShowPassword; + static PRBool mShowPassword; nsresult GetSystemColors(); nsresult CallRemoteGetSystemColors();