[go: nahoru, domu]

blob: 37bd92bf525a4966119dcd0b7f607ba3161c19a7 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2020 The Chromium Authors
Alexander Bolodurine76e12a2020-10-06 09:05:352// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4//
5// This file provides API functions to fetch external thumbnails for filesystem
6// providers that support it.
7
Joel Hockeyc2aae802023-08-11 05:06:138#ifndef CHROME_BROWSER_ASH_EXTENSIONS_FILE_MANAGER_IMAGE_LOADER_PRIVATE_API_H_
9#define CHROME_BROWSER_ASH_EXTENSIONS_FILE_MANAGER_IMAGE_LOADER_PRIVATE_API_H_
Alexander Bolodurine76e12a2020-10-06 09:05:3510
11#include <memory>
12#include <string>
13
Henrique Ferreirod67f0472022-11-05 00:40:0914#include "chrome/browser/ash/extensions/file_manager/logged_extension_function.h"
Alexander Bolodurine76e12a2020-10-06 09:05:3515
Henrique Ferreiroe828b7b02021-03-23 23:00:5916#include "chrome/browser/ash/arc/fileapi/arc_documents_provider_root.h"
Joel Hockeyc2aae802023-08-11 05:06:1317#include "chrome/common/extensions/api/image_loader_private.h"
Alexander Bolodurine76e12a2020-10-06 09:05:3518#include "chrome/services/printing/public/mojom/pdf_thumbnailer.mojom.h"
19#include "mojo/public/cpp/bindings/remote.h"
Alexander Bolodurin5b217412020-10-21 11:55:3120#include "storage/browser/file_system/file_system_url.h"
Alexander Bolodurine76e12a2020-10-06 09:05:3521
22class SkBitmap;
23
24namespace extensions {
25
26// Base class for thumbnail functions
Joel Hockeyc2aae802023-08-11 05:06:1327class ImageLoaderPrivateGetThumbnailFunction : public LoggedExtensionFunction {
Alexander Bolodurine76e12a2020-10-06 09:05:3528 public:
Joel Hockeyc2aae802023-08-11 05:06:1329 ImageLoaderPrivateGetThumbnailFunction();
Alexander Bolodurine76e12a2020-10-06 09:05:3530
31 protected:
Joel Hockeyc2aae802023-08-11 05:06:1332 ~ImageLoaderPrivateGetThumbnailFunction() override = default;
Alexander Bolodurine76e12a2020-10-06 09:05:3533
34 // Responds with a base64 encoded PNG thumbnail data.
35 void SendEncodedThumbnail(std::string thumbnail_data_url);
Alexander Bolodurine76e12a2020-10-06 09:05:3536};
37
Joel Hockeyc2aae802023-08-11 05:06:1338class ImageLoaderPrivateGetDriveThumbnailFunction
39 : public ImageLoaderPrivateGetThumbnailFunction {
Alexander Bolodurine76e12a2020-10-06 09:05:3540 public:
Joel Hockeyc2aae802023-08-11 05:06:1341 DECLARE_EXTENSION_FUNCTION("imageLoaderPrivate.getDriveThumbnail",
42 IMAGELOADERPRIVATE_GETDRIVETHUMBNAIL)
Alexander Bolodurine76e12a2020-10-06 09:05:3543
Joel Hockeyc2aae802023-08-11 05:06:1344 ImageLoaderPrivateGetDriveThumbnailFunction();
Alexander Bolodurine76e12a2020-10-06 09:05:3545
46 protected:
Joel Hockeyc2aae802023-08-11 05:06:1347 ~ImageLoaderPrivateGetDriveThumbnailFunction() override;
Alexander Bolodurine76e12a2020-10-06 09:05:3548
49 // ExtensionFunction overrides.
50 ResponseAction Run() override;
51
52 private:
53 // A callback invoked when thumbnail data has been generated.
Mohamed Mansour5cf92142023-12-08 23:12:1254 void GotThumbnail(const std::optional<std::vector<uint8_t>>& data);
Alexander Bolodurine76e12a2020-10-06 09:05:3555};
56
Joel Hockeyc2aae802023-08-11 05:06:1357class ImageLoaderPrivateGetPdfThumbnailFunction
58 : public ImageLoaderPrivateGetThumbnailFunction {
Alexander Bolodurine76e12a2020-10-06 09:05:3559 public:
Joel Hockeyc2aae802023-08-11 05:06:1360 DECLARE_EXTENSION_FUNCTION("imageLoaderPrivate.getPdfThumbnail",
61 IMAGELOADERPRIVATE_GETPDFTHUMBNAIL)
Alexander Bolodurine76e12a2020-10-06 09:05:3562
Joel Hockeyc2aae802023-08-11 05:06:1363 ImageLoaderPrivateGetPdfThumbnailFunction();
Alexander Bolodurine76e12a2020-10-06 09:05:3564
65 protected:
Joel Hockeyc2aae802023-08-11 05:06:1366 ~ImageLoaderPrivateGetPdfThumbnailFunction() override;
Alexander Bolodurine76e12a2020-10-06 09:05:3567
68 // ExtensionFunction overrides.
69 ResponseAction Run() override;
70
71 private:
72 // For a given |content| starts fetching the first page PDF thumbnail by
73 // calling PdfThumbnailer from the printing service. The first parameters,
74 // |size| is supplied by the JavaScript caller.
75 void FetchThumbnail(const gfx::Size& size, const std::string& content);
76
77 // Callback invoked by the thumbnailing service when a PDF thumbnail has been
78 // generated. The solitary parameter |bitmap| is supplied by the callback.
79 // If |bitmap| is null, an error occurred. Otherwise, |bitmap| contains the
80 // generated thumbnail.
81 void GotThumbnail(const SkBitmap& bitmap);
82
83 // Handles a mojo channel disconnect event.
84 void ThumbnailDisconnected();
85
86 // Holds the channel to Printing PDF thumbnailing service. Bound only
87 // when needed.
88 mojo::Remote<printing::mojom::PdfThumbnailer> pdf_thumbnailer_;
89
90 // The dots per inch (dpi) resolution at which the PDF is rendered to a
91 // thumbnail. The value of 30 is selected so that a US Letter size page does
92 // not overflow a kSize x kSize thumbnail.
93 constexpr static int kDpi = 30;
94};
95
Joel Hockeyc2aae802023-08-11 05:06:1396class ImageLoaderPrivateGetArcDocumentsProviderThumbnailFunction
97 : public ImageLoaderPrivateGetThumbnailFunction {
Alexander Bolodurin5b217412020-10-21 11:55:3198 public:
99 DECLARE_EXTENSION_FUNCTION(
Joel Hockeyc2aae802023-08-11 05:06:13100 "imageLoaderPrivate.getArcDocumentsProviderThumbnail",
101 IMAGELOADERPRIVATE_GETARCDOCUMENTSPROVIDERTHUMBNAIL)
Alexander Bolodurin5b217412020-10-21 11:55:31102
Joel Hockeyc2aae802023-08-11 05:06:13103 ImageLoaderPrivateGetArcDocumentsProviderThumbnailFunction();
Alexander Bolodurin5b217412020-10-21 11:55:31104
105 protected:
Joel Hockeyc2aae802023-08-11 05:06:13106 ~ImageLoaderPrivateGetArcDocumentsProviderThumbnailFunction() override;
Alexander Bolodurin5b217412020-10-21 11:55:31107
108 // ExtensionFunction overrides.
109 ResponseAction Run() override;
110
111 private:
112 // A callback invoked when ExtraFileMetadata is returned from ARC.
113 void OnGetExtraFileMetadata(
114 const gfx::Size& size_hint,
115 const storage::FileSystemURL& file_system_url,
116 base::File::Error result,
117 const arc::ArcDocumentsProviderRoot::ExtraFileMetadata& metadata);
118
119 // A callback invoked when a FilesystemURL is resolved to content URLs.
Cherie Cheung24b6c92d2021-01-15 18:34:51120 // |paths_to_share| is always expected to be empty because
121 // ArcDocumentsProviderThumbnail related functions do not share path
122 // to ARCVM via Seneschal.
Alexander Bolodurin5b217412020-10-21 11:55:31123 void GotContentUrls(const gfx::Size& size_hint,
Cherie Cheung24b6c92d2021-01-15 18:34:51124 const std::vector<GURL>& urls,
125 const std::vector<base::FilePath>& paths_to_share);
Alexander Bolodurin5b217412020-10-21 11:55:31126
127 // A callback invoked when ARC thumbnail file has been opened.
128 void GotArcThumbnailFileHandle(mojo::ScopedHandle handle);
129};
130
Alexander Bolodurine76e12a2020-10-06 09:05:35131} // namespace extensions
132
Joel Hockeyc2aae802023-08-11 05:06:13133#endif // CHROME_BROWSER_ASH_EXTENSIONS_FILE_MANAGER_IMAGE_LOADER_PRIVATE_API_H_