Commit e7f0733c authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Add High Priority timeout to Overlay Infobars

Crash Restore Infobar banners display longer than other Infobars.
This change adds functionality for this distinction and implements
the longer presentation for the crash restore Infobar.

Bug: 1071914
Change-Id: Ib71d7961681a06c8728230ce728457421b145f09
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2342142Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796610}
parent b37aa8ef
......@@ -63,6 +63,11 @@ class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate {
// should be skipped but not the badge and subsequent modals.
bool skip_banner() const { return skip_banner_; }
// Whether or not the banner should be shown for a longer time and be
// presented immediately.
bool high_priority() const { return high_priority_; }
void set_high_priority(bool high_priority);
// Returns the InfobarUIDelegate associated to this Infobar.
id<InfobarUIDelegate> InfobarUIDelegate();
......@@ -86,6 +91,7 @@ class InfoBarIOS : public infobars::InfoBar, public InfoBarControllerDelegate {
InfobarType infobar_type_;
bool accepted_ = false;
bool skip_banner_ = false;
bool high_priority_ = false;
base::WeakPtrFactory<InfoBarIOS> weak_factory_{this};
};
......
......@@ -52,6 +52,12 @@ void InfoBarIOS::set_accepted(bool accepted) {
}
}
void InfoBarIOS::set_high_priority(bool high_priority) {
if (high_priority_ == high_priority)
return;
high_priority_ = high_priority;
}
id<InfobarUIDelegate> InfoBarIOS::InfobarUIDelegate() {
DCHECK(ui_delegate_);
return ui_delegate_;
......
......@@ -47,5 +47,8 @@ std::unique_ptr<infobars::InfoBar> CreateHighPriorityConfirmInfoBar(
badgeSupport:NO
type:InfobarType::kInfobarTypeConfirm];
coordinator.highPriorityPresentation = YES;
return std::make_unique<InfoBarIOS>(coordinator, std::move(delegate));
std::unique_ptr<InfoBarIOS> infobar =
std::make_unique<InfoBarIOS>(coordinator, std::move(delegate));
infobar->set_high_priority(true);
return infobar;
}
......@@ -129,7 +129,7 @@ class InfobarOverlayBrowserAgentTest
// that has the same InfobarOverlayType as the test fixture.
std::unique_ptr<OverlayRequest> CreateRequest() {
return OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar_, GetParam());
&infobar_, GetParam(), false);
}
OverlayModality modality() {
......
......@@ -31,7 +31,7 @@ class InfobarBannerOverlayRequestCallbackInstallerTest : public PlatformTest {
&mock_handler_) {
std::unique_ptr<OverlayRequest> request =
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar_, InfobarOverlayType::kBanner);
&infobar_, InfobarOverlayType::kBanner, infobar_.high_priority());
request_ = request.get();
queue()->AddRequest(std::move(request));
installer_.InstallCallbacks(request_);
......
......@@ -39,7 +39,8 @@ class InfobarModalOverlayRequestCallbackInstallerTest : public PlatformTest {
InfobarModalOverlayRequestCallbackInstallerTest()
: request_(OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar_,
InfobarOverlayType::kModal)),
InfobarOverlayType::kModal,
infobar_.high_priority())),
installer_(&mock_handler_) {
installer_.InstallCallbacks(request_.get());
}
......
......@@ -21,5 +21,6 @@ FakeInfobarOverlayRequestFactory::CreateInfobarRequest(
infobars::InfoBar* infobar,
InfobarOverlayType type) {
return OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
static_cast<InfoBarIOS*>(infobar), type);
static_cast<InfoBarIOS*>(infobar), type,
static_cast<InfoBarIOS*>(infobar)->high_priority());
}
......@@ -60,7 +60,7 @@ TEST_F(InfobarModalCompletionNotifierTest, ModalCompletion) {
// Add a detail sheet request for |infobar_|.
std::unique_ptr<OverlayRequest> detail_sheet_request =
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar_, InfobarOverlayType::kDetailSheet);
&infobar_, InfobarOverlayType::kDetailSheet, false);
std::unique_ptr<FakeOverlayRequestCancelHandler>
passed_detail_sheet_cancel_handler =
std::make_unique<FakeOverlayRequestCancelHandler>(
......@@ -72,7 +72,7 @@ TEST_F(InfobarModalCompletionNotifierTest, ModalCompletion) {
// Add a modal request for |infobar_|.
std::unique_ptr<OverlayRequest> modal_request =
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar_, InfobarOverlayType::kModal);
&infobar_, InfobarOverlayType::kModal, false);
std::unique_ptr<FakeOverlayRequestCancelHandler> passed_modal_cancel_handler =
std::make_unique<FakeOverlayRequestCancelHandler>(modal_request.get(),
queue());
......
......@@ -46,15 +46,21 @@ InfobarOverlayTabHelper::OverlayRequestScheduler::~OverlayRequestScheduler() =
void InfobarOverlayTabHelper::OverlayRequestScheduler::OnInfoBarAdded(
InfoBar* infobar) {
InfoBarIOS* ios_infobar = static_cast<InfoBarIOS*>(infobar);
// Skip showing banner if it was requested. Badge and modals will keep
// showing.
if (static_cast<InfoBarIOS*>(infobar)->skip_banner())
if (ios_infobar->skip_banner())
return;
InsertParams params(static_cast<InfoBarIOS*>(infobar));
InsertParams params(ios_infobar);
params.overlay_type = InfobarOverlayType::kBanner;
params.insertion_index = OverlayRequestQueue::FromWebState(
web_state_, OverlayModality::kInfobarBanner)
->size();
// If the Infobar high priority, then insert it into the front of the banner
// queue.
params.insertion_index =
ios_infobar->high_priority()
? 0
: OverlayRequestQueue::FromWebState(web_state_,
OverlayModality::kInfobarBanner)
->size();
params.source = InfobarOverlayInsertionSource::kInfoBarManager;
tab_helper_->request_inserter()->InsertOverlayRequest(params);
}
......
......@@ -13,6 +13,7 @@
#import "ios/chrome/browser/infobars/overlays/infobar_overlay_request_inserter.h"
#include "ios/chrome/browser/infobars/test/fake_infobar_delegate.h"
#import "ios/chrome/browser/infobars/test/fake_infobar_ios.h"
#import "ios/chrome/browser/overlays/public/common/infobars/infobar_overlay_request_config.h"
#include "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/overlays/public/overlay_request_queue.h"
#include "ios/chrome/browser/overlays/test/fake_overlay_user_data.h"
......@@ -61,3 +62,20 @@ TEST_F(InfobarOverlayTabHelperTest, AddInfoBar) {
manager()->AddInfoBar(std::make_unique<FakeInfobarIOS>());
ASSERT_TRUE(front_request());
}
TEST_F(InfobarOverlayTabHelperTest, HighPriorityInfoBar) {
ASSERT_FALSE(front_request());
manager()->AddInfoBar(std::make_unique<FakeInfobarIOS>());
ASSERT_TRUE(front_request());
std::unique_ptr<FakeInfobarIOS> high_priority_infobar =
std::make_unique<FakeInfobarIOS>(
InfobarType::kInfobarTypeTranslate,
base::ASCIIToUTF16("FakeTranslateInfobar"));
high_priority_infobar->set_high_priority(true);
manager()->AddInfoBar(std::move(high_priority_infobar));
OverlayRequest* request = front_request();
InfobarOverlayRequestConfig* config =
request->GetConfig<InfobarOverlayRequestConfig>();
ASSERT_TRUE(config->is_high_priority());
}
......@@ -29,7 +29,7 @@ TEST_F(InfobarOverlayUtilTest, GetOverlayRequestInfobar) {
auto infobar_request =
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar, InfobarOverlayType::kBanner);
&infobar, InfobarOverlayType::kBanner, infobar.high_priority());
EXPECT_EQ(&infobar, GetOverlayRequestInfobar(infobar_request.get()));
auto non_infobar_request =
......@@ -42,14 +42,16 @@ TEST_F(InfobarOverlayUtilTest, GetOverlayRequestInfobarType) {
FakeInfobarIOS confirm_infobar;
auto confirm_infobar_request =
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&confirm_infobar, InfobarOverlayType::kBanner);
&confirm_infobar, InfobarOverlayType::kBanner,
confirm_infobar.high_priority());
EXPECT_EQ(InfobarType::kInfobarTypeConfirm,
GetOverlayRequestInfobarType(confirm_infobar_request.get()));
FakeInfobarIOS translate_infobar(InfobarType::kInfobarTypeTranslate);
auto translate_infobar_request =
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&translate_infobar, InfobarOverlayType::kBanner);
&translate_infobar, InfobarOverlayType::kBanner,
translate_infobar.high_priority());
EXPECT_EQ(InfobarType::kInfobarTypeTranslate,
GetOverlayRequestInfobarType(translate_infobar_request.get()));
}
......@@ -60,13 +62,13 @@ TEST_F(InfobarOverlayUtilTest, GetOverlayRequestInfobarOverlayType) {
FakeInfobarIOS infobar;
auto banner_request =
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar, InfobarOverlayType::kBanner);
&infobar, InfobarOverlayType::kBanner, infobar.high_priority());
EXPECT_EQ(InfobarOverlayType::kBanner,
GetOverlayRequestInfobarOverlayType(banner_request.get()));
auto modal_request =
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar, InfobarOverlayType::kModal);
&infobar, InfobarOverlayType::kModal, infobar.high_priority());
EXPECT_EQ(InfobarOverlayType::kModal,
GetOverlayRequestInfobarOverlayType(modal_request.get()));
}
......@@ -83,13 +85,13 @@ TEST_F(InfobarOverlayUtilTest, GetInfobarOverlayRequestIndex) {
OverlayRequestQueue::FromWebState(&web_state, OverlayModality::kTesting);
queue->AddRequest(
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar0, InfobarOverlayType::kBanner));
&infobar0, InfobarOverlayType::kBanner, infobar0.high_priority()));
queue->AddRequest(
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar1, InfobarOverlayType::kBanner));
&infobar1, InfobarOverlayType::kBanner, infobar1.high_priority()));
queue->AddRequest(
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
&infobar2, InfobarOverlayType::kBanner));
&infobar2, InfobarOverlayType::kBanner, infobar2.high_priority()));
size_t index = 0;
EXPECT_TRUE(GetInfobarOverlayRequestIndex(queue, &infobar0, &index));
......
......@@ -25,17 +25,21 @@ class InfobarOverlayRequestConfig
InfobarType infobar_type() const { return infobar_type_; }
// Whether |infobar_| has a badge.
bool has_badge() const { return has_badge_; }
// Whether the |infobar_| banner should be presented for a longer time.
bool is_high_priority() const { return is_high_priority_; }
// The overlay type for this infobar OverlayRequest.
InfobarOverlayType overlay_type() const { return overlay_type_; }
private:
OVERLAY_USER_DATA_SETUP(InfobarOverlayRequestConfig);
explicit InfobarOverlayRequestConfig(InfoBarIOS* infobar,
InfobarOverlayType overlay_type);
InfobarOverlayType overlay_type,
bool is_high_priority);
base::WeakPtr<InfoBarIOS> infobar_ = nullptr;
InfobarType infobar_type_;
bool has_badge_ = false;
bool is_high_priority_ = false;
InfobarOverlayType overlay_type_;
};
......
......@@ -17,11 +17,13 @@ OVERLAY_USER_DATA_SETUP_IMPL(InfobarOverlayRequestConfig);
InfobarOverlayRequestConfig::InfobarOverlayRequestConfig(
InfoBarIOS* infobar,
InfobarOverlayType overlay_type)
InfobarOverlayType overlay_type,
bool is_high_priority)
: infobar_(infobar->GetWeakPtr()),
infobar_type_(infobar->infobar_type()),
has_badge_(BadgeTypeForInfobarType(infobar_type_) !=
BadgeType::kBadgeTypeNone),
is_high_priority_(is_high_priority),
overlay_type_(overlay_type) {}
InfobarOverlayRequestConfig::~InfobarOverlayRequestConfig() = default;
......@@ -32,6 +32,9 @@ class ConfirmBannerRequestConfig
// The infobar's icon image.
gfx::Image icon_image() const { return icon_image_; }
// Whether to present the Infobar's banner for a longer amount of time.
bool is_high_priority() const { return is_high_priority_; }
private:
OVERLAY_USER_DATA_SETUP(ConfirmBannerRequestConfig);
explicit ConfirmBannerRequestConfig(infobars::InfoBar* infobar);
......@@ -45,6 +48,8 @@ class ConfirmBannerRequestConfig
base::string16 message_text_;
base::string16 button_label_text_;
gfx::Image icon_image_;
// True if the infobar's banner should be presented for a longer time.
bool is_high_priority_ = false;
};
} // namespace confirm_infobar_overlays
......
......@@ -28,6 +28,7 @@ ConfirmBannerRequestConfig::ConfirmBannerRequestConfig(
button_label_text_ =
delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK);
icon_image_ = delegate->GetIcon();
is_high_priority_ = static_cast<InfoBarIOS*>(infobar)->high_priority();
}
ConfirmBannerRequestConfig::~ConfirmBannerRequestConfig() = default;
......@@ -36,7 +37,7 @@ void ConfirmBannerRequestConfig::CreateAuxiliaryData(
base::SupportsUserData* user_data) {
InfobarOverlayRequestConfig::CreateForUserData(
user_data, static_cast<InfoBarIOS*>(infobar_),
InfobarOverlayType::kBanner);
InfobarOverlayType::kBanner, is_high_priority_);
}
} // namespace confirm_infobar_overlays
......@@ -27,5 +27,5 @@ void InfobarBannerPlaceholderRequestConfig::CreateAuxiliaryData(
PlaceholderRequestConfig::CreateForUserData(user_data);
InfobarOverlayRequestConfig::CreateForUserData(
user_data, static_cast<InfoBarIOS*>(infobar_),
InfobarOverlayType::kBanner);
InfobarOverlayType::kBanner, false);
}
......@@ -51,7 +51,7 @@ void SaveCardBannerRequestConfig::CreateAuxiliaryData(
base::SupportsUserData* user_data) {
InfobarOverlayRequestConfig::CreateForUserData(
user_data, static_cast<InfoBarIOS*>(infobar_),
InfobarOverlayType::kBanner);
InfobarOverlayType::kBanner, false);
}
} // namespace save_card_infobar_overlays
......@@ -46,5 +46,5 @@ void SavePasswordInfobarBannerOverlayRequestConfig::CreateAuxiliaryData(
base::SupportsUserData* user_data) {
InfobarOverlayRequestConfig::CreateForUserData(
user_data, static_cast<InfoBarIOS*>(infobar_),
InfobarOverlayType::kBanner);
InfobarOverlayType::kBanner, false);
}
......@@ -42,7 +42,7 @@ void TranslateBannerRequestConfig::CreateAuxiliaryData(
base::SupportsUserData* user_data) {
InfobarOverlayRequestConfig::CreateForUserData(
user_data, static_cast<InfoBarIOS*>(infobar_),
InfobarOverlayType::kBanner);
InfobarOverlayType::kBanner, false);
}
} // namespace translate_infobar_overlays
......@@ -44,6 +44,6 @@ PasswordInfobarModalOverlayRequestConfig::
void PasswordInfobarModalOverlayRequestConfig::CreateAuxiliaryData(
base::SupportsUserData* user_data) {
InfobarOverlayRequestConfig::CreateForUserData(user_data, infobar_,
InfobarOverlayType::kModal);
InfobarOverlayRequestConfig::CreateForUserData(
user_data, infobar_, InfobarOverlayType::kModal, false);
}
......@@ -40,8 +40,8 @@ SaveCardModalRequestConfig::~SaveCardModalRequestConfig() = default;
void SaveCardModalRequestConfig::CreateAuxiliaryData(
base::SupportsUserData* user_data) {
InfobarOverlayRequestConfig::CreateForUserData(user_data, infobar_,
InfobarOverlayType::kModal);
InfobarOverlayRequestConfig::CreateForUserData(
user_data, infobar_, InfobarOverlayType::kModal, false);
}
NSMutableArray<SaveCardMessageWithLinks*>*
......
......@@ -41,8 +41,8 @@ TranslateModalRequestConfig::~TranslateModalRequestConfig() = default;
void TranslateModalRequestConfig::CreateAuxiliaryData(
base::SupportsUserData* user_data) {
InfobarOverlayRequestConfig::CreateForUserData(user_data, infobar_,
InfobarOverlayType::kModal);
InfobarOverlayRequestConfig::CreateForUserData(
user_data, infobar_, InfobarOverlayType::kModal, false);
}
} // namespace translate_infobar_overlays
......@@ -332,7 +332,7 @@ TEST_P(BadgeMediatorTest, InfobarBannerOverlayObserving) {
web_state(), OverlayModality::kInfobarBanner);
queue->AddRequest(
OverlayRequest::CreateWithConfig<InfobarOverlayRequestConfig>(
infobar, InfobarOverlayType::kBanner));
infobar, InfobarOverlayType::kBanner, infobar->high_priority()));
EXPECT_TRUE(item.badgeState & BadgeStatePresented);
// Simulate dismissal of the banner and verify that the badge state is no
......
......@@ -110,9 +110,13 @@
if (!UIAccessibilityIsVoiceOverRunning()) {
// Auto-dismiss the banner after timeout if VoiceOver is off (banner should
// persist until user explicitly swipes it away).
NSTimeInterval timeout =
config->is_high_priority()
? kInfobarBannerLongPresentationDurationInSeconds
: kInfobarBannerDefaultPresentationDurationInSeconds;
[self performSelector:@selector(dismissBannerIfReady)
withObject:nil
afterDelay:kInfobarBannerDefaultPresentationDurationInSeconds];
afterDelay:timeout];
}
}
......
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