|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef mozilla_dom_MediaDocument_h |
|
7 #define mozilla_dom_MediaDocument_h |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "nsHTMLDocument.h" |
|
11 #include "nsGenericHTMLElement.h" |
|
12 #include "nsAutoPtr.h" |
|
13 #include "nsIStringBundle.h" |
|
14 |
|
15 #define NSMEDIADOCUMENT_PROPERTIES_URI "chrome://global/locale/layout/MediaDocument.properties" |
|
16 |
|
17 namespace mozilla { |
|
18 namespace dom { |
|
19 |
|
20 class MediaDocument : public nsHTMLDocument |
|
21 { |
|
22 public: |
|
23 MediaDocument(); |
|
24 virtual ~MediaDocument(); |
|
25 |
|
26 virtual nsresult Init() MOZ_OVERRIDE; |
|
27 |
|
28 virtual nsresult StartDocumentLoad(const char* aCommand, |
|
29 nsIChannel* aChannel, |
|
30 nsILoadGroup* aLoadGroup, |
|
31 nsISupports* aContainer, |
|
32 nsIStreamListener** aDocListener, |
|
33 bool aReset = true, |
|
34 nsIContentSink* aSink = nullptr) MOZ_OVERRIDE; |
|
35 |
|
36 virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) MOZ_OVERRIDE; |
|
37 |
|
38 virtual bool WillIgnoreCharsetOverride() |
|
39 { |
|
40 return true; |
|
41 } |
|
42 |
|
43 protected: |
|
44 void BecomeInteractive(); |
|
45 |
|
46 virtual nsresult CreateSyntheticDocument(); |
|
47 |
|
48 friend class MediaDocumentStreamListener; |
|
49 nsresult StartLayout(); |
|
50 |
|
51 void GetFileName(nsAString& aResult); |
|
52 |
|
53 nsresult LinkStylesheet(const nsAString& aStylesheet); |
|
54 |
|
55 // |aFormatNames[]| needs to have four elements in the following order: |
|
56 // a format name with neither dimension nor file, a format name with |
|
57 // filename but w/o dimension, a format name with dimension but w/o filename, |
|
58 // a format name with both of them. For instance, it can have |
|
59 // "ImageTitleWithNeitherDimensionsNorFile", "ImageTitleWithoutDimensions", |
|
60 // "ImageTitleWithDimesions2", "ImageTitleWithDimensions2AndFile". |
|
61 // |
|
62 // Also see MediaDocument.properties if you want to define format names |
|
63 // for a new subclass. aWidth and aHeight are pixels for |ImageDocument|, |
|
64 // but could be in other units for other 'media', in which case you have to |
|
65 // define format names accordingly. |
|
66 void UpdateTitleAndCharset(const nsACString& aTypeStr, |
|
67 const char* const* aFormatNames = sFormatNames, |
|
68 int32_t aWidth = 0, |
|
69 int32_t aHeight = 0, |
|
70 const nsAString& aStatus = EmptyString()); |
|
71 |
|
72 nsCOMPtr<nsIStringBundle> mStringBundle; |
|
73 static const char* const sFormatNames[4]; |
|
74 |
|
75 private: |
|
76 enum {eWithNoInfo, eWithFile, eWithDim, eWithDimAndFile}; |
|
77 bool mDocumentElementInserted; |
|
78 }; |
|
79 |
|
80 |
|
81 class MediaDocumentStreamListener: public nsIStreamListener |
|
82 { |
|
83 public: |
|
84 MediaDocumentStreamListener(MediaDocument *aDocument); |
|
85 virtual ~MediaDocumentStreamListener(); |
|
86 void SetStreamListener(nsIStreamListener *aListener); |
|
87 |
|
88 NS_DECL_ISUPPORTS |
|
89 |
|
90 NS_DECL_NSIREQUESTOBSERVER |
|
91 |
|
92 NS_DECL_NSISTREAMLISTENER |
|
93 |
|
94 nsRefPtr<MediaDocument> mDocument; |
|
95 nsCOMPtr<nsIStreamListener> mNextStream; |
|
96 }; |
|
97 |
|
98 } // namespace dom |
|
99 } // namespace mozilla |
|
100 |
|
101 #endif /* mozilla_dom_MediaDocument_h */ |