Mark PdfProgressiveSearchifier as Chrome OS only
It is not used on other platforms. This also makes chrome_pdf::Searchify() and CreateProgressiveSearchifier() Chrome OS only. Change-Id: Id1012402a11bfcfe0db4cd39bbf18fd0cc2928ba Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5903662 Reviewed-by: Chu-Hsuan Yang <chuhsuan@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1364052}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f84363d262
commit
e2a56cae9d
15
pdf/BUILD.gn
15
pdf/BUILD.gn
@ -54,7 +54,7 @@ if (enable_pdf) {
|
||||
"//ui/gfx/geometry",
|
||||
]
|
||||
|
||||
if (enable_screen_ai_service) {
|
||||
if (is_chromeos && enable_screen_ai_service) {
|
||||
public_deps = [ ":pdf_progressive_searchifier" ]
|
||||
}
|
||||
}
|
||||
@ -238,8 +238,6 @@ if (enable_pdf) {
|
||||
sources += [
|
||||
"pdfium/pdfium_on_demand_searchifier.cc",
|
||||
"pdfium/pdfium_on_demand_searchifier.h",
|
||||
"pdfium/pdfium_progressive_searchifier.cc",
|
||||
"pdfium/pdfium_progressive_searchifier.h",
|
||||
"pdfium/pdfium_searchify.cc",
|
||||
"pdfium/pdfium_searchify.h",
|
||||
"pdfium/pdfium_searchify_font.cc",
|
||||
@ -248,11 +246,18 @@ if (enable_pdf) {
|
||||
|
||||
public_deps += [ "//services/screen_ai/public/mojom" ]
|
||||
|
||||
deps += [ ":pdf_progressive_searchifier" ]
|
||||
if (is_chromeos) {
|
||||
sources += [
|
||||
"pdfium/pdfium_progressive_searchifier.cc",
|
||||
"pdfium/pdfium_progressive_searchifier.h",
|
||||
]
|
||||
|
||||
deps += [ ":pdf_progressive_searchifier" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enable_screen_ai_service) {
|
||||
if (is_chromeos && enable_screen_ai_service) {
|
||||
source_set("pdf_progressive_searchifier") {
|
||||
public = [ "pdf_progressive_searchifier.h" ]
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "base/check.h"
|
||||
#include "base/feature_list.h"
|
||||
#include "build/build_config.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "pdf/pdf_features.h"
|
||||
#include "pdf/pdf_init.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
@ -20,14 +21,14 @@
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/size_f.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#include <memory>
|
||||
|
||||
#include "base/functional/callback.h"
|
||||
#include "pdf/pdf_progressive_searchifier.h"
|
||||
#include "services/screen_ai/public/mojom/screen_ai_service.mojom.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
@ -184,7 +185,7 @@ std::vector<uint8_t> ConvertPdfDocumentToNupPdf(
|
||||
input_buffer, pages_per_sheet, page_size, printable_area);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
std::vector<uint8_t> Searchify(
|
||||
base::span<const uint8_t> pdf_buffer,
|
||||
base::RepeatingCallback<screen_ai::mojom::VisualAnnotationPtr(
|
||||
@ -198,6 +199,6 @@ std::unique_ptr<PdfProgressiveSearchifier> CreateProgressiveSearchifier() {
|
||||
PDFiumEngineExports* engine_exports = PDFiumEngineExports::Get();
|
||||
return engine_exports->CreateProgressiveSearchifier();
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
13
pdf/pdf.h
13
pdf/pdf.h
@ -11,6 +11,7 @@
|
||||
#include "base/containers/span.h"
|
||||
#include "base/values.h"
|
||||
#include "build/build_config.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
#include "services/screen_ai/buildflags/buildflags.h"
|
||||
|
||||
@ -22,13 +23,13 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#include <memory>
|
||||
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "services/screen_ai/public/mojom/screen_ai_service.mojom.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
namespace gfx {
|
||||
class Rect;
|
||||
@ -38,9 +39,9 @@ class SizeF;
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
class PdfProgressiveSearchifier;
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
void SetUseSkiaRendererPolicy(bool use_skia);
|
||||
|
||||
@ -225,7 +226,7 @@ std::vector<uint8_t> ConvertPdfDocumentToNupPdf(
|
||||
const gfx::Size& page_size,
|
||||
const gfx::Rect& printable_area);
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
// Converts an inaccessible PDF to a searchable PDF.
|
||||
// `pdf_buffer` is the buffer of the inaccessible PDF.
|
||||
// `perform_ocr_callback` is the callback that takes an image and outputs
|
||||
@ -244,7 +245,7 @@ std::vector<uint8_t> Searchify(
|
||||
// Creates a PDF searchifier for future operations, such as adding and deleting
|
||||
// pages, and saving PDFs. Crashes if failed to create.
|
||||
std::unique_ptr<PdfProgressiveSearchifier> CreateProgressiveSearchifier();
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "base/notreached.h"
|
||||
#include "base/numerics/checked_math.h"
|
||||
#include "build/build_config.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
#include "pdf/loader/document_loader.h"
|
||||
#include "pdf/loader/url_loader_wrapper.h"
|
||||
@ -38,7 +39,7 @@
|
||||
#include "ui/gfx/geometry/size_f.h"
|
||||
#include "ui/gfx/geometry/vector2d.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#include <memory>
|
||||
|
||||
#include "base/functional/callback.h"
|
||||
@ -47,7 +48,7 @@
|
||||
#include "pdf/pdfium/pdfium_searchify.h"
|
||||
#include "services/screen_ai/public/mojom/screen_ai_service.mojom.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#endif
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
using printing::ConvertUnitFloat;
|
||||
using printing::kPointsPerInch;
|
||||
@ -568,7 +569,7 @@ std::optional<gfx::SizeF> PDFiumEngineExports::GetPDFPageSizeByIndex(
|
||||
return gfx::SizeF(size.width, size.height);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
std::vector<uint8_t> PDFiumEngineExports::Searchify(
|
||||
base::span<const uint8_t> pdf_buffer,
|
||||
base::RepeatingCallback<screen_ai::mojom::VisualAnnotationPtr(
|
||||
@ -580,6 +581,6 @@ std::unique_ptr<PdfProgressiveSearchifier>
|
||||
PDFiumEngineExports::CreateProgressiveSearchifier() {
|
||||
return std::make_unique<PdfiumProgressiveSearchifier>();
|
||||
}
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "base/containers/span.h"
|
||||
#include "base/values.h"
|
||||
#include "build/build_config.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "pdf/document_metadata.h"
|
||||
#include "services/screen_ai/buildflags/buildflags.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
@ -28,19 +29,19 @@
|
||||
#include "pdf/flatten_pdf_result.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#include <memory>
|
||||
|
||||
#include "base/functional/callback_forward.h"
|
||||
#include "services/screen_ai/public/mojom/screen_ai_service.mojom.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#endif
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
class PdfProgressiveSearchifier;
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
// Interface for exports that wrap PDFiumEngine.
|
||||
class PDFiumEngineExports {
|
||||
@ -140,7 +141,7 @@ class PDFiumEngineExports {
|
||||
base::span<const uint8_t> pdf_buffer,
|
||||
int page_index);
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
// Converts an inaccessible PDF to a searchable PDF. See `Searchify` in pdf.h
|
||||
// for more details.
|
||||
std::vector<uint8_t> Searchify(
|
||||
@ -151,7 +152,7 @@ class PDFiumEngineExports {
|
||||
// Creates a PDF searchifier for future operations, such as adding and
|
||||
// deleting pages, and saving PDFs.
|
||||
std::unique_ptr<PdfProgressiveSearchifier> CreateProgressiveSearchifier();
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
};
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/test/mock_callback.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "pdf/pdf.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "services/screen_ai/buildflags/buildflags.h"
|
||||
@ -22,7 +23,7 @@
|
||||
#include "ui/gfx/geometry/size_f.h"
|
||||
#include "ui/gfx/geometry/test/geometry_util.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@ -32,12 +33,13 @@
|
||||
#include "services/screen_ai/public/mojom/screen_ai_service.mojom.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
namespace {
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
class ScopedLibraryInitializer {
|
||||
public:
|
||||
ScopedLibraryInitializer() {
|
||||
@ -47,27 +49,6 @@ class ScopedLibraryInitializer {
|
||||
~ScopedLibraryInitializer() { ShutdownSDK(); }
|
||||
};
|
||||
|
||||
class PDFiumEngineExportsTest : public testing::Test {
|
||||
public:
|
||||
PDFiumEngineExportsTest() = default;
|
||||
PDFiumEngineExportsTest(const PDFiumEngineExportsTest&) = delete;
|
||||
PDFiumEngineExportsTest& operator=(const PDFiumEngineExportsTest&) = delete;
|
||||
~PDFiumEngineExportsTest() override = default;
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
pdf_data_dir_ = base::PathService::CheckedGet(base::DIR_SRC_TEST_DATA_ROOT)
|
||||
.Append(FILE_PATH_LITERAL("pdf"))
|
||||
.Append(FILE_PATH_LITERAL("test"))
|
||||
.Append(FILE_PATH_LITERAL("data"));
|
||||
}
|
||||
|
||||
const base::FilePath& pdf_data_dir() const { return pdf_data_dir_; }
|
||||
|
||||
private:
|
||||
base::FilePath pdf_data_dir_;
|
||||
};
|
||||
|
||||
// Returns all characters in the page.
|
||||
std::string GetText(base::span<const uint8_t> pdf, int page_index) {
|
||||
ScopedFPDFDocument document(
|
||||
@ -112,6 +93,28 @@ std::vector<gfx::RectF> GetTextPositions(base::span<const uint8_t> pdf,
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
class PDFiumEngineExportsTest : public testing::Test {
|
||||
public:
|
||||
PDFiumEngineExportsTest() = default;
|
||||
PDFiumEngineExportsTest(const PDFiumEngineExportsTest&) = delete;
|
||||
PDFiumEngineExportsTest& operator=(const PDFiumEngineExportsTest&) = delete;
|
||||
~PDFiumEngineExportsTest() override = default;
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
pdf_data_dir_ = base::PathService::CheckedGet(base::DIR_SRC_TEST_DATA_ROOT)
|
||||
.Append(FILE_PATH_LITERAL("pdf"))
|
||||
.Append(FILE_PATH_LITERAL("test"))
|
||||
.Append(FILE_PATH_LITERAL("data"));
|
||||
}
|
||||
|
||||
const base::FilePath& pdf_data_dir() const { return pdf_data_dir_; }
|
||||
|
||||
private:
|
||||
base::FilePath pdf_data_dir_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -221,7 +224,7 @@ TEST_F(PDFiumEngineExportsTest, ConvertPdfDocumentToNupPdf) {
|
||||
}
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
constexpr char kExpectedText[] = "Hello World! 你好!🙂";
|
||||
|
||||
TEST_F(PDFiumEngineExportsTest, Searchify) {
|
||||
@ -446,6 +449,6 @@ TEST_F(PDFiumEngineExportsTest, PdfProgressiveSearchifierText) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
#endif // BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
Reference in New Issue
Block a user