diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerSession.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerSession.java index a1c5221a07f4..512cf079c685 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerSession.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerSession.java @@ -31,8 +31,6 @@ public class LayerSession { protected class Compositor extends JNIObject { public LayerView layerView; - private volatile boolean mContentDocumentIsDisplayed; - public boolean isReady() { return LayerSession.this.isCompositorReady(); } @@ -129,23 +127,12 @@ public class LayerSession { public native void sendToolbarPixelsToCompositor(final int width, final int height, final int[] pixels); - @WrapForJNI(calledFrom = "gecko") - private void contentDocumentChanged() { - mContentDocumentIsDisplayed = false; - } - - @WrapForJNI(calledFrom = "gecko") - private boolean isContentDocumentDisplayed() { - return mContentDocumentIsDisplayed; - } - // The compositor invokes this function just before compositing a frame where the // document is different from the document composited on the last frame. In these // cases, the viewport information we have in Java is no longer valid and needs to // be replaced with the new viewport information provided. @WrapForJNI(calledFrom = "ui") public void updateRootFrameMetrics(float scrollX, float scrollY, float zoom) { - mContentDocumentIsDisplayed = true; if (layerView != null) { layerView.onMetricsChanged(scrollX, scrollY, zoom); } diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java index d138b5a66416..b5397c42936c 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java @@ -319,10 +319,6 @@ public class LayerView extends FrameLayout { mCompositor = session.mCompositor; mCompositor.layerView = this; - // Reset the content-document-is-displayed flag. - mCompositor.updateRootFrameMetrics(/* scroolX */ 0, /* scrollY */ 0, - /* zoom */ 1.0f); - mToolbarAnimator.notifyCompositorCreated(mCompositor); final NativePanZoomController npzc = (NativePanZoomController) mPanZoomController; diff --git a/widget/android/AndroidBridge.cpp b/widget/android/AndroidBridge.cpp index 13ff0f621563..719c4b19c32d 100644 --- a/widget/android/AndroidBridge.cpp +++ b/widget/android/AndroidBridge.cpp @@ -873,8 +873,8 @@ __attribute__ ((visibility("default"))) jobject JNICALL Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(JNIEnv *env, jclass, jlong size); -static jni::DependentRef -GetJavaCompositor(mozIDOMWindowProxy* aWindow) +static RefPtr +GetWidget(mozIDOMWindowProxy* aWindow) { MOZ_ASSERT(aWindow); @@ -883,27 +883,26 @@ GetJavaCompositor(mozIDOMWindowProxy* aWindow) widget::WidgetUtils::DOMWindowToWidget(domWindow); MOZ_ASSERT(widget); - return static_cast(widget.get())->GetJavaCompositor(); + return RefPtr(static_cast(widget.get())); } void AndroidBridge::ContentDocumentChanged(mozIDOMWindowProxy* aWindow) { - auto layerClient = GetJavaCompositor(aWindow); - if (!layerClient) { - return; + auto widget = GetWidget(aWindow); + if (widget) { + widget->SetContentDocumentDisplayed(false); } - layerClient->ContentDocumentChanged(); } bool AndroidBridge::IsContentDocumentDisplayed(mozIDOMWindowProxy* aWindow) { - auto layerClient = GetJavaCompositor(aWindow); - if (!layerClient) { - return false; + auto widget = GetWidget(aWindow); + if (widget) { + return widget->IsContentDocumentDisplayed(); } - return layerClient->IsContentDocumentDisplayed(); + return false; } jni::Object::LocalRef AndroidBridge::ChannelCreate(jni::Object::Param stream) { diff --git a/widget/android/GeneratedJNIWrappers.cpp b/widget/android/GeneratedJNIWrappers.cpp index 9adcd8e39c5a..23b5f65d7e70 100644 --- a/widget/android/GeneratedJNIWrappers.cpp +++ b/widget/android/GeneratedJNIWrappers.cpp @@ -1254,14 +1254,6 @@ const char LayerSession::Compositor::name[] = constexpr char LayerSession::Compositor::AttachToJava_t::name[]; constexpr char LayerSession::Compositor::AttachToJava_t::signature[]; -constexpr char LayerSession::Compositor::ContentDocumentChanged_t::name[]; -constexpr char LayerSession::Compositor::ContentDocumentChanged_t::signature[]; - -auto LayerSession::Compositor::ContentDocumentChanged() const -> void -{ - return mozilla::jni::Method::Call(Compositor::mCtx, nullptr); -} - constexpr char LayerSession::Compositor::CreateCompositor_t::name[]; constexpr char LayerSession::Compositor::CreateCompositor_t::signature[]; @@ -1271,14 +1263,6 @@ constexpr char LayerSession::Compositor::DisposeNative_t::signature[]; constexpr char LayerSession::Compositor::EnableLayerUpdateNotifications_t::name[]; constexpr char LayerSession::Compositor::EnableLayerUpdateNotifications_t::signature[]; -constexpr char LayerSession::Compositor::IsContentDocumentDisplayed_t::name[]; -constexpr char LayerSession::Compositor::IsContentDocumentDisplayed_t::signature[]; - -auto LayerSession::Compositor::IsContentDocumentDisplayed() const -> bool -{ - return mozilla::jni::Method::Call(Compositor::mCtx, nullptr); -} - constexpr char LayerSession::Compositor::OnBoundsChanged_t::name[]; constexpr char LayerSession::Compositor::OnBoundsChanged_t::signature[]; diff --git a/widget/android/GeneratedJNIWrappers.h b/widget/android/GeneratedJNIWrappers.h index 9279a6ce4d91..8927e948f398 100644 --- a/widget/android/GeneratedJNIWrappers.h +++ b/widget/android/GeneratedJNIWrappers.h @@ -3812,25 +3812,6 @@ public: mozilla::jni::DispatchTarget::GECKO; }; - struct ContentDocumentChanged_t { - typedef Compositor Owner; - typedef void ReturnType; - typedef void SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "contentDocumentChanged"; - static constexpr char signature[] = - "()V"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::GECKO; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto ContentDocumentChanged() const -> void; - struct CreateCompositor_t { typedef Compositor Owner; typedef void ReturnType; @@ -3886,25 +3867,6 @@ public: mozilla::jni::DispatchTarget::CURRENT; }; - struct IsContentDocumentDisplayed_t { - typedef Compositor Owner; - typedef bool ReturnType; - typedef bool SetterType; - typedef mozilla::jni::Args<> Args; - static constexpr char name[] = "isContentDocumentDisplayed"; - static constexpr char signature[] = - "()Z"; - static const bool isStatic = false; - static const mozilla::jni::ExceptionMode exceptionMode = - mozilla::jni::ExceptionMode::ABORT; - static const mozilla::jni::CallingThread callingThread = - mozilla::jni::CallingThread::GECKO; - static const mozilla::jni::DispatchTarget dispatchTarget = - mozilla::jni::DispatchTarget::CURRENT; - }; - - auto IsContentDocumentDisplayed() const -> bool; - struct OnBoundsChanged_t { typedef Compositor Owner; typedef void ReturnType; diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index 44809555e1df..1af6bf0b9070 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -2323,14 +2323,18 @@ nsWindow::GetWidgetScreen() return screenMgrAndroid->ScreenForId(mScreenId); } -jni::DependentRef -nsWindow::GetJavaCompositor() +void +nsWindow::SetContentDocumentDisplayed(bool aDisplayed) { - if (NativePtr::Locked lvs{mLayerViewSupport}) { - return lvs->GetJavaCompositor().Get(); - } - return nullptr; + mContentDocumentDisplayed = aDisplayed; } + +bool +nsWindow::IsContentDocumentDisplayed() +{ + return mContentDocumentDisplayed; +} + void nsWindow::RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage) { @@ -2346,6 +2350,7 @@ nsWindow::UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset, const CSSToSc MOZ_ASSERT(AndroidBridge::IsJavaUiThread()); if (NativePtr::Locked lvs{mLayerViewSupport}) { const auto& compositor = lvs->GetJavaCompositor(); + mContentDocumentDisplayed = true; compositor->UpdateRootFrameMetrics(aScrollOffset.x, aScrollOffset.y, aZoom.scale); } } diff --git a/widget/android/nsWindow.h b/widget/android/nsWindow.h index 41a7524beedb..4d9b192aaa32 100644 --- a/widget/android/nsWindow.h +++ b/widget/android/nsWindow.h @@ -196,6 +196,8 @@ private: // Class that implements native PresentationMediaPlayerManager calls. class PMPMSupport; + mozilla::Atomic mContentDocumentDisplayed; + public: static nsWindow* TopWindow(); @@ -300,7 +302,8 @@ public: mozilla::layers::CompositorBridgeChild* GetCompositorBridgeChild() const; - mozilla::jni::DependentRef GetJavaCompositor(); + void SetContentDocumentDisplayed(bool aDisplayed); + bool IsContentDocumentDisplayed(); // Call this function when the users activity is the direct cause of an // event (like a keypress or mouse click).