Commit 6d5aac01 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Remove OverlayPresenter from OverlayPresentationContext interface

The OverlayPresenter passed as an argument for the
OverlayPresentationContext API was not used by the implementation.  This
CL decouples the presentation context interface from OverlayPresenter.

Bug: none
Change-Id: Iefa20303f6b38d22240fb9f29f0c3ec6675cb55a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2069257
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745167}
parent d02f6478
...@@ -160,7 +160,7 @@ void OverlayPresenterImpl::SetActiveWebState( ...@@ -160,7 +160,7 @@ void OverlayPresenterImpl::SetActiveWebState(
} else { } else {
// For WebState activations, the overlay UI for the previously active // For WebState activations, the overlay UI for the previously active
// WebState should be hidden, as it may be shown again upon reactivating. // WebState should be hidden, as it may be shown again upon reactivating.
presentation_context_->HideOverlayUI(this, previously_active_request); presentation_context_->HideOverlayUI(previously_active_request);
} }
} }
...@@ -193,8 +193,9 @@ void OverlayPresenterImpl::PresentOverlayForActiveRequest() { ...@@ -193,8 +193,9 @@ void OverlayPresenterImpl::PresentOverlayForActiveRequest() {
// Overlays cannot be presented if one is already presented. // Overlays cannot be presented if one is already presented.
DCHECK(!presenting_); DCHECK(!presenting_);
// Overlays cannot be shown without a presentation context. // Overlays cannot be shown without a presentation context or if the
if (!presentation_context_) // presentation context is already showing overlay UI.
if (!presentation_context_ || presentation_context_->IsShowingOverlayUI())
return; return;
// No presentation is necessary if there is no active reqeust or the context // No presentation is necessary if there is no active reqeust or the context
...@@ -219,9 +220,8 @@ void OverlayPresenterImpl::PresentOverlayForActiveRequest() { ...@@ -219,9 +220,8 @@ void OverlayPresenterImpl::PresentOverlayForActiveRequest() {
OverlayDismissalCallback dismissal_callback = base::BindOnce( OverlayDismissalCallback dismissal_callback = base::BindOnce(
&OverlayPresenterImpl::OverlayWasDismissed, weak_factory_.GetWeakPtr(), &OverlayPresenterImpl::OverlayWasDismissed, weak_factory_.GetWeakPtr(),
presentation_context_, request, GetActiveQueue()->GetWeakPtr()); presentation_context_, request, GetActiveQueue()->GetWeakPtr());
presentation_context_->ShowOverlayUI(this, request, presentation_context_->ShowOverlayUI(
std::move(presentation_callback), request, std::move(presentation_callback), std::move(dismissal_callback));
std::move(dismissal_callback));
} }
void OverlayPresenterImpl::OverlayWasPresented( void OverlayPresenterImpl::OverlayWasPresented(
...@@ -286,7 +286,7 @@ void OverlayPresenterImpl::OverlayWasDismissed( ...@@ -286,7 +286,7 @@ void OverlayPresenterImpl::OverlayWasDismissed(
void OverlayPresenterImpl::CancelOverlayUIForRequest(OverlayRequest* request) { void OverlayPresenterImpl::CancelOverlayUIForRequest(OverlayRequest* request) {
if (!presentation_context_ || !request) if (!presentation_context_ || !request)
return; return;
presentation_context_->CancelOverlayUI(this, request); presentation_context_->CancelOverlayUI(request);
} }
void OverlayPresenterImpl::CancelAllOverlayUI() { void OverlayPresenterImpl::CancelAllOverlayUI() {
...@@ -372,7 +372,7 @@ void OverlayPresenterImpl::RequestAddedToQueue(OverlayRequestQueueImpl* queue, ...@@ -372,7 +372,7 @@ void OverlayPresenterImpl::RequestAddedToQueue(OverlayRequestQueueImpl* queue,
presented_request_ && queue->size() > 1 && presented_request_ && queue->size() > 1 &&
queue->GetRequest(/*index=*/1) == presented_request_; queue->GetRequest(/*index=*/1) == presented_request_;
if (should_dismiss_for_inserted_request) if (should_dismiss_for_inserted_request)
presentation_context_->HideOverlayUI(this, presented_request_); presentation_context_->HideOverlayUI(presented_request_);
} }
void OverlayPresenterImpl::OverlayRequestQueueDestroyed( void OverlayPresenterImpl::OverlayRequestQueueDestroyed(
...@@ -392,7 +392,7 @@ void OverlayPresenterImpl:: ...@@ -392,7 +392,7 @@ void OverlayPresenterImpl::
OverlayRequest* request = GetActiveRequest(); OverlayRequest* request = GetActiveRequest();
if (presenting_ && if (presenting_ &&
!presentation_context->CanShowUIForRequest(request, capabilities)) { !presentation_context->CanShowUIForRequest(request, capabilities)) {
presentation_context_->HideOverlayUI(this, GetActiveRequest()); presentation_context_->HideOverlayUI(GetActiveRequest());
} }
} }
......
...@@ -8,11 +8,10 @@ ...@@ -8,11 +8,10 @@
#include "ios/chrome/browser/overlays/public/overlay_dismissal_callback.h" #include "ios/chrome/browser/overlays/public/overlay_dismissal_callback.h"
#include "ios/chrome/browser/overlays/public/overlay_presentation_callback.h" #include "ios/chrome/browser/overlays/public/overlay_presentation_callback.h"
class OverlayPresenter;
class OverlayRequest; class OverlayRequest;
class OverlayPresentationContextObserver; class OverlayPresentationContextObserver;
// Object that handles presenting the overlay UI for OverlayPresenter. // Object that handles presenting the overlay UI for OverlayRequests.
class OverlayPresentationContext { class OverlayPresentationContext {
public: public:
OverlayPresentationContext() = default; OverlayPresentationContext() = default;
...@@ -49,31 +48,32 @@ class OverlayPresentationContext { ...@@ -49,31 +48,32 @@ class OverlayPresentationContext {
// |request| with its current presentation capabilities. // |request| with its current presentation capabilities.
virtual bool CanShowUIForRequest(OverlayRequest* request) const = 0; virtual bool CanShowUIForRequest(OverlayRequest* request) const = 0;
// Called by |presenter| to show the overlay UI for |request|. // Whether overlay UI is currently shown in the context.
// |presentation_callback| must be called when the UI is finished being virtual bool IsShowingOverlayUI() const = 0;
// presented. |dismissal_callback| must be stored and called whenever the UI
// is finished being dismissed for user interaction, hiding, or cancellation. // Called to show the overlay UI for |request|. |presentation_callback| must
// Must only be called when CanShowUIForRequest() returns true for |request|. // be called when the UI is finished being presented. |dismissal_callback|
virtual void ShowOverlayUI(OverlayPresenter* presenter, // must be stored and called whenever the UI is finished being dismissed for
OverlayRequest* request, // user interaction, hiding, or cancellation. Must only be called when:
// - IsShowingOverlayUI() returns false, and
// - CanShowUIForRequest() returns true for |request|.
virtual void ShowOverlayUI(OverlayRequest* request,
OverlayPresentationCallback presentation_callback, OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) = 0; OverlayDismissalCallback dismissal_callback) = 0;
// Called by |presenter| to hide the overlay UI for |request|. Hidden // Called to hide the overlay UI for |request|. Hidden overlays may be shown
// overlays may be shown again, so they should be kept in memory or // again, so they should be kept in memory or serialized so that the state can
// serialized so that the state can be restored if shown again. When hiding // be restored if shown again. When hiding an overlay, the presented UI must
// an overlay, the presented UI must be dismissed, and the overlay's // be dismissed, and the overlay's dismissal callback must must be executed
// dismissal callback must must be executed upon the dismissal's completion. // upon the dismissal's completion. Must only be called when |request| is
// Must only be called when |request| is displayed within the context. // displayed within the context.
virtual void HideOverlayUI(OverlayPresenter* presenter, virtual void HideOverlayUI(OverlayRequest* request) = 0;
OverlayRequest* request) = 0;
// Called by |presenter| to cancel the overlay UI for |request|. If the UI // Called to cancel the overlay UI for |request|. If the UI is presented, it
// is presented, it should be dismissed and the dismissal callback should be // should be dismissed and the dismissal callback should be executed upon the
// executed upon the dismissal's completion. Otherwise, any state // dismissal's completion. Otherwise, any state corresponding to any hidden
// corresponding to any hidden overlays should be cleaned up. // overlays should be cleaned up.
virtual void CancelOverlayUI(OverlayPresenter* presenter, virtual void CancelOverlayUI(OverlayRequest* request) = 0;
OverlayRequest* request) = 0;
}; };
#endif // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_OVERLAY_PRESENTATION_CONTEXT_H_ #endif // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_OVERLAY_PRESENTATION_CONTEXT_H_
...@@ -75,11 +75,20 @@ bool FakeOverlayPresentationContext::CanShowUIForRequest( ...@@ -75,11 +75,20 @@ bool FakeOverlayPresentationContext::CanShowUIForRequest(
bool FakeOverlayPresentationContext::CanShowUIForRequest( bool FakeOverlayPresentationContext::CanShowUIForRequest(
OverlayRequest* request) const { OverlayRequest* request) const {
return CanShowUIForRequest(request, capabilities_); return CanShowUIForRequest(request, capabilities_) && !IsShowingOverlayUI();
}
bool FakeOverlayPresentationContext::IsShowingOverlayUI() const {
for (auto& request_ui_state_pair : states_) {
if (request_ui_state_pair.second.presentation_state ==
PresentationState::kPresented) {
return true;
}
}
return false;
} }
void FakeOverlayPresentationContext::ShowOverlayUI( void FakeOverlayPresentationContext::ShowOverlayUI(
OverlayPresenter* presenter,
OverlayRequest* request, OverlayRequest* request,
OverlayPresentationCallback presentation_callback, OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) { OverlayDismissalCallback dismissal_callback) {
...@@ -89,13 +98,11 @@ void FakeOverlayPresentationContext::ShowOverlayUI( ...@@ -89,13 +98,11 @@ void FakeOverlayPresentationContext::ShowOverlayUI(
std::move(presentation_callback).Run(); std::move(presentation_callback).Run();
} }
void FakeOverlayPresentationContext::HideOverlayUI(OverlayPresenter* presenter, void FakeOverlayPresentationContext::HideOverlayUI(OverlayRequest* request) {
OverlayRequest* request) {
SimulateDismissalForRequest(request, OverlayDismissalReason::kHiding); SimulateDismissalForRequest(request, OverlayDismissalReason::kHiding);
} }
void FakeOverlayPresentationContext::CancelOverlayUI( void FakeOverlayPresentationContext::CancelOverlayUI(
OverlayPresenter* presenter,
OverlayRequest* request) { OverlayRequest* request) {
FakeUIState& state = states_[request]; FakeUIState& state = states_[request];
if (state.presentation_state == PresentationState::kPresented) { if (state.presentation_state == PresentationState::kPresented) {
......
...@@ -47,14 +47,12 @@ class FakeOverlayPresentationContext : public OverlayPresentationContext { ...@@ -47,14 +47,12 @@ class FakeOverlayPresentationContext : public OverlayPresentationContext {
OverlayRequest* request, OverlayRequest* request,
UIPresentationCapabilities capabilities) const override; UIPresentationCapabilities capabilities) const override;
bool CanShowUIForRequest(OverlayRequest* request) const override; bool CanShowUIForRequest(OverlayRequest* request) const override;
void ShowOverlayUI(OverlayPresenter* presenter, bool IsShowingOverlayUI() const override;
OverlayRequest* request, void ShowOverlayUI(OverlayRequest* request,
OverlayPresentationCallback presentation_callback, OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) override; OverlayDismissalCallback dismissal_callback) override;
void HideOverlayUI(OverlayPresenter* presenter, void HideOverlayUI(OverlayRequest* request) override;
OverlayRequest* request) override; void CancelOverlayUI(OverlayRequest* request) override;
void CancelOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) override;
private: private:
// Struct used to store state for the fake presentation context. // Struct used to store state for the fake presentation context.
......
...@@ -68,14 +68,12 @@ class OverlayPresentationContextImpl : public OverlayPresentationContext { ...@@ -68,14 +68,12 @@ class OverlayPresentationContextImpl : public OverlayPresentationContext {
OverlayRequest* request, OverlayRequest* request,
UIPresentationCapabilities capabilities) const override; UIPresentationCapabilities capabilities) const override;
bool CanShowUIForRequest(OverlayRequest* request) const override; bool CanShowUIForRequest(OverlayRequest* request) const override;
void ShowOverlayUI(OverlayPresenter* presenter, bool IsShowingOverlayUI() const override;
OverlayRequest* request, void ShowOverlayUI(OverlayRequest* request,
OverlayPresentationCallback presentation_callback, OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) override; OverlayDismissalCallback dismissal_callback) override;
void HideOverlayUI(OverlayPresenter* presenter, void HideOverlayUI(OverlayRequest* request) override;
OverlayRequest* request) override; void CancelOverlayUI(OverlayRequest* request) override;
void CancelOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) override;
private: private:
OverlayPresentationContextImpl(Browser* browser, OverlayModality modality); OverlayPresentationContextImpl(Browser* browser, OverlayModality modality);
......
...@@ -110,12 +110,16 @@ bool OverlayPresentationContextImpl::CanShowUIForRequest( ...@@ -110,12 +110,16 @@ bool OverlayPresentationContextImpl::CanShowUIForRequest(
return CanShowUIForRequest(request, GetPresentationCapabilities()); return CanShowUIForRequest(request, GetPresentationCapabilities());
} }
bool OverlayPresentationContextImpl::IsShowingOverlayUI() const {
return !!request_;
}
void OverlayPresentationContextImpl::ShowOverlayUI( void OverlayPresentationContextImpl::ShowOverlayUI(
OverlayPresenter* presenter,
OverlayRequest* request, OverlayRequest* request,
OverlayPresentationCallback presentation_callback, OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) { OverlayDismissalCallback dismissal_callback) {
DCHECK_EQ(presenter_, presenter); DCHECK(!IsShowingOverlayUI());
DCHECK(CanShowUIForRequest(request));
// Create the UI state for |request| if necessary. // Create the UI state for |request| if necessary.
if (!GetRequestUIState(request)) if (!GetRequestUIState(request))
states_[request] = std::make_unique<OverlayRequestUIState>(request); states_[request] = std::make_unique<OverlayRequestUIState>(request);
...@@ -125,9 +129,8 @@ void OverlayPresentationContextImpl::ShowOverlayUI( ...@@ -125,9 +129,8 @@ void OverlayPresentationContextImpl::ShowOverlayUI(
SetRequest(request); SetRequest(request);
} }
void OverlayPresentationContextImpl::HideOverlayUI(OverlayPresenter* presenter, void OverlayPresentationContextImpl::HideOverlayUI(OverlayRequest* request) {
OverlayRequest* request) { DCHECK(CanShowUIForRequest(request));
DCHECK_EQ(presenter_, presenter);
DCHECK_EQ(request_, request); DCHECK_EQ(request_, request);
DCHECK(CanShowUIForRequest(request)); DCHECK(CanShowUIForRequest(request));
...@@ -140,10 +143,8 @@ void OverlayPresentationContextImpl::HideOverlayUI(OverlayPresenter* presenter, ...@@ -140,10 +143,8 @@ void OverlayPresentationContextImpl::HideOverlayUI(OverlayPresenter* presenter,
} }
void OverlayPresentationContextImpl::CancelOverlayUI( void OverlayPresentationContextImpl::CancelOverlayUI(
OverlayPresenter* presenter,
OverlayRequest* request) { OverlayRequest* request) {
DCHECK_EQ(presenter_, presenter); DCHECK(CanShowUIForRequest(request));
// No cleanup required if there is no UI state for |request|. This can // No cleanup required if there is no UI state for |request|. This can
// occur when cancelling an OverlayRequest whose UI has never been // occur when cancelling an OverlayRequest whose UI has never been
// presented. // presented.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment