Bug 1826027 - Check whether window is destroyed during starting touch event. r=geckoview-reviewers,calu

`HandleMotionEvent` have a race condition of destroying `nsWindow` (in Gecko
main thread) and dispatching touch event (Android UI thread). When destroying
the window, it can accept motion event.

So we should check whether window is destroyed.

Differential Revision: https://phabricator.services.mozilla.com/D174390
This commit is contained in:
Makoto Kato 2023-04-04 04:00:09 +00:00
Родитель 20cc0e0a3f
Коммит 785a9d72ef
2 изменённых файлов: 16 добавлений и 2 удалений

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

@ -806,7 +806,14 @@ class NPZCSupport final
if (!win) {
return;
}
nsWindow* gkWindow = win->GetNsWindow();
RefPtr<nsWindow> gkWindow = win->GetNsWindow();
if (!gkWindow) {
return;
}
MutexAutoLock lock(gkWindow->GetDestroyMutex());
if (gkWindow->Destroyed()) {
return;
}
jni::NativeWeakPtr<NPZCSupport> weakPtrToThis =
gkWindow->GetNPZCSupportWeakPtr();
mObserver = Observer::Create(std::move(weakPtrToThis));
@ -1966,7 +1973,8 @@ nsWindow::nsWindow()
mDynamicToolbarMaxHeight(0),
mSizeMode(nsSizeMode_Normal),
mIsFullScreen(false),
mCompositorWidgetDelegate(nullptr) {}
mCompositorWidgetDelegate(nullptr),
mDestroyMutex("nsWindow::mDestroyMutex") {}
nsWindow::~nsWindow() {
gTopLevelWindows.RemoveElement(this);
@ -2035,6 +2043,8 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
}
void nsWindow::Destroy() {
MutexAutoLock lock(mDestroyMutex);
nsBaseWidget::mOnDestroyCalled = true;
// Disassociate our native object from GeckoView.

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

@ -129,6 +129,8 @@ class nsWindow final : public nsBaseWidget {
void DetachNatives();
mozilla::Mutex& GetDestroyMutex() { return mDestroyMutex; }
//
// nsIWidget
//
@ -282,6 +284,8 @@ class nsWindow final : public nsBaseWidget {
mozilla::widget::PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate;
mozilla::Mutex mDestroyMutex;
friend class mozilla::widget::GeckoViewSupport;
friend class mozilla::widget::LayerViewSupport;
friend class mozilla::widget::NPZCSupport;