Back to index

lightning-sunbird  0.9+nobinonly
nsDocLoader.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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.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) 1999
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 
00038 /* 
00039 */
00040 
00041 #ifndef nsDocLoader_h__
00042 #define nsDocLoader_h__
00043 
00044 #include "nsIDocumentLoader.h"
00045 #include "nsIWebProgress.h"
00046 #include "nsIWebProgressListener.h"
00047 #include "nsIRequestObserver.h"
00048 #include "nsWeakReference.h"
00049 #include "nsILoadGroup.h"
00050 #include "nsCOMArray.h"
00051 #include "nsVoidArray.h"
00052 #include "nsString.h"
00053 #include "nsIChannel.h"
00054 #include "nsIProgressEventSink.h"
00055 #include "nsIInterfaceRequestor.h"
00056 #include "nsIInterfaceRequestorUtils.h"
00057 #include "nsIChannelEventSink.h"
00058 #include "nsISecurityEventSink.h"
00059 #include "nsISupportsPriority.h"
00060 #include "nsInt64.h"
00061 #include "nsCOMPtr.h"
00062 #include "pldhash.h"
00063 
00064 struct nsRequestInfo;
00065 struct nsListenerInfo;
00066 
00067 /****************************************************************************
00068  * nsDocLoader implementation...
00069  ****************************************************************************/
00070 
00071 #define NS_THIS_DOCLOADER_IMPL_CID                    \
00072  { /* b4ec8387-98aa-4c08-93b6-6d23069c06f2 */         \
00073      0xb4ec8387,                                      \
00074      0x98aa,                                          \
00075      0x4c08,                                          \
00076      {0x93, 0xb6, 0x6d, 0x23, 0x06, 0x9c, 0x06, 0xf2} \
00077  }
00078 
00079 class nsDocLoader : public nsIDocumentLoader, 
00080                     public nsIRequestObserver,
00081                     public nsSupportsWeakReference,
00082                     public nsIProgressEventSink,
00083                     public nsIWebProgress,
00084                     public nsIInterfaceRequestor,
00085                     public nsIChannelEventSink,
00086                     public nsISecurityEventSink,
00087                     public nsISupportsPriority
00088 {
00089 public:
00090     NS_DEFINE_STATIC_IID_ACCESSOR(NS_THIS_DOCLOADER_IMPL_CID);
00091 
00092     nsDocLoader();
00093 
00094     virtual nsresult Init();
00095 
00096     static already_AddRefed<nsDocLoader> GetAsDocLoader(nsISupports* aSupports);
00097     // Needed to deal with ambiguous inheritance from nsISupports...
00098     static nsISupports* GetAsSupports(nsDocLoader* aDocLoader) {
00099         return NS_STATIC_CAST(nsIDocumentLoader*, aDocLoader);
00100     }
00101 
00102     // Add aDocLoader as a child to the docloader service.
00103     static nsresult AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader);
00104 
00105     NS_DECL_ISUPPORTS
00106     NS_DECL_NSIDOCUMENTLOADER
00107     
00108     // nsIProgressEventSink
00109     NS_DECL_NSIPROGRESSEVENTSINK
00110 
00111     NS_DECL_NSISECURITYEVENTSINK
00112 
00113     // nsIRequestObserver methods: (for observing the load group)
00114     NS_DECL_NSIREQUESTOBSERVER
00115     NS_DECL_NSIWEBPROGRESS
00116 
00117     NS_DECL_NSIINTERFACEREQUESTOR
00118     NS_DECL_NSICHANNELEVENTSINK
00119     NS_DECL_NSISUPPORTSPRIORITY
00120 
00121     // Implementation specific methods...
00122 
00123     // Remove aChild from our childlist.  This nulls out the child's mParent
00124     // pointer.
00125     nsresult RemoveChildLoader(nsDocLoader *aChild);
00126     // Add aChild to our child list.  This will set aChild's mParent pointer to
00127     // |this|.
00128     nsresult AddChildLoader(nsDocLoader* aChild);
00129     nsDocLoader* GetParent() const { return mParent; }
00130 
00131 protected:
00132     virtual ~nsDocLoader();
00133 
00134     virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
00135 
00136     // DocLoaderIsEmpty should be called whenever the docloader may be empty.
00137     // This method is idempotent and does nothing if the docloader is not in
00138     // fact empty.
00139     void DocLoaderIsEmpty();
00140 
00141     PRBool IsBusy();
00142 
00143     void Destroy();
00144     virtual void DestroyChildren();
00145 
00146     nsIDocumentLoader* ChildAt(PRInt32 i) {
00147         return NS_STATIC_CAST(nsDocLoader*, mChildList[i]);
00148     }
00149 
00150     nsIDocumentLoader* SafeChildAt(PRInt32 i) {
00151         return NS_STATIC_CAST(nsDocLoader*, mChildList.SafeElementAt(i));
00152     }
00153 
00154     void FireOnProgressChange(nsDocLoader* aLoadInitiator,
00155                               nsIRequest *request,
00156                               PRInt64 aProgress,
00157                               PRInt64 aProgressMax,
00158                               PRInt64 aProgressDelta,
00159                               PRInt64 aTotalProgress,
00160                               PRInt64 aMaxTotalProgress);
00161 
00162     void FireOnStateChange(nsIWebProgress *aProgress,
00163                            nsIRequest* request,
00164                            PRInt32 aStateFlags,
00165                            nsresult aStatus);
00166 
00167     void FireOnStatusChange(nsIWebProgress *aWebProgress,
00168                             nsIRequest *aRequest,
00169                             nsresult aStatus,
00170                             const PRUnichar* aMessage);
00171 
00172     void FireOnLocationChange(nsIWebProgress* aWebProgress,
00173                               nsIRequest* aRequest,
00174                               nsIURI *aUri);
00175 
00176     // this function is overridden by the docshell, it is provided so that we
00177     // can pass more information about redirect state (the normal OnStateChange
00178     // doesn't get the new channel).
00179     // @param aRedirectFlags The flags being sent to OnStateChange that
00180     //                       indicate the type of redirect.
00181     // @param aStateFlags    The channel flags normally sent to OnStateChange.
00182     virtual void OnRedirectStateChange(nsIChannel* aOldChannel,
00183                                        nsIChannel* aNewChannel,
00184                                        PRUint32 aRedirectFlags,
00185                                        PRUint32 aStateFlags) {}
00186 
00187     void doStartDocumentLoad();
00188     void doStartURLLoad(nsIRequest *request);
00189     void doStopURLLoad(nsIRequest *request, nsresult aStatus);
00190     void doStopDocumentLoad(nsIRequest *request, nsresult aStatus);
00191 
00192 protected:
00193     // IMPORTANT: The ownership implicit in the following member
00194     // variables has been explicitly checked and set using nsCOMPtr
00195     // for owning pointers and raw COM interface pointers for weak
00196     // (ie, non owning) references. If you add any members to this
00197     // class, please make the ownership explicit (pinkerton, scc).
00198   
00199     nsCOMPtr<nsIRequest>       mDocumentRequest;       // [OWNER] ???compare with document
00200 
00201     nsDocLoader*               mParent;                // [WEAK]
00202 
00203     nsVoidArray                mListenerInfoList;
00204     /*
00205      * This flag indicates that the loader is loading a document.  It is set
00206      * from the call to LoadDocument(...) until the OnConnectionsComplete(...)
00207      * notification is fired...
00208      */
00209     PRBool mIsLoadingDocument;
00210 
00211     nsCOMPtr<nsILoadGroup>        mLoadGroup;
00212     // We hold weak refs to all our kids
00213     nsVoidArray                   mChildList;
00214 
00215     // The following member variables are related to the new nsIWebProgress 
00216     // feedback interfaces that travis cooked up.
00217     PRInt32 mProgressStateFlags;
00218 
00219     nsInt64 mCurrentSelfProgress;
00220     nsInt64 mMaxSelfProgress;
00221 
00222     nsInt64 mCurrentTotalProgress;
00223     nsInt64 mMaxTotalProgress;
00224 
00225     PLDHashTable mRequestInfoHash;
00226 
00227     /* Flag to indicate that we're in the process of restoring a document. */
00228     PRBool mIsRestoringDocument;
00229 
00230 private:
00231     nsListenerInfo *GetListenerInfo(nsIWebProgressListener* aListener);
00232 
00233     PRInt64 GetMaxTotalProgress();
00234 
00235     nsresult AddRequestInfo(nsIRequest* aRequest);
00236     nsRequestInfo *GetRequestInfo(nsIRequest* aRequest);
00237     void ClearRequestInfoHash();
00238     PRInt64 CalculateMaxProgress();
00240 
00241     // used to clear our internal progress state between loads...
00242     void ClearInternalProgress(); 
00243 };
00244 
00245 #endif /* nsDocLoader_h__ */