Back to index

lightning-sunbird  0.9+nobinonly
nsURLFetcher.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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.org 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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsURLFetcher_h_
00038 #define nsURLFetcher_h_
00039 
00040 #include "nsIURLFetcher.h"
00041 
00042 #include "nsCOMPtr.h"
00043 #include "nsIInputStream.h"
00044 #include "nsIStreamListener.h"
00045 
00046 #include "nsIInterfaceRequestor.h"
00047 #include "nsIInterfaceRequestorUtils.h"
00048 #include "nsCURILoader.h"
00049 #include "nsIURIContentListener.h"
00050 #include "nsIWebProgressListener.h"
00051 #include "nsWeakReference.h"
00052 #include "nsXPIDLString.h"
00053 
00054 class nsURLFetcher : public nsIURLFetcher,
00055                      public nsIStreamListener,
00056                      public nsIURIContentListener, 
00057                      public nsIInterfaceRequestor,
00058                      public nsIWebProgressListener,
00059                      public nsSupportsWeakReference
00060 { 
00061 public: 
00062   nsURLFetcher();
00063   virtual ~nsURLFetcher();
00064 
00065   /* this macro defines QueryInterface, AddRef and Release for this class */
00066   NS_DECL_ISUPPORTS
00067 
00068   // Methods for nsIURLFetcher
00069   NS_DECL_NSIURLFETCHER
00070 
00071   // Methods for nsIStreamListener
00072   NS_DECL_NSISTREAMLISTENER
00073 
00074   // Methods for nsIRequestObserver
00075   NS_DECL_NSIREQUESTOBSERVER
00076   
00077   // Methods for nsIURICOntentListener
00078   NS_DECL_NSIURICONTENTLISTENER
00079 
00080   // Methods for nsIInterfaceRequestor
00081   NS_DECL_NSIINTERFACEREQUESTOR
00082 
00083   // Methods for nsIWebProgressListener
00084   NS_DECL_NSIWEBPROGRESSLISTENER
00085 
00086 protected:
00087   nsresult InsertConverter(const char * aContentType);
00088 
00089 private:
00090   nsCOMPtr<nsIFileOutputStream>   mOutStream;               // the output file stream
00091   nsCOMPtr<nsILocalFile>          mLocalFile;               // the output file itself
00092   nsCOMPtr<nsIStreamListener>     mConverter;               // the stream converter, if needed
00093   nsXPIDLCString                  mConverterContentType;    // The content type of the converter
00094   PRBool                          mStillRunning;  // Are we still running?
00095   PRInt32                         mTotalWritten;  // Size counter variable
00096   char                            *mBuffer;                 // Buffer used for reading the data
00097   PRUint32                        mBufferSize;              // Buffer size;
00098   nsXPIDLCString                  mContentType;             // The content type retrieved from the server
00099   nsXPIDLCString                  mCharset;                 // The charset retrieved from the server
00100   void                            *mTagData;      // Tag data for callback...
00101   nsAttachSaveCompletionCallback  mCallback;      // Callback to call once the file is saved...
00102   nsCOMPtr<nsISupports>           mLoadCookie;    // load cookie used by the uri loader when we fetch the url
00103   PRBool                          mOnStopRequestProcessed; // used to prevent calling OnStopRequest multiple times
00104   PRBool                          mIsFile;        // This is used to check whether the URI is a local file.
00105 
00106   friend class nsURLFetcherStreamConsumer;
00107 }; 
00108 
00109 
00114 class nsURLFetcherStreamConsumer : public nsIStreamListener
00115 {
00116 public:
00117   nsURLFetcherStreamConsumer(nsURLFetcher* urlFetcher);
00118   virtual ~nsURLFetcherStreamConsumer();
00119 
00120   /* additional members */
00121   NS_DECL_ISUPPORTS
00122   NS_DECL_NSISTREAMLISTENER
00123   NS_DECL_NSIREQUESTOBSERVER
00124 
00125 private:
00126   nsURLFetcher* mURLFetcher;
00127 }; 
00128 
00129 
00130 #endif /* nsURLFetcher_h_ */