From 751a846ce0a32af4b45be81295e3c92e64f68d8a Mon Sep 17 00:00:00 2001 From: "Randall E. Barker" Date: Tue, 29 Oct 2019 00:50:38 -0700 Subject: [PATCH] Set prompt delegate when new stacked tab is created (#2087) --- .../vrbrowser/browser/PromptDelegate.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/PromptDelegate.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/PromptDelegate.java index fad378061..132b5a855 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/PromptDelegate.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/PromptDelegate.java @@ -13,6 +13,7 @@ import org.mozilla.vrbrowser.AppExecutors; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.VRBrowserApplication; +import org.mozilla.vrbrowser.browser.engine.Session; import org.mozilla.vrbrowser.db.PopUpSite; import org.mozilla.vrbrowser.ui.viewmodel.PopUpsViewModel; import org.mozilla.vrbrowser.ui.widgets.UIWidget; @@ -33,7 +34,7 @@ import java.util.NoSuchElementException; import java.util.Optional; -public class PromptDelegate implements GeckoSession.PromptDelegate { +public class PromptDelegate implements GeckoSession.PromptDelegate, WindowWidget.WindowListener { private PromptWidget mPrompt; private PopUpBlockDialogWidget mPopUpPrompt; @@ -57,12 +58,16 @@ public void attachToWindow(@NonNull WindowWidget window) { detachFromWindow(); mAttachedWindow = window; + mAttachedWindow.addWindowListener(this); mAttachedWindow.getSession().setPromptDelegate(this); mViewModel.getAll().observeForever(mObserver); } public void detachFromWindow() { - mAttachedWindow = null; + if (mAttachedWindow != null) { + mAttachedWindow.removeWindowListener(this); + mAttachedWindow = null; + } mViewModel.getAll().removeObserver(mObserver); } @@ -307,4 +312,11 @@ public void onDismiss() { } } + // WindowWidget.WindowListener + + @Override + public void onSessionChanged(@NonNull Session aOldSession, @NonNull Session aSession) { + aOldSession.setPromptDelegate(null); + aSession.setPromptDelegate(this); + } }