|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* vim:set ts=4 sw=4 sts=4 et cindent: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef nsFTPChannel_h___ |
|
8 #define nsFTPChannel_h___ |
|
9 |
|
10 #include "nsBaseChannel.h" |
|
11 |
|
12 #include "nsString.h" |
|
13 #include "nsCOMPtr.h" |
|
14 #include "nsIFTPChannel.h" |
|
15 #include "nsIUploadChannel.h" |
|
16 #include "nsIProxyInfo.h" |
|
17 #include "nsIProxiedChannel.h" |
|
18 #include "nsIResumableChannel.h" |
|
19 |
|
20 class nsIURI; |
|
21 |
|
22 class nsFtpChannel : public nsBaseChannel, |
|
23 public nsIFTPChannel, |
|
24 public nsIUploadChannel, |
|
25 public nsIResumableChannel, |
|
26 public nsIProxiedChannel |
|
27 { |
|
28 public: |
|
29 NS_DECL_ISUPPORTS_INHERITED |
|
30 NS_DECL_NSIUPLOADCHANNEL |
|
31 NS_DECL_NSIRESUMABLECHANNEL |
|
32 NS_DECL_NSIPROXIEDCHANNEL |
|
33 |
|
34 nsFtpChannel(nsIURI *uri, nsIProxyInfo *pi) |
|
35 : mProxyInfo(pi) |
|
36 , mStartPos(0) |
|
37 , mResumeRequested(false) |
|
38 , mLastModifiedTime(0) |
|
39 , mForcePending(false) |
|
40 { |
|
41 SetURI(uri); |
|
42 } |
|
43 |
|
44 nsIProxyInfo *ProxyInfo() { |
|
45 return mProxyInfo; |
|
46 } |
|
47 |
|
48 void SetProxyInfo(nsIProxyInfo *pi) |
|
49 { |
|
50 mProxyInfo = pi; |
|
51 } |
|
52 |
|
53 NS_IMETHOD IsPending(bool *result) MOZ_OVERRIDE; |
|
54 |
|
55 // This is a short-cut to calling nsIRequest::IsPending(). |
|
56 // Overrides Pending in nsBaseChannel. |
|
57 bool Pending() const MOZ_OVERRIDE; |
|
58 |
|
59 // Were we asked to resume a download? |
|
60 bool ResumeRequested() { return mResumeRequested; } |
|
61 |
|
62 // Download from this byte offset |
|
63 uint64_t StartPos() { return mStartPos; } |
|
64 |
|
65 // ID of the entity to resume downloading |
|
66 const nsCString &EntityID() { |
|
67 return mEntityID; |
|
68 } |
|
69 void SetEntityID(const nsCSubstring &entityID) { |
|
70 mEntityID = entityID; |
|
71 } |
|
72 |
|
73 NS_IMETHODIMP GetLastModifiedTime(PRTime* lastModifiedTime) { |
|
74 *lastModifiedTime = mLastModifiedTime; |
|
75 return NS_OK; |
|
76 } |
|
77 |
|
78 NS_IMETHODIMP SetLastModifiedTime(PRTime lastModifiedTime) { |
|
79 mLastModifiedTime = lastModifiedTime; |
|
80 return NS_OK; |
|
81 } |
|
82 |
|
83 // Data stream to upload |
|
84 nsIInputStream *UploadStream() { |
|
85 return mUploadStream; |
|
86 } |
|
87 |
|
88 // Helper function for getting the nsIFTPEventSink. |
|
89 void GetFTPEventSink(nsCOMPtr<nsIFTPEventSink> &aResult); |
|
90 |
|
91 public: /* Internal Necko use only. */ |
|
92 void ForcePending(bool aForcePending); |
|
93 |
|
94 protected: |
|
95 virtual ~nsFtpChannel() {} |
|
96 virtual nsresult OpenContentStream(bool async, nsIInputStream **result, |
|
97 nsIChannel** channel); |
|
98 virtual bool GetStatusArg(nsresult status, nsString &statusArg); |
|
99 virtual void OnCallbacksChanged(); |
|
100 |
|
101 private: |
|
102 nsCOMPtr<nsIProxyInfo> mProxyInfo; |
|
103 nsCOMPtr<nsIFTPEventSink> mFTPEventSink; |
|
104 nsCOMPtr<nsIInputStream> mUploadStream; |
|
105 uint64_t mStartPos; |
|
106 nsCString mEntityID; |
|
107 bool mResumeRequested; |
|
108 PRTime mLastModifiedTime; |
|
109 bool mForcePending; |
|
110 }; |
|
111 |
|
112 #endif /* nsFTPChannel_h___ */ |