Transfer Searchify state to PDF Viewer WebUI.
To measure PDF Searchify's success in increasing user interaction with PDFs and to show Searchify progress (see go/pdf-ocr-design, page 8), the following two states are passed to the PDF Viewer WebUI: - PDF has searchify text. - Searchify is in progress. The former will be used to record the new metrics and the latter will be used to show Searchify progress indicator. Bug: 360803943 Change-Id: I08bc59813b0ec1718df3475dc1a6ad8b1519b34c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6001955 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Ramin Halavati <rhalavati@chromium.org> Cr-Commit-Position: refs/heads/main@{#1380199}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
667b1f4889
commit
1907e156d4
@ -912,6 +912,12 @@ export class PdfViewerElement extends PdfViewerBaseElement {
|
||||
// Editing mode can only be entered once, and cannot be exited.
|
||||
this.hasEdits_ = true;
|
||||
return;
|
||||
case 'setHasSearchifyText':
|
||||
// TODO(crbug.com/360803943): Add separate metrics for searchified PDFs.
|
||||
return;
|
||||
case 'showSearchifyInProgress':
|
||||
// TODO(crbug.com/360803943): Trigger showing/hiding searchify progress.
|
||||
return;
|
||||
case 'startedFindInPage':
|
||||
record(UserAction.FIND_IN_PAGE);
|
||||
return;
|
||||
|
@ -1418,8 +1418,54 @@ bool PdfViewWebPlugin::IsInAnnotationMode() const {
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
void PdfViewWebPlugin::OnSearchifyStateChange(bool busy) {
|
||||
pdf_host_->OnSearchifyStateChange(busy);
|
||||
|
||||
if (busy && show_searchify_in_progress_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (busy) {
|
||||
// The UI is asked to show the progress indicator with 1s delay, so that if
|
||||
// the task finishes in less than 1s, the indicator would not be shown.
|
||||
show_searchify_in_progress_ = true;
|
||||
base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&PdfViewWebPlugin::SetShowSearchifyInProgress,
|
||||
weak_factory_.GetWeakPtr(), /*show=*/true),
|
||||
base::Seconds(1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (show_searchify_in_progress_) {
|
||||
show_searchify_in_progress_ = false;
|
||||
SetShowSearchifyInProgress(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void PdfViewWebPlugin::SetShowSearchifyInProgress(bool show) {
|
||||
// Searchify tasks are expected to be quite fast most of the times, and if so,
|
||||
// showing progress indicator is not needed.
|
||||
// `SetShowSearchifyInProgress` is posted with delay to allow discarding the
|
||||
// the request to show the progress indicator in such cases.
|
||||
// A true `show` and a false `show_searchify_in_progress_` means that the task
|
||||
// finished before the indicator is shown and UI element is not needed.
|
||||
if (show && !show_searchify_in_progress_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(crbug.com/360803943): Add test.
|
||||
base::Value::Dict message;
|
||||
message.Set("type", "showSearchifyInProgress");
|
||||
message.Set("show", show);
|
||||
client_->PostMessage(std::move(message));
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::OnHasSearchifyText() {
|
||||
// TODO(crbug.com/360803943): Add test.
|
||||
base::Value::Dict message;
|
||||
message.Set("type", "setHasSearchifyText");
|
||||
client_->PostMessage(std::move(message));
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
void PdfViewWebPlugin::SetCaretPosition(const gfx::PointF& position) {
|
||||
engine_->SetCaretPosition(FrameToPdfCoordinates(position));
|
||||
|
@ -385,6 +385,7 @@ class PdfViewWebPlugin final : public PDFiumEngineClient,
|
||||
#endif // BUILDFLAG(ENABLE_PDF_INK2)
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
void OnSearchifyStateChange(bool busy) override;
|
||||
void OnHasSearchifyText() override;
|
||||
#endif
|
||||
|
||||
// pdf::mojom::PdfListener:
|
||||
@ -694,6 +695,11 @@ class PdfViewWebPlugin final : public PDFiumEngineClient,
|
||||
// Starts loading accessibility information.
|
||||
void LoadAccessibility();
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
// Triggered to show/hide Searchify progress indicator.
|
||||
void SetShowSearchifyInProgress(bool show);
|
||||
#endif
|
||||
|
||||
bool initialized_ = false;
|
||||
|
||||
blink::WebString selected_text_;
|
||||
@ -914,6 +920,10 @@ class PdfViewWebPlugin final : public PDFiumEngineClient,
|
||||
// Queue of available preview pages to load next.
|
||||
base::queue<PreviewPageInfo> preview_pages_info_;
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
bool show_searchify_in_progress_ = false;
|
||||
#endif
|
||||
|
||||
base::WeakPtrFactory<PdfViewWebPlugin> weak_factory_{this};
|
||||
};
|
||||
|
||||
|
@ -4292,6 +4292,13 @@ void PDFiumEngine::CancelPendingSearchify(int page_index) {
|
||||
void PDFiumEngine::OnSearchifyStateChange(bool busy) {
|
||||
client_->OnSearchifyStateChange(busy);
|
||||
}
|
||||
|
||||
void PDFiumEngine::OnHasSearchifyText() {
|
||||
if (!has_searchify_text_) {
|
||||
has_searchify_text_ = true;
|
||||
client_->OnHasSearchifyText();
|
||||
}
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
void PDFiumEngine::UpdateLinkUnderCursor(const std::string& target_url) {
|
||||
|
@ -391,6 +391,9 @@ class PDFiumEngine : public DocumentLoader::Client, public IFSDK_PAUSE {
|
||||
// See the comment for `OnSearchifyStateChange` in pdf/pdf.mojom.
|
||||
void OnSearchifyStateChange(bool busy);
|
||||
|
||||
// Called when searchify text is added.
|
||||
void OnHasSearchifyText();
|
||||
|
||||
PDFiumOnDemandSearchifier* GetSearchifierForTesting() {
|
||||
return searchifier_.get();
|
||||
}
|
||||
@ -870,6 +873,9 @@ class PDFiumEngine : public DocumentLoader::Client, public IFSDK_PAUSE {
|
||||
// Keeps track of the indices of pages for which "PDF.PageHasText" metric is
|
||||
// reported.
|
||||
std::set<int> page_has_text_metric_reported_;
|
||||
|
||||
// Records if at least one page has searchify text.
|
||||
bool has_searchify_text_ = false;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<PDFiumDocument> document_;
|
||||
|
@ -207,6 +207,9 @@ class PDFiumEngineClient {
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
// See the comment for `OnSearchifyStateChange` in pdf/pdf.mojom.
|
||||
virtual void OnSearchifyStateChange(bool busy) = 0;
|
||||
|
||||
// Notifies that at least one page is searchified.
|
||||
virtual void OnHasSearchifyText() = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -168,12 +168,17 @@ void PDFiumOnDemandSearchifier::SearchifyNextImage() {
|
||||
// It is expected that the page would be still loaded.
|
||||
FPDF_PAGE page = current_page_->page();
|
||||
CHECK(page);
|
||||
bool added_text = false;
|
||||
for (auto& result : current_page_ocr_results_) {
|
||||
FPDF_PAGEOBJECT image = FPDFPage_GetObject(page, result.image_index);
|
||||
std::vector<FPDF_PAGEOBJECT> added_text_objects =
|
||||
AddTextOnImage(engine_->doc(), page, font_.get(), image,
|
||||
std::move(result.annotation), result.image_size);
|
||||
current_page_->OnSearchifyGotOcrResult(added_text_objects);
|
||||
added_text |= !added_text_objects.empty();
|
||||
}
|
||||
if (added_text) {
|
||||
engine_->OnHasSearchifyText();
|
||||
}
|
||||
current_page_ocr_results_.clear();
|
||||
|
||||
|
@ -179,7 +179,13 @@ bool PreviewModeClient::IsInAnnotationMode() const {
|
||||
#endif // BUILDFLAG(ENABLE_PDF_INK2)
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
void PreviewModeClient::OnSearchifyStateChange(bool busy) {}
|
||||
void PreviewModeClient::OnSearchifyStateChange(bool busy) {
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
void PreviewModeClient::OnHasSearchifyText() {
|
||||
NOTREACHED();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -80,6 +80,7 @@ class PreviewModeClient : public PDFiumEngineClient {
|
||||
#endif // BUILDFLAG(ENABLE_PDF_INK2)
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
void OnSearchifyStateChange(bool busy) override;
|
||||
void OnHasSearchifyText() override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
@ -80,6 +80,8 @@ bool TestClient::IsInAnnotationMode() const {
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
void TestClient::OnSearchifyStateChange(bool busy) {}
|
||||
|
||||
void TestClient::OnHasSearchifyText() {}
|
||||
#endif
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -50,6 +50,7 @@ class TestClient : public PDFiumEngineClient {
|
||||
#endif // BUILDFLAG(ENABLE_PDF_INK2)
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
void OnSearchifyStateChange(bool busy) override;
|
||||
void OnHasSearchifyText() override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user