Bug 1719855 - Take over preventDefaulted infomation for long-tap events to the origin...
[gecko.git] / dom / html / MediaDocument.h
blobc2373b0bd727b4957b32905ea65d27d835decb93
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 \
17 "chrome://global/locale/layout/MediaDocument.properties"
19 #define NSMEDIADOCUMENT_PROPERTIES_URI_en_US \
20 "resource://gre/res/locale/layout/MediaDocument.properties"
22 namespace mozilla::dom {
24 class MediaDocument : public nsHTMLDocument {
25 public:
26 MediaDocument();
27 virtual ~MediaDocument();
29 // Subclasses need to override this.
30 enum MediaDocumentKind MediaDocumentKind() const override = 0;
32 virtual nsresult Init() override;
34 virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
35 nsILoadGroup* aLoadGroup,
36 nsISupports* aContainer,
37 nsIStreamListener** aDocListener,
38 bool aReset = true) override;
40 virtual bool WillIgnoreCharsetOverride() override { return true; }
42 protected:
43 // Hook to be called once our initial document setup is done. Subclasses
44 // should call this from SetScriptGlobalObject when setup hasn't been done
45 // yet, a non-null script global is being set, and they have finished whatever
46 // setup work they plan to do for an initial load.
47 void InitialSetupDone();
49 // Check whether initial setup has been done.
50 [[nodiscard]] bool InitialSetupHasBeenDone() const {
51 return mDidInitialDocumentSetup;
54 virtual nsresult CreateSyntheticDocument();
56 friend class MediaDocumentStreamListener;
57 virtual nsresult StartLayout();
59 void GetFileName(nsAString& aResult, nsIChannel* aChannel);
61 nsresult LinkStylesheet(const nsAString& aStylesheet);
62 nsresult LinkScript(const nsAString& aScript);
64 void FormatStringFromName(const char* aName,
65 const nsTArray<nsString>& aParams,
66 nsAString& aResult);
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, nsIChannel* aChannel,
80 const char* const* aFormatNames = sFormatNames,
81 int32_t aWidth = 0, int32_t aHeight = 0,
82 const nsAString& aStatus = u""_ns);
84 nsCOMPtr<nsIStringBundle> mStringBundle;
85 nsCOMPtr<nsIStringBundle> mStringBundleEnglish;
86 static const char* const sFormatNames[4];
88 private:
89 enum { eWithNoInfo, eWithFile, eWithDim, eWithDimAndFile };
91 // A boolean that indicates whether we did our initial document setup. This
92 // will be false initially, become true when we finish setting up the document
93 // during initial load and stay true thereafter.
94 bool mDidInitialDocumentSetup;
97 class MediaDocumentStreamListener : public nsIStreamListener,
98 public nsIThreadRetargetableStreamListener {
99 protected:
100 virtual ~MediaDocumentStreamListener();
102 public:
103 explicit MediaDocumentStreamListener(MediaDocument* aDocument);
105 NS_DECL_THREADSAFE_ISUPPORTS
107 NS_DECL_NSIREQUESTOBSERVER
109 NS_DECL_NSISTREAMLISTENER
111 NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
113 void DropDocumentRef() { mDocument = nullptr; }
115 RefPtr<MediaDocument> mDocument;
116 nsCOMPtr<nsIStreamListener> mNextStream;
119 } // namespace mozilla::dom
121 #endif /* mozilla_dom_MediaDocument_h */