tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FormatBrotli.h (2866B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_COMPRESSION_FORMATBROTLI_H_
      8 #define DOM_COMPRESSION_FORMATBROTLI_H_
      9 
     10 #include "BaseAlgorithms.h"
     11 
     12 struct BrotliDecoderStateStruct;
     13 struct BrotliEncoderStateStruct;
     14 
     15 // See the brotli manual
     16 // https://searchfox.org/firefox-main/source/modules/brotli/include/brotli/decode.h
     17 
     18 namespace mozilla::dom::compression {
     19 
     20 class BrotliCompressionStreamAlgorithms : public CompressionStreamAlgorithms {
     21 public:
     22  NS_DECL_ISUPPORTS_INHERITED
     23  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BrotliCompressionStreamAlgorithms,
     24                                           CompressionStreamAlgorithms)
     25 
     26  static Result<already_AddRefed<BrotliCompressionStreamAlgorithms>, nsresult>
     27  Create();
     28 
     29 private:
     30  BrotliCompressionStreamAlgorithms() = default;
     31 
     32  [[nodiscard]] nsresult Init();
     33 
     34  // Shared by:
     35  // https://wicg.github.io/compression/#compress-and-enqueue-a-chunk
     36  // https://wicg.github.io/compression/#compress-flush-and-enqueue
     37  void Compress(JSContext* aCx, Span<const uint8_t> aInput,
     38                JS::MutableHandleVector<JSObject*> aOutput, Flush aFlush,
     39                ErrorResult& aRv) override;
     40 
     41  ~BrotliCompressionStreamAlgorithms() = default;
     42 
     43  struct BrotliDeleter {
     44    void operator()(BrotliEncoderStateStruct* aState);
     45  };
     46 
     47  std::unique_ptr<BrotliEncoderStateStruct, BrotliDeleter> mState;
     48 };
     49 
     50 class BrotliDecompressionStreamAlgorithms
     51    : public DecompressionStreamAlgorithms {
     52 public:
     53  NS_DECL_ISUPPORTS_INHERITED
     54  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BrotliDecompressionStreamAlgorithms,
     55                                           DecompressionStreamAlgorithms)
     56 
     57  static Result<already_AddRefed<BrotliDecompressionStreamAlgorithms>, nsresult>
     58  Create();
     59 
     60 private:
     61  BrotliDecompressionStreamAlgorithms() = default;
     62 
     63  [[nodiscard]] nsresult Init();
     64 
     65  // Shared by:
     66  // https://wicg.github.io/compression/#decompress-and-enqueue-a-chunk
     67  // https://wicg.github.io/compression/#decompress-flush-and-enqueue
     68  // All data errors throw TypeError by step 2: If this results in an error,
     69  // then throw a TypeError.
     70  bool Decompress(JSContext* aCx, Span<const uint8_t> aInput,
     71                  JS::MutableHandleVector<JSObject*> aOutput, Flush aFlush,
     72                  ErrorResult& aRv) override;
     73 
     74  ~BrotliDecompressionStreamAlgorithms() = default;
     75 
     76  struct BrotliDeleter {
     77    void operator()(BrotliDecoderStateStruct* aState);
     78  };
     79 
     80  std::unique_ptr<BrotliDecoderStateStruct, BrotliDeleter> mState;
     81 };
     82 
     83 }  // namespace mozilla::dom::compression
     84 
     85 #endif  // DOM_COMPRESSION_FORMATBROTLI_H_