Compare commits

...

1 Commits

Author SHA1 Message Date
Shelley Vohr
045200d662 fix: pdf download functionality
https://chromium-review.googlesource.com/c/chromium/src/+/6682424
2025-09-18 21:35:16 -04:00
3 changed files with 51 additions and 0 deletions

View File

@@ -25,6 +25,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 +109,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,14 @@
// 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/pdf_view_web_plugin.h` 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 +60,11 @@ namespace pdfViewerPrivate {
DOMString url,
IsAllowedLocalFileAccessCallback callback);
// Sends a request to save the PDF to Google Drive.
static void saveToDrive(
SaveRequestType saveRequestType,
optional VoidCallback callback);
// Sets the current tab title to `title` for a full-page PDF.
static void setPdfDocumentTitle(
DOMString title,