fix: add missed enum SaveRequestType to PdfViewerPrivate function (#48409)

fix: add missed SaveRequestType enum to PdfViewerPrivate function

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
This commit is contained in:
BILL SHEN 2025-10-03 23:59:30 +08:00 committed by GitHub
commit 6dc3923b93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 0 deletions

View file

@ -72,3 +72,6 @@ enterprise_cloud_content_analysis = false
# We don't use anything from here, and it causes target collisions
enable_linux_installer = false
# Disable "Save to Drive" feature in PDF viewer
enable_pdf_save_to_drive = false

View file

@ -16,6 +16,7 @@
#include "components/pdf/common/constants.h"
#include "components/prefs/pref_service.h"
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
#include "pdf/buildflags.h"
#include "url/url_constants.h"
namespace extensions {
@ -25,6 +26,8 @@ namespace {
namespace IsAllowedLocalFileAccess =
api::pdf_viewer_private::IsAllowedLocalFileAccess;
namespace SaveToDrive = api::pdf_viewer_private::SaveToDrive;
namespace SetPdfPluginAttributes =
api::pdf_viewer_private::SetPdfPluginAttributes;
@ -107,6 +110,24 @@ PdfViewerPrivateIsAllowedLocalFileAccessFunction::Run() {
IsUrlAllowedToEmbedLocalFiles(GURL(params->url), base::Value::List())));
}
PdfViewerPrivateSaveToDriveFunction::PdfViewerPrivateSaveToDriveFunction() =
default;
PdfViewerPrivateSaveToDriveFunction::~PdfViewerPrivateSaveToDriveFunction() =
default;
ExtensionFunction::ResponseAction PdfViewerPrivateSaveToDriveFunction::Run() {
#if BUILDFLAG(ENABLE_PDF_SAVE_TO_DRIVE)
std::optional<SaveToDrive::Params> params =
SaveToDrive::Params::Create(args());
EXTENSION_FUNCTION_VALIDATE(params);
// TODO(crbug.com/424208776): Start the save to drive flow.
return RespondNow(NoArguments());
#else
return RespondNow(Error("Not supported"));
#endif // BUILDFLAG(ENABLE_PDF_SAVE_TO_DRIVE)
}
PdfViewerPrivateSetPdfDocumentTitleFunction::
PdfViewerPrivateSetPdfDocumentTitleFunction() = default;

View file

@ -46,6 +46,24 @@ class PdfViewerPrivateIsAllowedLocalFileAccessFunction
ResponseAction Run() override;
};
class PdfViewerPrivateSaveToDriveFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("pdfViewerPrivate.saveToDrive",
PDFVIEWERPRIVATE_SAVETODRIVE)
PdfViewerPrivateSaveToDriveFunction();
PdfViewerPrivateSaveToDriveFunction(
const PdfViewerPrivateSaveToDriveFunction&) = delete;
PdfViewerPrivateSaveToDriveFunction& operator=(
const PdfViewerPrivateSaveToDriveFunction&) = delete;
protected:
~PdfViewerPrivateSaveToDriveFunction() override;
// Override from ExtensionFunction:
ResponseAction Run() override;
};
class PdfViewerPrivateSetPdfDocumentTitleFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("pdfViewerPrivate.setPdfDocumentTitle",

View file

@ -6,6 +6,15 @@
// functionality that the PDF Viewer needs from outside the PDF plugin. This API
// is exclusively for the PDF Viewer.
namespace pdfViewerPrivate {
// Must match `SaveRequestType` in `pdf/mojom/pdf.mojom` and
// `tools/typescript/definitions/pdf_viewer_private.d.ts`.
enum SaveRequestType {
ANNOTATION,
ORIGINAL,
EDITED,
SEARCHIFIED
};
// Nearly identical to mimeHandlerPrivate.StreamInfo, but without a mime type
// nor a response header field. Those fields are unused by the PDF viewer.
dictionary StreamInfo {
@ -52,6 +61,13 @@ namespace pdfViewerPrivate {
DOMString url,
IsAllowedLocalFileAccessCallback callback);
// Sends a request to save the PDF to Google Drive if `saveRequestType` is
// set. Otherwise, if `saveRequestType` is not set, the default action is
// to cancel the existing upload.
static void saveToDrive(
optional SaveRequestType saveRequestType,
optional VoidCallback callback);
// Sets the current tab title to `title` for a full-page PDF.
static void setPdfDocumentTitle(
DOMString title,