Share kMaxPreviewPages between PreviewPageTextExtractor and PdfToBitmapConverter
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "brave/browser/ui/webui/ai_chat/ai_chat_ui.h"
|
||||
#include "brave/browser/ui/webui/ai_chat/ai_chat_ui_page_handler.h"
|
||||
#include "brave/components/ai_chat/content/browser/ai_chat_tab_helper.h"
|
||||
#include "brave/components/ai_chat/core/browser/constants.h"
|
||||
#include "brave/components/constants/brave_paths.h"
|
||||
#include "brave/components/l10n/common/test/scoped_default_locale.h"
|
||||
#include "brave/components/text_recognition/common/buildflags/buildflags.h"
|
||||
@@ -191,7 +192,7 @@ IN_PROC_BROWSER_TEST_F(AIChatUIBrowserTest, PrintPreviewPagesLimit) {
|
||||
NavigateURL(
|
||||
https_server_.GetURL("docs.google.com", "/extra_long_canvas.html"));
|
||||
CreatePrintPreview(ai_chat_page_handler);
|
||||
std::string expected_string(19, '\n');
|
||||
std::string expected_string(ai_chat::kMaxPreviewPages - 1, '\n');
|
||||
base::StrAppend(&expected_string, {"This is the way."});
|
||||
FetchPageContent(FROM_HERE, chat_tab_helper, expected_string);
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ void AIChatUIPageHandler::OnPreviewReady() {
|
||||
prefs->GetBoolean(::prefs::kPdfUseSkiaRendererEnabled));
|
||||
}
|
||||
pdf_to_bitmap_converter_->GetBitmap(
|
||||
std::move(pdf_region.region),
|
||||
std::move(pdf_region.region), kMaxPreviewPages,
|
||||
base::BindOnce(&AIChatUIPageHandler::OnGetBitmaps,
|
||||
base::Unretained(this)));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "base/task/bind_post_task.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#include "base/task/thread_pool.h"
|
||||
#include "brave/components/ai_chat/core/browser/constants.h"
|
||||
#include "brave/components/ai_chat/core/common/mojom/page_content_extractor.mojom.h"
|
||||
#include "brave/components/l10n/common/locale_util.h"
|
||||
#include "brave/components/text_recognition/common/buildflags/buildflags.h"
|
||||
@@ -57,7 +58,6 @@ constexpr auto kScreenshotRetrievalHosts =
|
||||
{
|
||||
"twitter.com",
|
||||
});
|
||||
constexpr size_t kMaxPreviewPages = 20;
|
||||
#endif
|
||||
|
||||
constexpr auto kVideoPageContentTypes =
|
||||
|
||||
@@ -17,6 +17,8 @@ base::span<const webui::LocalizedString> GetLocalizedStrings();
|
||||
extern const base::fixed_flat_set<std::string_view, 1>
|
||||
kPrintPreviewRetrievalHosts;
|
||||
|
||||
constexpr uint8_t kMaxPreviewPages = 20;
|
||||
|
||||
} // namespace ai_chat
|
||||
|
||||
#endif // BRAVE_COMPONENTS_AI_CHAT_CORE_BROWSER_CONSTANTS_H_
|
||||
|
||||
@@ -22,6 +22,7 @@ PdfToBitmapConverter::~PdfToBitmapConverter() = default;
|
||||
|
||||
void PdfToBitmapConverter::GetBitmap(
|
||||
base::ReadOnlySharedMemoryRegion pdf_region,
|
||||
std::optional<uint8_t> max_pages,
|
||||
GetBitmapCallback callback) {
|
||||
// Decode memory region as PDF bytes.
|
||||
base::ReadOnlySharedMemoryMapping pdf_map = pdf_region.Map();
|
||||
@@ -39,6 +40,10 @@ void PdfToBitmapConverter::GetBitmap(
|
||||
return;
|
||||
}
|
||||
|
||||
if (max_pages.has_value() && *max_pages < page_count) {
|
||||
page_count = *max_pages;
|
||||
}
|
||||
|
||||
std::vector<SkBitmap> bitmaps;
|
||||
for (int page_index = 0; page_index < page_count; page_index++) {
|
||||
std::optional<gfx::SizeF> page_size =
|
||||
|
||||
@@ -23,6 +23,7 @@ class PdfToBitmapConverter : public printing::mojom::PdfToBitmapConverter {
|
||||
|
||||
// printing::mojom::PdfToBitmapConverter:
|
||||
void GetBitmap(base::ReadOnlySharedMemoryRegion pdf_region,
|
||||
std::optional<uint8_t> max_pages,
|
||||
GetBitmapCallback callback) override;
|
||||
|
||||
void SetUseSkiaRendererPolicy(bool use_skia) override;
|
||||
|
||||
@@ -10,8 +10,9 @@ import "skia/public/mojom/bitmap.mojom";
|
||||
import "ui/gfx/geometry/mojom/geometry.mojom";
|
||||
|
||||
interface PdfToBitmapConverter {
|
||||
GetBitmap(mojo_base.mojom.ReadOnlySharedMemoryRegion pdf_region)
|
||||
=> (array<skia.mojom.BitmapN32>? bitmap);
|
||||
// If max_pages is provided, the converter will process at most max_pages
|
||||
GetBitmap(mojo_base.mojom.ReadOnlySharedMemoryRegion pdf_region,
|
||||
uint8? max_pages) => (array<skia.mojom.BitmapN32>? bitmap);
|
||||
|
||||
// Sets the status for enterprise policy `kPdfUseSkiaRendererEnabled`. It
|
||||
// should be called immediately once `mojom::PdfToBitmapConverter` remote
|
||||
|
||||
Reference in New Issue
Block a user