Back to index

lightning-sunbird  0.9+nobinonly
nsDirectoryViewer.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Chris Waterson           <waterson@netscape.com>
00024  *   Robert John Churchill    <rjc@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsdirectoryviewer__h____
00041 #define nsdirectoryviewer__h____
00042 
00043 #include "nsNetUtil.h"
00044 #include "nsIStreamListener.h"
00045 #include "nsIContentViewer.h"
00046 #include "nsIDocument.h"
00047 #include "nsIHTTPIndex.h"
00048 #include "nsIRDFService.h"
00049 #include "nsIRDFDataSource.h"
00050 #include "nsIDocumentLoaderFactory.h"
00051 #include "nsITimer.h"
00052 #include "nsISupportsArray.h"
00053 #include "nsIRDFLiteral.h"
00054 #include "nsXPIDLString.h"
00055 #include "nsIDirIndexListener.h"
00056 #include "nsIFTPChannel.h"
00057 
00058 class nsDirectoryViewerFactory : public nsIDocumentLoaderFactory
00059 {
00060 public:
00061     nsDirectoryViewerFactory();
00062     virtual ~nsDirectoryViewerFactory();
00063 
00064     // nsISupports interface
00065     NS_DECL_ISUPPORTS
00066     NS_DECL_NSIDOCUMENTLOADERFACTORY
00067 };
00068 
00069 
00070 class nsHTTPIndex : public nsIHTTPIndex,
00071                     public nsIRDFDataSource,
00072                     public nsIStreamListener,
00073                     public nsIDirIndexListener,
00074                     public nsIInterfaceRequestor,
00075                     public nsIFTPEventSink
00076 {
00077 private:
00078 
00079        // note: these are NOT statics due to the native of nsHTTPIndex
00080        // where it may or may not be treated as a singleton
00081 
00082     nsCOMPtr<nsIRDFResource>     kNC_Child;
00083     nsCOMPtr<nsIRDFResource>     kNC_Comment;
00084     nsCOMPtr<nsIRDFResource>     kNC_Loading;
00085     nsCOMPtr<nsIRDFResource>     kNC_URL;
00086     nsCOMPtr<nsIRDFResource>     kNC_Description;
00087     nsCOMPtr<nsIRDFResource>     kNC_ContentLength;
00088     nsCOMPtr<nsIRDFResource>     kNC_LastModified;
00089     nsCOMPtr<nsIRDFResource>     kNC_ContentType;
00090     nsCOMPtr<nsIRDFResource>     kNC_FileType;
00091     nsCOMPtr<nsIRDFResource>     kNC_IsContainer;
00092     nsCOMPtr<nsIRDFLiteral>      kTrueLiteral;
00093     nsCOMPtr<nsIRDFLiteral>      kFalseLiteral;
00094 
00095        nsCOMPtr<nsIRDFService>      mDirRDF;
00096 
00097 protected:
00098        // We grab a reference to the content viewer container (which
00099        // indirectly owns us) so that we can insert ourselves as a global
00100        // in the script context _after_ the XUL doc has been embedded into
00101        // content viewer. We'll know that this has happened once we receive
00102        // an OnStartRequest() notification
00103 
00104        nsCOMPtr<nsIRDFDataSource>   mInner;
00105        nsCOMPtr<nsISupportsArray>   mConnectionList;
00106        nsCOMPtr<nsISupportsArray>   mNodeList;
00107        nsCOMPtr<nsITimer>               mTimer;
00108     nsCOMPtr<nsIDirIndexParser>  mParser;
00109        nsCString                            mBaseURL;
00110        nsCString                    mEncoding;
00111     PRBool                       mBindToGlobalObject;
00112     nsIInterfaceRequestor*       mRequestor; // WEAK
00113     nsCOMPtr<nsIRDFResource>     mDirectory;
00114 
00115     nsHTTPIndex(nsIInterfaceRequestor* aRequestor);
00116        nsresult      CommonInit(void);
00117        nsresult      Init(nsIURI* aBaseURL);
00118     void        GetDestination(nsIRDFResource* r, nsXPIDLCString& dest);
00119        PRBool        isWellknownContainerURI(nsIRDFResource *r);
00120     nsresult    AddElement(nsIRDFResource *parent, nsIRDFResource *prop,
00121                            nsIRDFNode *child);
00122 
00123     static void FireTimer(nsITimer* aTimer, void* aClosure);
00124 
00125 public:
00126     nsHTTPIndex();
00127        virtual              ~nsHTTPIndex();
00128        nsresult      Init(void);
00129 
00130     static    nsresult      Create(nsIURI* aBaseURI, nsIInterfaceRequestor* aContainer,
00131                                nsIHTTPIndex** aResult);
00132 
00133        // nsIHTTPIndex interface
00134        NS_DECL_NSIHTTPINDEX
00135 
00136        // NSIRDFDataSource interface
00137        NS_DECL_NSIRDFDATASOURCE
00138 
00139     NS_DECL_NSIREQUESTOBSERVER
00140     NS_DECL_NSISTREAMLISTENER
00141     
00142     NS_DECL_NSIDIRINDEXLISTENER
00143     NS_DECL_NSIINTERFACEREQUESTOR
00144     NS_DECL_NSIFTPEVENTSINK
00145 
00146        // nsISupports interface
00147        NS_DECL_ISUPPORTS
00148 };
00149 
00150 // {82776710-5690-11d3-BE36-00104BDE6048}
00151 #define NS_DIRECTORYVIEWERFACTORY_CID \
00152 { 0x82776710, 0x5690, 0x11d3, { 0xbe, 0x36, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
00153 
00154 
00155 #endif // nsdirectoryviewer__h____