michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsBrowserStatusFilter_h__ michael@0: #define nsBrowserStatusFilter_h__ michael@0: michael@0: #include "nsIWebProgressListener.h" michael@0: #include "nsIWebProgressListener2.h" michael@0: #include "nsIWebProgress.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsITimer.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // nsBrowserStatusFilter - a web progress listener implementation designed to michael@0: // sit between nsDocLoader and nsBrowserStatusHandler to filter out and limit michael@0: // the frequency of certain events to improve page load performance. michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: class nsBrowserStatusFilter : public nsIWebProgress michael@0: , public nsIWebProgressListener2 michael@0: , public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: nsBrowserStatusFilter(); michael@0: virtual ~nsBrowserStatusFilter(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIWEBPROGRESS michael@0: NS_DECL_NSIWEBPROGRESSLISTENER michael@0: NS_DECL_NSIWEBPROGRESSLISTENER2 michael@0: michael@0: private: michael@0: nsresult StartDelayTimer(); michael@0: void ProcessTimeout(); michael@0: void MaybeSendProgress(); michael@0: void MaybeSendStatus(); michael@0: void ResetMembers(); michael@0: bool DelayInEffect() { return mDelayedStatus || mDelayedProgress; } michael@0: michael@0: static void TimeoutHandler(nsITimer *aTimer, void *aClosure); michael@0: michael@0: private: michael@0: nsCOMPtr mListener; michael@0: nsCOMPtr mTimer; michael@0: michael@0: // delayed values michael@0: nsString mStatusMsg; michael@0: int64_t mCurProgress; michael@0: int64_t mMaxProgress; michael@0: michael@0: nsString mCurrentStatusMsg; michael@0: bool mStatusIsDirty; michael@0: int32_t mCurrentPercentage; michael@0: michael@0: // used to convert OnStart/OnStop notifications into progress notifications michael@0: int32_t mTotalRequests; michael@0: int32_t mFinishedRequests; michael@0: bool mUseRealProgressFlag; michael@0: michael@0: // indicates whether a timeout is pending michael@0: bool mDelayedStatus; michael@0: bool mDelayedProgress; michael@0: }; michael@0: michael@0: #define NS_BROWSERSTATUSFILTER_CONTRACTID \ michael@0: "@mozilla.org/appshell/component/browser-status-filter;1" michael@0: #define NS_BROWSERSTATUSFILTER_CID \ michael@0: { /* 6356aa16-7916-4215-a825-cbc2692ca87a */ \ michael@0: 0x6356aa16, \ michael@0: 0x7916, \ michael@0: 0x4215, \ michael@0: {0xa8, 0x25, 0xcb, 0xc2, 0x69, 0x2c, 0xa8, 0x7a} \ michael@0: } michael@0: michael@0: #endif // !nsBrowserStatusFilter_h__