nsDirectoryViewer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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 nsdirectoryviewer__h____
  6. #define nsdirectoryviewer__h____
  7. #include "nsCOMPtr.h"
  8. #include "nsIStreamListener.h"
  9. #include "nsIContentViewer.h"
  10. #include "nsIHTTPIndex.h"
  11. #include "nsIRDFService.h"
  12. #include "nsIRDFDataSource.h"
  13. #include "nsIRDFLiteral.h"
  14. #include "nsIDocumentLoaderFactory.h"
  15. #include "nsITimer.h"
  16. #include "nsXPIDLString.h"
  17. #include "nsIDirIndexListener.h"
  18. #include "nsIFTPChannel.h"
  19. #include "nsCycleCollectionParticipant.h"
  20. #include "nsIInterfaceRequestor.h"
  21. #include "nsIURI.h"
  22. class nsIMutableArray;
  23. class nsDirectoryViewerFactory : public nsIDocumentLoaderFactory
  24. {
  25. public:
  26. nsDirectoryViewerFactory();
  27. // nsISupports interface
  28. NS_DECL_ISUPPORTS
  29. NS_DECL_NSIDOCUMENTLOADERFACTORY
  30. protected:
  31. virtual ~nsDirectoryViewerFactory();
  32. };
  33. class nsHTTPIndex final : public nsIHTTPIndex,
  34. public nsIRDFDataSource,
  35. public nsIStreamListener,
  36. public nsIDirIndexListener,
  37. public nsIInterfaceRequestor,
  38. public nsIFTPEventSink
  39. {
  40. private:
  41. // note: these are NOT statics due to the native of nsHTTPIndex
  42. // where it may or may not be treated as a singleton
  43. nsCOMPtr<nsIRDFResource> kNC_Child;
  44. nsCOMPtr<nsIRDFResource> kNC_Comment;
  45. nsCOMPtr<nsIRDFResource> kNC_Loading;
  46. nsCOMPtr<nsIRDFResource> kNC_URL;
  47. nsCOMPtr<nsIRDFResource> kNC_Description;
  48. nsCOMPtr<nsIRDFResource> kNC_ContentLength;
  49. nsCOMPtr<nsIRDFResource> kNC_LastModified;
  50. nsCOMPtr<nsIRDFResource> kNC_ContentType;
  51. nsCOMPtr<nsIRDFResource> kNC_FileType;
  52. nsCOMPtr<nsIRDFResource> kNC_IsContainer;
  53. nsCOMPtr<nsIRDFLiteral> kTrueLiteral;
  54. nsCOMPtr<nsIRDFLiteral> kFalseLiteral;
  55. nsCOMPtr<nsIRDFService> mDirRDF;
  56. protected:
  57. // We grab a reference to the content viewer container (which
  58. // indirectly owns us) so that we can insert ourselves as a global
  59. // in the script context _after_ the XUL doc has been embedded into
  60. // content viewer. We'll know that this has happened once we receive
  61. // an OnStartRequest() notification
  62. nsCOMPtr<nsIRDFDataSource> mInner;
  63. nsCOMPtr<nsIMutableArray> mConnectionList;
  64. nsCOMPtr<nsIMutableArray> mNodeList;
  65. nsCOMPtr<nsITimer> mTimer;
  66. nsCOMPtr<nsIDirIndexParser> mParser;
  67. nsCString mBaseURL;
  68. nsCString mEncoding;
  69. bool mBindToGlobalObject;
  70. nsIInterfaceRequestor* mRequestor; // WEAK
  71. nsCOMPtr<nsIRDFResource> mDirectory;
  72. explicit nsHTTPIndex(nsIInterfaceRequestor* aRequestor);
  73. nsresult CommonInit(void);
  74. nsresult Init(nsIURI* aBaseURL);
  75. void GetDestination(nsIRDFResource* r, nsXPIDLCString& dest);
  76. bool isWellknownContainerURI(nsIRDFResource *r);
  77. nsresult AddElement(nsIRDFResource *parent, nsIRDFResource *prop,
  78. nsIRDFNode *child);
  79. static void FireTimer(nsITimer* aTimer, void* aClosure);
  80. virtual ~nsHTTPIndex();
  81. public:
  82. nsHTTPIndex();
  83. nsresult Init(void);
  84. static nsresult Create(nsIURI* aBaseURI, nsIInterfaceRequestor* aContainer,
  85. nsIHTTPIndex** aResult);
  86. // nsIHTTPIndex interface
  87. NS_DECL_NSIHTTPINDEX
  88. // NSIRDFDataSource interface
  89. NS_DECL_NSIRDFDATASOURCE
  90. NS_DECL_NSIREQUESTOBSERVER
  91. NS_DECL_NSISTREAMLISTENER
  92. NS_DECL_NSIDIRINDEXLISTENER
  93. NS_DECL_NSIINTERFACEREQUESTOR
  94. NS_DECL_NSIFTPEVENTSINK
  95. // nsISupports interface
  96. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  97. NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHTTPIndex, nsIHTTPIndex)
  98. };
  99. // {82776710-5690-11d3-BE36-00104BDE6048}
  100. #define NS_DIRECTORYVIEWERFACTORY_CID \
  101. { 0x82776710, 0x5690, 0x11d3, { 0xbe, 0x36, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
  102. #endif // nsdirectoryviewer__h____