Commit 1f3f00fe authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Fix crash in WebAppIconDownloader::CancelDownloads()

It is possible for CancelDownloads() to be called after the callback_
has already been called via successful download or a previous
navigation. This CL adds a null check to avoid crashing in these corner
case scenarios.

Bug: 1059847
Change-Id: Idc97407ba67195beba51a9053ee2d71dcbd911f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2102995Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750466}
parent 421d2ad9
......@@ -166,7 +166,8 @@ void WebAppIconDownloader::DidUpdateFaviconURL(
void WebAppIconDownloader::CancelDownloads() {
in_progress_requests_.clear();
icons_map_.clear();
std::move(callback_).Run(/*success=*/false, icons_map_);
if (callback_)
std::move(callback_).Run(/*success=*/false, icons_map_);
}
} // namespace web_app
......@@ -298,6 +298,24 @@ TEST_F(WebAppIconDownloaderTest, PageNavigates) {
EXPECT_FALSE(downloader.downloads_succeeded());
}
TEST_F(WebAppIconDownloaderTest, PageNavigatesAfterDownload) {
const GURL url("http://www.google.com/icon.png");
TestWebAppIconDownloader downloader(web_contents(), {url});
downloader.SkipPageFavicons();
downloader.Start();
EXPECT_EQ(1u, downloader.pending_requests());
downloader.CompleteImageDownload(0, 200, url, {gfx::Size(32, 32)});
EXPECT_EQ(0u, downloader.pending_requests());
EXPECT_TRUE(downloader.downloads_succeeded());
// Navigating the renderer after downloads have completed should not crash.
content::NavigationSimulator::CreateRendererInitiated(
GURL("https://foo.example"), main_rfh())
->Commit();
}
TEST_F(WebAppIconDownloaderTest, PageNavigatesSameDocument) {
content::NavigationSimulator::NavigateAndCommitFromBrowser(
web_contents(), GURL("https://foo.example"));
......
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