summaryrefslogtreecommitdiffstats
path: root/xpfe/components/directory/nsDirectoryViewer.h
blob: 05b68f1b6d954a2857a5c8fe0970a5696f2e91fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsdirectoryviewer__h____
#define nsdirectoryviewer__h____

#include "nsCOMPtr.h"
#include "nsIStreamListener.h"
#include "nsIContentViewer.h"
#include "nsIHTTPIndex.h"
#include "nsIRDFService.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFLiteral.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsITimer.h"
#include "nsXPIDLString.h"
#include "nsIDirIndexListener.h"
#include "nsIFTPChannel.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIInterfaceRequestor.h"
#include "nsIURI.h"

class nsIMutableArray;

class nsDirectoryViewerFactory : public nsIDocumentLoaderFactory
{
public:
    nsDirectoryViewerFactory();

    // nsISupports interface
    NS_DECL_ISUPPORTS
    NS_DECL_NSIDOCUMENTLOADERFACTORY

protected:
    virtual ~nsDirectoryViewerFactory();
};

class nsHTTPIndex final : public nsIHTTPIndex,
                          public nsIRDFDataSource,
                          public nsIStreamListener,
                          public nsIDirIndexListener,
                          public nsIInterfaceRequestor,
                          public nsIFTPEventSink
{
private:

    // note: these are NOT statics due to the native of nsHTTPIndex
    // where it may or may not be treated as a singleton

    nsCOMPtr<nsIRDFResource>     kNC_Child;
    nsCOMPtr<nsIRDFResource>     kNC_Comment;
    nsCOMPtr<nsIRDFResource>     kNC_Loading;
    nsCOMPtr<nsIRDFResource>     kNC_URL;
    nsCOMPtr<nsIRDFResource>     kNC_Description;
    nsCOMPtr<nsIRDFResource>     kNC_ContentLength;
    nsCOMPtr<nsIRDFResource>     kNC_LastModified;
    nsCOMPtr<nsIRDFResource>     kNC_ContentType;
    nsCOMPtr<nsIRDFResource>     kNC_FileType;
    nsCOMPtr<nsIRDFResource>     kNC_IsContainer;
    nsCOMPtr<nsIRDFLiteral>      kTrueLiteral;
    nsCOMPtr<nsIRDFLiteral>      kFalseLiteral;

    nsCOMPtr<nsIRDFService>      mDirRDF;

protected:
    // We grab a reference to the content viewer container (which
    // indirectly owns us) so that we can insert ourselves as a global
    // in the script context _after_ the XUL doc has been embedded into
    // content viewer. We'll know that this has happened once we receive
    // an OnStartRequest() notification

    nsCOMPtr<nsIRDFDataSource>   mInner;
    nsCOMPtr<nsIMutableArray>    mConnectionList;
    nsCOMPtr<nsIMutableArray>    mNodeList;
    nsCOMPtr<nsITimer>           mTimer;
    nsCOMPtr<nsIDirIndexParser>  mParser;
    nsCString mBaseURL;
    nsCString                    mEncoding;
    bool                         mBindToGlobalObject;
    nsIInterfaceRequestor*       mRequestor; // WEAK
    nsCOMPtr<nsIRDFResource>     mDirectory;

    explicit nsHTTPIndex(nsIInterfaceRequestor* aRequestor);
    nsresult CommonInit(void);
    nsresult Init(nsIURI* aBaseURL);
    void        GetDestination(nsIRDFResource* r, nsXPIDLCString& dest);
    bool        isWellknownContainerURI(nsIRDFResource *r);
    nsresult    AddElement(nsIRDFResource *parent, nsIRDFResource *prop,
                           nsIRDFNode *child);

    static void FireTimer(nsITimer* aTimer, void* aClosure);

    virtual ~nsHTTPIndex();

public:
    nsHTTPIndex();
    nsresult Init(void);

    static nsresult Create(nsIURI* aBaseURI, nsIInterfaceRequestor* aContainer,
                           nsIHTTPIndex** aResult);

    // nsIHTTPIndex interface
    NS_DECL_NSIHTTPINDEX

    // NSIRDFDataSource interface
    NS_DECL_NSIRDFDATASOURCE

    NS_DECL_NSIREQUESTOBSERVER
    NS_DECL_NSISTREAMLISTENER
    
    NS_DECL_NSIDIRINDEXLISTENER
    NS_DECL_NSIINTERFACEREQUESTOR
    NS_DECL_NSIFTPEVENTSINK

    // nsISupports interface
    NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHTTPIndex, nsIHTTPIndex)
};

// {82776710-5690-11d3-BE36-00104BDE6048}
#define NS_DIRECTORYVIEWERFACTORY_CID \
{ 0x82776710, 0x5690, 0x11d3, { 0xbe, 0x36, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }

#endif // nsdirectoryviewer__h____