bug 573669 - Suspend Gecko's event loop when onPause() is called by Android r=vlad

This commit is contained in:
Brad Lassey 2010-06-22 11:22:31 -04:00
Родитель ee3b55bcc3
Коммит 585347c343
5 изменённых файлов: 36 добавлений и 0 удалений

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

@ -161,6 +161,8 @@ abstract public class GeckoApp
@Override
public void onPause()
{
Log.i("GeckoApp", "pause");
GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_PAUSING));
// The user is navigating away from this activity, but nothing
// has come to the foreground yet; for Gecko, we may want to
@ -176,6 +178,10 @@ abstract public class GeckoApp
@Override
public void onResume()
{
Log.i("GeckoApp", "resume");
GeckoAppShell.onResume();
if (surfaceView != null)
surfaceView.mSurfaceNeedsRedraw = true;
// After an onPause, the activity is back in the foreground.
// Undo whatever we did in onPause.
super.onResume();

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

@ -82,6 +82,7 @@ class GeckoAppShell
public static native void setInitialSize(int width, int height);
public static native void setSurfaceView(GeckoSurfaceView sv);
public static native void putenv(String map);
public static native void onResume();
// java-side stuff
public static void loadGeckoLibs() {

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

@ -57,6 +57,7 @@ extern "C" {
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_setSurfaceView(JNIEnv *jenv, jclass, jobject sv);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_setInitialSize(JNIEnv *jenv, jclass, int width, int height);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_putenv(JNIEnv *jenv, jclass, jstring map);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_onResume(JNIEnv *, jclass);
}
@ -106,3 +107,10 @@ Java_org_mozilla_gecko_GeckoAppShell_putenv(JNIEnv *jenv, jclass, jstring map)
jenv->ReleaseStringUTFChars(map, str);
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_onResume(JNIEnv *jenv, jclass jc)
{
if (nsAppShell::gAppShell)
nsAppShell::gAppShell->OnResume();
}

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

@ -79,6 +79,8 @@ nsAppShell::nsAppShell()
: mQueueLock(nsnull),
mCondLock(nsnull),
mQueueCond(nsnull),
mPausedLock(nsnull),
mPaused(nsnull),
mNumDraws(0)
{
gAppShell = this;
@ -111,7 +113,9 @@ nsAppShell::Init()
mQueueLock = PR_NewLock();
mCondLock = PR_NewLock();
mPausedLock = PR_NewLock();
mQueueCond = PR_NewCondVar(mCondLock);
mPaused = PR_NewCondVar(mPausedLock);
return nsBaseAppShell::Init();
}
@ -252,6 +256,10 @@ nsAppShell::ProcessNextNativeEvent(PRBool mayWait)
nsCOMPtr<nsIObserverService> obsServ =
mozilla::services::GetObserverService();
obsServ->NotifyObservers(nsnull, "profile-before-change", nsnull);
// The OS is sending us to the background, block this thread until
// onResume is called to signal that we're back in the foreground
PR_WaitCondVar(mPaused, PR_INTERVAL_NO_TIMEOUT);
break;
}
@ -346,6 +354,15 @@ nsAppShell::RemoveNextEvent()
PR_Unlock(mQueueLock);
}
void
nsAppShell::OnResume()
{
PR_Lock(mPausedLock);
PR_NotifyCondVar(mPaused);
PR_Unlock(mPausedLock);
}
// Used by IPC code
namespace mozilla {

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

@ -68,6 +68,8 @@ public:
void PostEvent(mozilla::AndroidGeckoEvent *event);
void RemoveNextEvent();
void OnResume();
protected:
virtual void ScheduleNativeEventCallback();
virtual ~nsAppShell();
@ -75,7 +77,9 @@ protected:
int mNumDraws;
PRLock *mQueueLock;
PRLock *mCondLock;
PRLock *mPausedLock;
PRCondVar *mQueueCond;
PRCondVar *mPaused;
nsTArray<mozilla::AndroidGeckoEvent *> mEventQueue;
mozilla::AndroidGeckoEvent *GetNextEvent();