diff --git a/build/args/all.gn b/build/args/all.gn index 1f79dea5ca7..4da70319aa8 100644 --- a/build/args/all.gn +++ b/build/args/all.gn @@ -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 diff --git a/shell/browser/extensions/api/pdf_viewer_private/pdf_viewer_private_api.cc b/shell/browser/extensions/api/pdf_viewer_private/pdf_viewer_private_api.cc index bab43369537..07e285c6fa1 100644 --- a/shell/browser/extensions/api/pdf_viewer_private/pdf_viewer_private_api.cc +++ b/shell/browser/extensions/api/pdf_viewer_private/pdf_viewer_private_api.cc @@ -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 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; diff --git a/shell/browser/extensions/api/pdf_viewer_private/pdf_viewer_private_api.h b/shell/browser/extensions/api/pdf_viewer_private/pdf_viewer_private_api.h index f184924ad8d..86ce8e86666 100644 --- a/shell/browser/extensions/api/pdf_viewer_private/pdf_viewer_private_api.h +++ b/shell/browser/extensions/api/pdf_viewer_private/pdf_viewer_private_api.h @@ -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", diff --git a/shell/common/extensions/api/pdf_viewer_private.idl b/shell/common/extensions/api/pdf_viewer_private.idl index 0de5d9f6ce6..449f53ccfc4 100644 --- a/shell/common/extensions/api/pdf_viewer_private.idl +++ b/shell/common/extensions/api/pdf_viewer_private.idl @@ -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,