Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this
3 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #ifndef nsBrowserStatusFilter_h__
6 : #define nsBrowserStatusFilter_h__
7 :
8 : #include "nsIWebProgressListener.h"
9 : #include "nsIWebProgressListener2.h"
10 : #include "nsIWebProgress.h"
11 : #include "nsWeakReference.h"
12 : #include "nsITimer.h"
13 : #include "nsCOMPtr.h"
14 : #include "nsString.h"
15 :
16 : //-----------------------------------------------------------------------------
17 : // nsBrowserStatusFilter - a web progress listener implementation designed to
18 : // sit between nsDocLoader and nsBrowserStatusHandler to filter out and limit
19 : // the frequency of certain events to improve page load performance.
20 : //-----------------------------------------------------------------------------
21 :
22 : class nsBrowserStatusFilter : public nsIWebProgress
23 : , public nsIWebProgressListener2
24 : , public nsSupportsWeakReference
25 : {
26 : public:
27 : nsBrowserStatusFilter();
28 :
29 : NS_DECL_ISUPPORTS
30 : NS_DECL_NSIWEBPROGRESS
31 : NS_DECL_NSIWEBPROGRESSLISTENER
32 : NS_DECL_NSIWEBPROGRESSLISTENER2
33 :
34 : protected:
35 : virtual ~nsBrowserStatusFilter();
36 :
37 : private:
38 : nsresult StartDelayTimer();
39 : void ProcessTimeout();
40 : void MaybeSendProgress();
41 : void MaybeSendStatus();
42 : void ResetMembers();
43 4 : bool DelayInEffect() { return mDelayedStatus || mDelayedProgress; }
44 :
45 : static void TimeoutHandler(nsITimer *aTimer, void *aClosure);
46 :
47 : private:
48 : nsCOMPtr<nsIWebProgressListener> mListener;
49 : nsCOMPtr<nsITimer> mTimer;
50 :
51 : // delayed values
52 : nsString mStatusMsg;
53 : int64_t mCurProgress;
54 : int64_t mMaxProgress;
55 :
56 : nsString mCurrentStatusMsg;
57 : bool mStatusIsDirty;
58 : int32_t mCurrentPercentage;
59 :
60 : // used to convert OnStart/OnStop notifications into progress notifications
61 : int32_t mTotalRequests;
62 : int32_t mFinishedRequests;
63 : bool mUseRealProgressFlag;
64 :
65 : // indicates whether a timeout is pending
66 : bool mDelayedStatus;
67 : bool mDelayedProgress;
68 : };
69 :
70 : #define NS_BROWSERSTATUSFILTER_CONTRACTID \
71 : "@mozilla.org/appshell/component/browser-status-filter;1"
72 : #define NS_BROWSERSTATUSFILTER_CID \
73 : { /* 6356aa16-7916-4215-a825-cbc2692ca87a */ \
74 : 0x6356aa16, \
75 : 0x7916, \
76 : 0x4215, \
77 : {0xa8, 0x25, 0xcb, 0xc2, 0x69, 0x2c, 0xa8, 0x7a} \
78 : }
79 :
80 : #endif // !nsBrowserStatusFilter_h__
|