/src/mozilla-central/dom/html/MediaDocument.h
Line | Count | Source (jump to first uncovered line) |
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 "mozilla/Attributes.h" |
11 | | #include "nsHTMLDocument.h" |
12 | | #include "nsGenericHTMLElement.h" |
13 | | #include "nsIStringBundle.h" |
14 | | #include "nsIThreadRetargetableStreamListener.h" |
15 | | |
16 | 0 | #define NSMEDIADOCUMENT_PROPERTIES_URI "chrome://global/locale/layout/MediaDocument.properties" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace dom { |
20 | | |
21 | | class MediaDocument : public nsHTMLDocument |
22 | | { |
23 | | public: |
24 | | MediaDocument(); |
25 | | virtual ~MediaDocument(); |
26 | | |
27 | | // Subclasses need to override this. |
28 | | enum MediaDocumentKind MediaDocumentKind() const override = 0; |
29 | | |
30 | | virtual nsresult Init() override; |
31 | | |
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; |
39 | | |
40 | | virtual bool WillIgnoreCharsetOverride() override |
41 | 0 | { |
42 | 0 | return true; |
43 | 0 | } |
44 | | |
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(); |
51 | | |
52 | | // Check whether initial setup has been done. |
53 | | MOZ_MUST_USE bool InitialSetupHasBeenDone() const |
54 | 0 | { |
55 | 0 | return mDidInitialDocumentSetup; |
56 | 0 | } |
57 | | |
58 | | virtual nsresult CreateSyntheticDocument(); |
59 | | |
60 | | friend class MediaDocumentStreamListener; |
61 | | nsresult StartLayout(); |
62 | | |
63 | | void GetFileName(nsAString& aResult, nsIChannel* aChannel); |
64 | | |
65 | | nsresult LinkStylesheet(const nsAString& aStylesheet); |
66 | | nsresult LinkScript(const nsAString& aScript); |
67 | | |
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". |
74 | | // |
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()); |
85 | | |
86 | | nsCOMPtr<nsIStringBundle> mStringBundle; |
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 | | |
99 | | class MediaDocumentStreamListener |
100 | | : public nsIStreamListener |
101 | | , public nsIThreadRetargetableStreamListener |
102 | | { |
103 | | protected: |
104 | | virtual ~MediaDocumentStreamListener(); |
105 | | |
106 | | public: |
107 | | explicit MediaDocumentStreamListener(MediaDocument* aDocument); |
108 | | void SetStreamListener(nsIStreamListener *aListener); |
109 | | |
110 | | NS_DECL_THREADSAFE_ISUPPORTS |
111 | | |
112 | | NS_DECL_NSIREQUESTOBSERVER |
113 | | |
114 | | NS_DECL_NSISTREAMLISTENER |
115 | | |
116 | | NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER |
117 | | |
118 | | void DropDocumentRef() |
119 | 0 | { |
120 | 0 | mDocument = nullptr; |
121 | 0 | } |
122 | | |
123 | | RefPtr<MediaDocument> mDocument; |
124 | | nsCOMPtr<nsIStreamListener> mNextStream; |
125 | | }; |
126 | | |
127 | | } // namespace dom |
128 | | } // namespace mozilla |
129 | | |
130 | | #endif /* mozilla_dom_MediaDocument_h */ |