Bug 627084 - Add an app shell native event starvation timeout for cases where our native event pump messages get dropped by 3rd party code. r=roc

This commit is contained in:
Jim Mathies 2011-08-09 09:48:10 -05:00
Родитель d6059627f3
Коммит 5df8248e6a
2 изменённых файлов: 18 добавлений и 0 удалений

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

@ -54,6 +54,9 @@
const PRUnichar* kAppShellEventId = L"nsAppShell:EventID";
const PRUnichar* kTaskbarButtonEventId = L"TaskbarButtonCreated";
// The maximum time we allow before forcing a native event callback
#define NATIVE_EVENT_STARVATION_LIMIT mozilla::TimeDuration::FromSeconds(1)
static UINT sMsgId;
#if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
@ -135,6 +138,8 @@ nsAppShell::Init()
LSPAnnotate();
#endif
mLastNativeEventScheduled = TimeStamp::Now();
if (!sMsgId)
sMsgId = RegisterWindowMessageW(kAppShellEventId);
@ -306,6 +311,9 @@ nsAppShell::ScheduleNativeEventCallback()
{
// Post a message to the hidden message window
NS_ADDREF_THIS(); // will be released when the event is processed
// Time stamp this event so we can detect cases where the event gets
// dropping in sub classes / modal loops we do not control.
mLastNativeEventScheduled = TimeStamp::Now();
::PostMessage(mEventWnd, sMsgId, 0, reinterpret_cast<LPARAM>(this));
}
@ -348,5 +356,12 @@ nsAppShell::ProcessNextNativeEvent(PRBool mayWait)
if (mNativeCallbackPending && mEventloopNestingLevel == 1)
DoProcessMoreGeckoEvents();
// Check for starved native callbacks. If we haven't processed one
// of these events in NATIVE_EVENT_STARVATION_LIMIT, fire one off.
if ((TimeStamp::Now() - mLastNativeEventScheduled) >
NATIVE_EVENT_STARVATION_LIMIT) {
ScheduleNativeEventCallback();
}
return gotMessage;
}

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

@ -40,6 +40,7 @@
#include "nsBaseAppShell.h"
#include <windows.h>
#include "mozilla/TimeStamp.h"
/**
* Native Win32 Application shell wrapper
@ -51,6 +52,7 @@ public:
mEventWnd(NULL),
mNativeCallbackPending(PR_FALSE)
{}
typedef mozilla::TimeStamp TimeStamp;
nsresult Init();
void DoProcessMoreGeckoEvents();
@ -72,6 +74,7 @@ protected:
protected:
HWND mEventWnd;
PRBool mNativeCallbackPending;
TimeStamp mLastNativeEventScheduled;
};
#endif // nsAppShell_h__