Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider IDS_PDF_OCR_IN_PROGRESS when checking whether PDF is loaded. (uplift to 1.71.x) #25637

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions browser/ai_chat/ai_chat_ui_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,23 @@ IN_PROC_BROWSER_TEST_F(AIChatUIBrowserTest, ExtractionPrintDialog) {
#endif // BUILDFLAG(IS_WIN) && defined(ADDRESS_SANITIZER) &&
// defined(ARCH_CPU_64_BITS)
IN_PROC_BROWSER_TEST_F(AIChatUIBrowserTest, MAYBE_PrintPreviewFallback) {
auto run_loop = std::make_unique<base::RunLoop>();
// TODO(darkdh): Enable text_in_image.pdf when upstream fixes the hanging
// blank page issue. See https://github.com/brave/brave-browser/issues/41113
#if 0
NavigateURL(https_server_.GetURL("a.com", "/text_in_image.pdf"));

auto run_loop = std::make_unique<base::RunLoop>();
chat_tab_helper_->GeneratePageContent(
base::BindLambdaForTesting([&run_loop](std::string text, bool is_video,
std::string invalidation_token) {
EXPECT_FALSE(is_video);
EXPECT_EQ(
text,
"This is the way.\n\nI have spoken.\nWherever I Go, He Goes.");
EXPECT_EQ(text,
"This is the way.\n\nI have spoken.\nWherever I Go, He Goes.");
run_loop->Quit();
}));
run_loop->Run();
run_loop = std::make_unique<base::RunLoop>();
#endif

NavigateURL(https_server_.GetURL("a.com", "/canvas.html"));
chat_tab_helper_->GeneratePageContent(
Expand Down
9 changes: 9 additions & 0 deletions components/ai_chat/content/browser/pdf_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "brave/components/ai_chat/content/browser/pdf_utils.h"

#include "base/strings/strcat.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "pdf/buildflags.h"
Expand Down Expand Up @@ -127,6 +128,14 @@ bool IsPdfLoaded(const ui::AXNode* pdf_root) {
return false;
}

#if BUILDFLAG(ENABLE_PDF)
if (pdf_root->GetChildAtIndex(0)->GetChildAtIndex(0)->GetStringAttribute(
ax::mojom::StringAttribute::kName) ==
l10n_util::GetStringUTF8(IDS_PDF_OCR_IN_PROGRESS)) {
return false;
}
#endif

return true;
}

Expand Down
Loading