0

Update PDF Searchifier state transfer to browser.

`OnSearchifyStateChange` transfers the busy or not busy state of the
PDF searchifier to the browser to show UI elements. However only the
busy state is needed to show the IPH and the other state is not used.
Hence rename the function to `OnSearchifyStarted` and remove the
parameter.

Bug: 360803943
Change-Id: Ic7cc20aaf8eda759e2bd28355487e30535741eff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6016981
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
Auto-Submit: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1383547}
This commit is contained in:
Ramin Halavati
2024-11-15 12:31:47 +00:00
committed by Chromium LUCI CQ
parent 177d07e41d
commit f5526e69a4
11 changed files with 25 additions and 34 deletions

@ -101,17 +101,12 @@ void ChromePDFDocumentHelperClient::SetPluginCanSave(
}
}
void ChromePDFDocumentHelperClient::OnSearchifyStateChange(
bool busy,
void ChromePDFDocumentHelperClient::OnSearchifyStarted(
content::WebContents* contents) {
// TODO(crbug.com/360803943): Add test.
// Show the promo only when ScreenAI component is available and OCR can be
// done.
if (busy &&
screen_ai::ScreenAIInstallState::GetInstance()->IsComponentAvailable()) {
if (screen_ai::ScreenAIInstallState::GetInstance()->IsComponentAvailable()) {
MaybeShowFeaturePromo(contents);
}
// TODO(crbug.com/360803943): Manage progress indicator. If it's done through
// WebUI, update this function and the call chain to only send promo trigger.
}

@ -25,8 +25,7 @@ class ChromePDFDocumentHelperClient : public pdf::PDFDocumentHelperClient {
void OnSaveURL(content::WebContents* contents) override;
void SetPluginCanSave(content::RenderFrameHost* render_frame_host,
bool can_save) override;
void OnSearchifyStateChange(bool busy,
content::WebContents* contents) override;
void OnSearchifyStarted(content::WebContents* contents) override;
};
#endif // CHROME_BROWSER_UI_PDF_CHROME_PDF_DOCUMENT_HELPER_CLIENT_H_

@ -129,8 +129,8 @@ void PDFDocumentHelper::SetPluginCanSave(bool can_save) {
}
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
void PDFDocumentHelper::OnSearchifyStateChange(bool busy) {
client_->OnSearchifyStateChange(busy, &GetWebContents());
void PDFDocumentHelper::OnSearchifyStarted() {
client_->OnSearchifyStarted(&GetWebContents());
}
#endif

@ -88,7 +88,7 @@ class PDFDocumentHelper
int32_t right_height) override;
void SetPluginCanSave(bool can_save) override;
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
void OnSearchifyStateChange(bool busy) override;
void OnSearchifyStarted() override;
#endif
void GetPdfBytes(uint32_t size_limit,

@ -71,8 +71,7 @@ class TestPDFDocumentHelperClient : public PDFDocumentHelperClient {
start_ = start;
end_ = end;
}
void OnSearchifyStateChange(bool busy,
content::WebContents* contents) override {}
void OnSearchifyStarted(content::WebContents* contents) override {}
private:
// The last bounds reported by PDFDocumentHelper.

@ -36,9 +36,8 @@ class PDFDocumentHelperClient {
virtual void OnDidScroll(const gfx::SelectionBound& start,
const gfx::SelectionBound& end) {}
// See the comment for `OnSearchifyStateChange` in pdf/pdf.mojom.
virtual void OnSearchifyStateChange(bool busy,
content::WebContents* contents) = 0;
// Notifies that PDF searchifier started processing pages.
virtual void OnSearchifyStarted(content::WebContents* contents) = 0;
};
} // namespace pdf

@ -56,10 +56,7 @@ interface PdfHost {
// Notifies the embedder know the plugin can handle save commands internally.
SetPluginCanSave(bool can_save);
// Notifies that PDF searchifier has switched between busy or not busy.
// A busy state is when it has some queued pages to process or is processing a
// page at the moment. It comes out of this state either when all tasks are
// completed or canceled.
// Notifies that PDF searchifier has started processing pages.
[EnableIf=enable_screen_ai_service]
OnSearchifyStateChange(bool busy);
OnSearchifyStarted();
};

@ -1465,13 +1465,17 @@ 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_) {
if (!busy) {
if (show_searchify_in_progress_) {
show_searchify_in_progress_ = false;
SetShowSearchifyInProgress(false);
}
return;
}
if (busy) {
pdf_host_->OnSearchifyStarted();
if (!show_searchify_in_progress_) {
// 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;
@ -1482,11 +1486,6 @@ void PdfViewWebPlugin::OnSearchifyStateChange(bool busy) {
kSearchifyStatePropagationDelay);
return;
}
if (show_searchify_in_progress_) {
show_searchify_in_progress_ = false;
SetShowSearchifyInProgress(false);
}
}
void PdfViewWebPlugin::SetShowSearchifyInProgress(bool show) {

@ -366,7 +366,7 @@ class FakePdfHost : public pdf::mojom::PdfHost {
(override));
MOCK_METHOD(void, SetPluginCanSave, (bool), (override));
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
MOCK_METHOD(void, OnSearchifyStateChange, (bool), (override));
MOCK_METHOD(void, OnSearchifyStarted, (), (override));
#endif
};

@ -458,7 +458,10 @@ class PDFiumEngine : public DocumentLoader::Client, public IFSDK_PAUSE {
// if the page is not scheduled for searchify.
void CancelPendingSearchify(int page_index);
// See the comment for `OnSearchifyStateChange` in pdf/pdf.mojom.
// Notifies that PDF searchifier has switched between busy or not busy.
// A busy state is when it has some queued pages to process or is processing a
// page at the moment. It comes out of this state either when all tasks are
// completed or canceled.
void OnSearchifyStateChange(bool busy);
// Called when searchify text is added.

@ -205,7 +205,7 @@ class PDFiumEngineClient {
#endif // BUILDFLAG(ENABLE_PDF_INK2)
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
// See the comment for `OnSearchifyStateChange` in pdf/pdf.mojom.
// See the comment for `OnSearchifyStateChange` in pdf/pdfium/pdfium_engine.h.
virtual void OnSearchifyStateChange(bool busy) = 0;
// Notifies that at least one page is searchified.