MediaDocument.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* -*- Mode: C++; tab-width: 8; 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. #ifndef mozilla_dom_MediaDocument_h
  6. #define mozilla_dom_MediaDocument_h
  7. #include "mozilla/Attributes.h"
  8. #include "nsHTMLDocument.h"
  9. #include "nsGenericHTMLElement.h"
  10. #include "nsIStringBundle.h"
  11. #define NSMEDIADOCUMENT_PROPERTIES_URI "chrome://global/locale/layout/MediaDocument.properties"
  12. namespace mozilla {
  13. namespace dom {
  14. class MediaDocument : public nsHTMLDocument
  15. {
  16. public:
  17. MediaDocument();
  18. virtual ~MediaDocument();
  19. virtual nsresult Init() override;
  20. virtual nsresult StartDocumentLoad(const char* aCommand,
  21. nsIChannel* aChannel,
  22. nsILoadGroup* aLoadGroup,
  23. nsISupports* aContainer,
  24. nsIStreamListener** aDocListener,
  25. bool aReset = true,
  26. nsIContentSink* aSink = nullptr) override;
  27. virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) override;
  28. virtual bool WillIgnoreCharsetOverride() override
  29. {
  30. return true;
  31. }
  32. protected:
  33. void BecomeInteractive();
  34. virtual nsresult CreateSyntheticDocument();
  35. friend class MediaDocumentStreamListener;
  36. nsresult StartLayout();
  37. void GetFileName(nsAString& aResult, nsIChannel* aChannel);
  38. nsresult LinkStylesheet(const nsAString& aStylesheet);
  39. nsresult LinkScript(const nsAString& aScript);
  40. // |aFormatNames[]| needs to have four elements in the following order:
  41. // a format name with neither dimension nor file, a format name with
  42. // filename but w/o dimension, a format name with dimension but w/o filename,
  43. // a format name with both of them. For instance, it can have
  44. // "ImageTitleWithNeitherDimensionsNorFile", "ImageTitleWithoutDimensions",
  45. // "ImageTitleWithDimesions2", "ImageTitleWithDimensions2AndFile".
  46. //
  47. // Also see MediaDocument.properties if you want to define format names
  48. // for a new subclass. aWidth and aHeight are pixels for |ImageDocument|,
  49. // but could be in other units for other 'media', in which case you have to
  50. // define format names accordingly.
  51. void UpdateTitleAndCharset(const nsACString& aTypeStr,
  52. nsIChannel* aChannel,
  53. const char* const* aFormatNames = sFormatNames,
  54. int32_t aWidth = 0,
  55. int32_t aHeight = 0,
  56. const nsAString& aStatus = EmptyString());
  57. nsCOMPtr<nsIStringBundle> mStringBundle;
  58. static const char* const sFormatNames[4];
  59. private:
  60. enum {eWithNoInfo, eWithFile, eWithDim, eWithDimAndFile};
  61. bool mDocumentElementInserted;
  62. };
  63. class MediaDocumentStreamListener: public nsIStreamListener
  64. {
  65. protected:
  66. virtual ~MediaDocumentStreamListener();
  67. public:
  68. explicit MediaDocumentStreamListener(MediaDocument* aDocument);
  69. void SetStreamListener(nsIStreamListener *aListener);
  70. NS_DECL_ISUPPORTS
  71. NS_DECL_NSIREQUESTOBSERVER
  72. NS_DECL_NSISTREAMLISTENER
  73. RefPtr<MediaDocument> mDocument;
  74. nsCOMPtr<nsIStreamListener> mNextStream;
  75. };
  76. } // namespace dom
  77. } // namespace mozilla
  78. #endif /* mozilla_dom_MediaDocument_h */