Bug 1553135 - Lock LayerViewSupport during detach so that other methods cannot be called during this time. r=geckoview-reviewers,snorp

This is caused by a race condition when the compositor is detached. Because the actual detachment happens in a new thread, `detach` can complete and release the lock on `mLayerViewSupport`, and `RecvScreenPixels` can obtain the lock, before `mLayerViewSupport` is properly cleaned up. We therefore check to ensure that `lvs` is not null before calling a method on it.

Differential Revision: https://phabricator.services.mozilla.com/D36928

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emily Toop 2019-07-24 15:26:31 +00:00
parent fc92f585e2
commit 8a99efca37

View File

@ -18,15 +18,15 @@
#include "mozilla/WeakPtr.h"
#include "mozilla/WheelHandlingHelper.h" // for WheelDeltaAdjustmentStrategy
#include "mozilla/a11y/SessionAccessibility.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/Unused.h"
#include "mozilla/Preferences.h"
#include "mozilla/layers/RenderTrace.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/Unused.h"
#include "mozilla/a11y/SessionAccessibility.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/layers/RenderTrace.h"
#include <algorithm>
using mozilla::Unused;
@ -53,27 +53,27 @@ using mozilla::dom::ContentParent;
#include "nsLayoutUtils.h"
#include "nsViewManager.h"
#include "nsContentUtils.h"
#include "WidgetUtils.h"
#include "nsContentUtils.h"
#include "nsGfxCIID.h"
#include "nsGkAtoms.h"
#include "nsWidgetsCID.h"
#include "nsGfxCIID.h"
#include "gfxContext.h"
#include "AndroidContentController.h"
#include "GLContext.h"
#include "GLContextProvider.h"
#include "Layers.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/AsyncCompositionManager.h"
#include "ScopedGLHelpers.h"
#include "mozilla/layers/APZEventState.h"
#include "mozilla/layers/APZInputBridge.h"
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/IAPZCTreeManager.h"
#include "GLContext.h"
#include "GLContextProvider.h"
#include "ScopedGLHelpers.h"
#include "mozilla/layers/AsyncCompositionManager.h"
#include "mozilla/layers/CompositorOGL.h"
#include "AndroidContentController.h"
#include "mozilla/layers/IAPZCTreeManager.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "nsTArray.h"
@ -81,18 +81,18 @@ using mozilla::dom::ContentParent;
#include "AndroidBridgeUtilities.h"
#include "AndroidUiThread.h"
#include "FennecJNINatives.h"
#include "GeneratedJNINatives.h"
#include "GeckoEditableSupport.h"
#include "GeneratedJNINatives.h"
#include "KeyEvent.h"
#include "MotionEvent.h"
#include "ScreenHelperAndroid.h"
#include "imgIEncoder.h"
#include "nsString.h"
#include "GeckoProfiler.h" // For AUTO_PROFILER_LABEL
#include "nsIXULRuntime.h"
#include "nsPrintfCString.h"
#include "nsString.h"
#include "mozilla/ipc/Shmem.h"
@ -862,22 +862,29 @@ class nsWindow::LayerViewSupport final
return;
}
if (LockedWindowPtr window{mWindow}) {
uiThread->Dispatch(NS_NewRunnableFunction(
"LayerViewSupport::OnDetach",
[compositor, disposer = RefPtr<Runnable>(aDisposer),
result = &mCapturePixelsResults] {
while (!result->empty()) {
result->front()->CompleteExceptionally(
results = &mCapturePixelsResults, lock = &window] {
if (lock) {
while (!results->empty()) {
auto aResult = java::GeckoResult::LocalRef(results->front());
if (aResult) {
aResult->CompleteExceptionally(
java::sdk::IllegalStateException::New(
"The compositor has detached from the session")
.Cast<jni::Throwable>());
result->pop();
results->pop();
}
}
compositor->OnCompositorDetached();
disposer->Run();
}
}));
}
}
}
const GeckoSession::Compositor::Ref& GetJavaCompositor() const {
return mCompositor;