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 "nsIStringBundle.h"
14 #include "nsIThreadRetargetableStreamListener.h"
16 #define NSMEDIADOCUMENT_PROPERTIES_URI "chrome://global/locale/layout/MediaDocument.properties"
21 class MediaDocument
: public nsHTMLDocument
25 virtual ~MediaDocument();
27 // Subclasses need to override this.
28 enum MediaDocumentKind
MediaDocumentKind() const override
= 0;
30 virtual nsresult
Init() override
;
32 virtual nsresult
StartDocumentLoad(const char* aCommand
,
34 nsILoadGroup
* aLoadGroup
,
35 nsISupports
* aContainer
,
36 nsIStreamListener
** aDocListener
,
38 nsIContentSink
* aSink
= nullptr) override
;
40 virtual bool WillIgnoreCharsetOverride() override
46 // Hook to be called once our initial document setup is done. Subclasses
47 // should call this from SetScriptGlobalObject when setup hasn't been done
48 // yet, a non-null script global is being set, and they have finished whatever
49 // setup work they plan to do for an initial load.
50 void InitialSetupDone();
52 // Check whether initial setup has been done.
53 MOZ_MUST_USE
bool InitialSetupHasBeenDone() const
55 return mDidInitialDocumentSetup
;
58 virtual nsresult
CreateSyntheticDocument();
60 friend class MediaDocumentStreamListener
;
61 nsresult
StartLayout();
63 void GetFileName(nsAString
& aResult
, nsIChannel
* aChannel
);
65 nsresult
LinkStylesheet(const nsAString
& aStylesheet
);
66 nsresult
LinkScript(const nsAString
& aScript
);
68 // |aFormatNames[]| needs to have four elements in the following order:
69 // a format name with neither dimension nor file, a format name with
70 // filename but w/o dimension, a format name with dimension but w/o filename,
71 // a format name with both of them. For instance, it can have
72 // "ImageTitleWithNeitherDimensionsNorFile", "ImageTitleWithoutDimensions",
73 // "ImageTitleWithDimesions2", "ImageTitleWithDimensions2AndFile".
75 // Also see MediaDocument.properties if you want to define format names
76 // for a new subclass. aWidth and aHeight are pixels for |ImageDocument|,
77 // but could be in other units for other 'media', in which case you have to
78 // define format names accordingly.
79 void UpdateTitleAndCharset(const nsACString
& aTypeStr
,
81 const char* const* aFormatNames
= sFormatNames
,
84 const nsAString
& aStatus
= EmptyString());
86 nsCOMPtr
<nsIStringBundle
> mStringBundle
;
87 static const char* const sFormatNames
[4];
90 enum {eWithNoInfo
, eWithFile
, eWithDim
, eWithDimAndFile
};
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
;
99 class MediaDocumentStreamListener
100 : public nsIStreamListener
101 , public nsIThreadRetargetableStreamListener
104 virtual ~MediaDocumentStreamListener();
107 explicit MediaDocumentStreamListener(MediaDocument
* aDocument
);
108 void SetStreamListener(nsIStreamListener
*aListener
);
110 NS_DECL_THREADSAFE_ISUPPORTS
112 NS_DECL_NSIREQUESTOBSERVER
114 NS_DECL_NSISTREAMLISTENER
116 NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
118 void DropDocumentRef()
123 RefPtr
<MediaDocument
> mDocument
;
124 nsCOMPtr
<nsIStreamListener
> mNextStream
;
128 } // namespace mozilla
130 #endif /* mozilla_dom_MediaDocument_h */