0

Delay committing searchify results if page is being painted.

If a page is in progressive paint, committing searchify results can
crash PDFium. Hence delay adding the changes to the page until paint
completes for that page.

Bug: 392885625
Change-Id: I1d052985a7bdfbe98bd8f9d3051d1a28b031f3d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6218539
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1413919}
This commit is contained in:
Ramin Halavati
2025-01-30 22:08:47 -08:00
committed by Chromium LUCI CQ
parent 1adc264465
commit bcef8924d7
4 changed files with 28 additions and 0 deletions

@ -4384,6 +4384,15 @@ void PDFiumEngine::OnHasSearchifyText() {
client_->OnHasSearchifyText();
}
}
bool PDFiumEngine::IsPageScheduledForPaint(int page_index) const {
for (const auto& progressive_paint : progressive_paints_) {
if (progressive_paint.page_index() == page_index) {
return true;
}
}
return false;
}
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
void PDFiumEngine::UpdateLinkUnderCursor(const std::string& target_url) {

@ -480,6 +480,9 @@ class PDFiumEngine : public DocumentLoader::Client, public IFSDK_PAUSE {
PDFiumOnDemandSearchifier* GetSearchifierForTesting() {
return searchifier_.get();
}
// Tells if the page is in `progressive_paints_`
bool IsPageScheduledForPaint(int page_index) const;
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
void UnsupportedFeature(const std::string& feature);

@ -164,7 +164,21 @@ void PDFiumOnDemandSearchifier::SearchifyNextImage() {
!current_page_ocr_results_.empty());
}
CommitResultsToPage();
}
void PDFiumOnDemandSearchifier::CommitResultsToPage() {
if (!current_page_ocr_results_.empty()) {
// If the page is being painted, wait for paint to finish.
if (engine_->IsPageScheduledForPaint(current_page_->index())) {
base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&PDFiumOnDemandSearchifier::CommitResultsToPage,
weak_factory_.GetWeakPtr()),
kSearchifyPageDelay);
return;
}
// It is expected that the page would be still loaded.
FPDF_PAGE page = current_page_->page();
CHECK(page);

@ -54,6 +54,8 @@ class PDFiumOnDemandSearchifier {
void SearchifyNextPage();
void SearchifyNextImage();
void CommitResultsToPage();
struct BitmapResult {
SkBitmap bitmap;
int image_index;