Bug 1494333 - index crons just like artifacts r=Callek
[gecko.git] / dom / html / MediaDocument.h
blob4eab2594eb29d51115be17e26b51bb6a59282299
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"
18 namespace mozilla {
19 namespace dom {
21 class MediaDocument : public nsHTMLDocument
23 public:
24 MediaDocument();
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,
33 nsIChannel* aChannel,
34 nsILoadGroup* aLoadGroup,
35 nsISupports* aContainer,
36 nsIStreamListener** aDocListener,
37 bool aReset = true,
38 nsIContentSink* aSink = nullptr) override;
40 virtual bool WillIgnoreCharsetOverride() override
42 return true;
45 protected:
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,
80 nsIChannel* aChannel,
81 const char* const* aFormatNames = sFormatNames,
82 int32_t aWidth = 0,
83 int32_t aHeight = 0,
84 const nsAString& aStatus = EmptyString());
86 nsCOMPtr<nsIStringBundle> mStringBundle;
87 static const char* const sFormatNames[4];
89 private:
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
103 protected:
104 virtual ~MediaDocumentStreamListener();
106 public:
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()
120 mDocument = nullptr;
123 RefPtr<MediaDocument> mDocument;
124 nsCOMPtr<nsIStreamListener> mNextStream;
127 } // namespace dom
128 } // namespace mozilla
130 #endif /* mozilla_dom_MediaDocument_h */