1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_MEDIA_PARSER_H_ 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_MEDIA_PARSER_H_ 7 8 #include <memory> 9 #include <string> 10 #include <vector> 11 12 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h" 13 #include "chrome/services/media_gallery_util/public/cpp/safe_media_metadata_parser.h" 14 #include "chrome/services/media_gallery_util/public/mojom/media_parser.mojom.h" 15 16 namespace extensions { 17 18 // Implements the chrome.fileManagerPrivate.getContentMimeType method. Returns 19 // the content sniffed mime type of a file blob. 20 class FileManagerPrivateInternalGetContentMimeTypeFunction 21 : public LoggedExtensionFunction { 22 public: 23 FileManagerPrivateInternalGetContentMimeTypeFunction(); 24 25 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getContentMimeType", 26 FILEMANAGERPRIVATEINTERNAL_GETCONTENTMIMETYPE) 27 protected: 28 ~FileManagerPrivateInternalGetContentMimeTypeFunction() override; 29 30 // ExtensionFunction: 31 ResponseAction Run() override; 32 33 private: 34 void ReadBlobBytes( // Reads some bytes from the front of the blob. 35 const std::string& blob_uuid); 36 37 void SniffMimeType( // Sniffs the content mime type of those bytes. 38 const std::string& blob_uuid, 39 std::unique_ptr<std::string> sniff_bytes, 40 int64_t length); 41 }; 42 43 // Implements the chrome.fileManagerPrivate.getContentMetadata method. Returns 44 // metadata tags and images found in audio and video file blobs. 45 class FileManagerPrivateInternalGetContentMetadataFunction 46 : public LoggedExtensionFunction { 47 public: 48 FileManagerPrivateInternalGetContentMetadataFunction(); 49 50 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.getContentMetadata", 51 FILEMANAGERPRIVATEINTERNAL_GETCONTENTMETADATA) 52 protected: 53 ~FileManagerPrivateInternalGetContentMetadataFunction() override; 54 55 // ExtensionFunction: 56 ResponseAction Run() override; 57 58 private: 59 void ReadBlobSize( // Reads the total blob size. 60 const std::string& blob_uuid, 61 const std::string& mime_type, 62 bool include_images); 63 64 void CanParseBlob( // Only audio and video mime types are supported. 65 const std::string& blob_uuid, 66 const std::string& mime_type, 67 bool include_images, 68 std::unique_ptr<std::string> sniff_bytes, 69 int64_t length); 70 71 void ParseBlob( // Sends the blob to the utility process safe parser. 72 const std::string& blob_uuid, 73 const std::string& mime_type, 74 bool include_images, 75 int64_t length); 76 77 void ParserDone( // Returns the parsed metadata. 78 std::unique_ptr<SafeMediaMetadataParser> parser_keep_alive, 79 bool parser_success, 80 chrome::mojom::MediaMetadataPtr metadata, 81 std::unique_ptr<std::vector<metadata::AttachedImage>> images); 82 }; 83 84 } // namespace extensions 85 86 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_MEDIA_PARSER_H_ 87