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