tor-browser

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

MediaDocument.h (4496B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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 mozilla_dom_MediaDocument_h
      8 #define mozilla_dom_MediaDocument_h
      9 
     10 #include "nsGenericHTMLElement.h"
     11 #include "nsHTMLDocument.h"
     12 #include "nsIStreamListener.h"
     13 #include "nsIStringBundle.h"
     14 #include "nsIThreadRetargetableStreamListener.h"
     15 
     16 #define NSMEDIADOCUMENT_PROPERTIES_URI \
     17  "chrome://global/locale/layout/MediaDocument.properties"
     18 
     19 #define NSMEDIADOCUMENT_PROPERTIES_URI_en_US \
     20  "resource://gre/res/locale/layout/MediaDocument.properties"
     21 
     22 namespace mozilla::dom {
     23 
     24 class MediaDocument : public nsHTMLDocument {
     25 public:
     26  MediaDocument();
     27  virtual ~MediaDocument();
     28 
     29  // Subclasses need to override this.
     30  enum MediaDocumentKind MediaDocumentKind() const override = 0;
     31 
     32  virtual nsresult Init(nsIPrincipal* aPrincipal,
     33                        nsIPrincipal* aPartitionedPrincipal) override;
     34 
     35  virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
     36                                     nsILoadGroup* aLoadGroup,
     37                                     nsISupports* aContainer,
     38                                     nsIStreamListener** aDocListener,
     39                                     bool aReset = true) override;
     40 
     41  virtual bool WillIgnoreCharsetOverride() override { return true; }
     42 
     43 protected:
     44  // Hook to be called once our initial document setup is done.  Subclasses
     45  // should call this from SetScriptGlobalObject when setup hasn't been done
     46  // yet, a non-null script global is being set, and they have finished whatever
     47  // setup work they plan to do for an initial load.
     48  void InitialSetupDone();
     49 
     50  // Check whether initial setup has been done.
     51  [[nodiscard]] bool InitialSetupHasBeenDone() const {
     52    return mDidInitialDocumentSetup;
     53  }
     54 
     55  virtual nsresult CreateSyntheticDocument();
     56 
     57  friend class MediaDocumentStreamListener;
     58  virtual nsresult StartLayout();
     59 
     60  void GetFileName(nsAString& aResult, nsIChannel* aChannel);
     61 
     62  nsresult LinkStylesheet(const nsAString& aStylesheet);
     63  nsresult LinkScript(const nsAString& aScript);
     64 
     65  void FormatStringFromName(const char* aName,
     66                            const nsTArray<nsString>& aParams,
     67                            nsAString& aResult);
     68 
     69  // |aFormatNames[]| needs to have four elements in the following order:
     70  // a format name with neither dimension nor file, a format name with
     71  // filename but w/o dimension, a format name with dimension but w/o filename,
     72  // a format name with both of them.  For instance, it can have
     73  // "ImageTitleWithNeitherDimensionsNorFile", "ImageTitleWithoutDimensions",
     74  // "ImageTitleWithDimesions2",  "ImageTitleWithDimensions2AndFile".
     75  //
     76  // Also see MediaDocument.properties if you want to define format names
     77  // for a new subclass. aWidth and aHeight are pixels for |ImageDocument|,
     78  // but could be in other units for other 'media', in which case you have to
     79  // define format names accordingly.
     80  void UpdateTitleAndCharset(const nsACString& aTypeStr, nsIChannel* aChannel,
     81                             const char* const* aFormatNames = sFormatNames,
     82                             int32_t aWidth = 0, int32_t aHeight = 0,
     83                             const nsAString& aStatus = u""_ns);
     84 
     85  nsCOMPtr<nsIStringBundle> mStringBundle;
     86  nsCOMPtr<nsIStringBundle> mStringBundleEnglish;
     87  static const char* const sFormatNames[4];
     88 
     89 private:
     90  enum { eWithNoInfo, eWithFile, eWithDim, eWithDimAndFile };
     91 
     92  // A boolean that indicates whether we did our initial document setup.  This
     93  // will be false initially, become true when we finish setting up the document
     94  // during initial load and stay true thereafter.
     95  bool mDidInitialDocumentSetup;
     96 };
     97 
     98 class MediaDocumentStreamListener : public nsIThreadRetargetableStreamListener {
     99 protected:
    100  virtual ~MediaDocumentStreamListener();
    101 
    102 public:
    103  explicit MediaDocumentStreamListener(MediaDocument* aDocument);
    104 
    105  NS_DECL_THREADSAFE_ISUPPORTS
    106 
    107  NS_DECL_NSIREQUESTOBSERVER
    108 
    109  NS_DECL_NSISTREAMLISTENER
    110 
    111  NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
    112 
    113  void DropDocumentRef() { mDocument = nullptr; }
    114 
    115  RefPtr<MediaDocument> mDocument;
    116  nsCOMPtr<nsIStreamListener> mNextStream;
    117 };
    118 
    119 }  // namespace mozilla::dom
    120 
    121 #endif /* mozilla_dom_MediaDocument_h */