Commit 0a088fca authored by Ayu Ishii's avatar Ayu Ishii Committed by Commit Bot

WebOTP: Cancel when Sms Retreiver is called on Payments Handler

This change adds a check in the WebContentsDelevate is available before trying
to show a prompt. Currently it crashes when trying to use it via the Payment
Handler.

Change-Id: Icfd16c2c408212b3698b6cff97a9c2b3f81f820e
Bug: 1051930
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2081351
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746489}
parent 8a59a23c
......@@ -63,6 +63,17 @@ void SmsService::Create(
void SmsService::Receive(ReceiveCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// This flow relies on the delegate to display an infobar for user
// confirmation. Cancelling the call early if no delegate is available is
// easier to debug then silently dropping SMSes later on.
WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host());
if (!web_contents->GetDelegate()) {
std::move(callback).Run(SmsStatus::kCancelled, base::nullopt,
base::nullopt);
return;
}
if (callback_) {
std::move(callback_).Run(SmsStatus::kCancelled, base::nullopt,
base::nullopt);
......@@ -70,7 +81,6 @@ void SmsService::Receive(ReceiveCallback callback) {
}
start_time_ = base::TimeTicks::Now();
callback_ = std::move(callback);
// |one_time_code_|, |sms_| and prompt are still present from the previous
......@@ -126,6 +136,10 @@ void SmsService::NavigationEntryCommitted(
void SmsService::OpenInfoBar(const std::string& one_time_code) {
WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host());
if (!web_contents->GetDelegate()) {
Process(SmsStatus::kCancelled, base::nullopt, base::nullopt);
return;
}
prompt_open_ = true;
web_contents->GetDelegate()->CreateSmsPrompt(
......
......@@ -502,6 +502,31 @@ TEST_F(SmsServiceTest, Cancel) {
ASSERT_FALSE(service.fetcher()->HasSubscribers());
}
TEST_F(SmsServiceTest, CancelForNoDelegate) {
NavigateAndCommit(GURL(kTestUrl));
auto provider = std::make_unique<MockSmsProvider>();
SmsFetcherImpl fetcher(web_contents()->GetBrowserContext(),
std::move(provider));
mojo::Remote<blink::mojom::SmsReceiver> service;
SmsService::Create(&fetcher, main_rfh(),
service.BindNewPipeAndPassReceiver());
base::RunLoop loop;
service->Receive(base::BindLambdaForTesting(
[&loop](SmsStatus status, const Optional<string>& otp,
const Optional<string>& sms) {
EXPECT_EQ(SmsStatus::kCancelled, status);
EXPECT_EQ(base::nullopt, sms);
loop.Quit();
}));
loop.Run();
ASSERT_FALSE(fetcher.HasSubscribers());
}
TEST_F(SmsServiceTest, Abort) {
NavigateAndCommit(GURL(kTestUrl));
......
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