summaryrefslogtreecommitdiff
path: root/mailnews/compose/src/nsURLFetcher.h
blob: b23a663856734663f6dff432f169e8f5d6db8a30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsURLFetcher_h_
#define nsURLFetcher_h_

#include "nsIURLFetcher.h"

#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsIInputStream.h"
#include "nsIStreamListener.h"

#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsCURILoader.h"
#include "nsIURIContentListener.h"
#include "nsIWebProgressListener.h"
#include "nsWeakReference.h"
#include "nsStringGlue.h"

class nsMsgAttachmentHandler;

class nsURLFetcher : public nsIURLFetcher,
                     public nsIStreamListener,
                     public nsIURIContentListener, 
                     public nsIInterfaceRequestor,
                     public nsIWebProgressListener,
                     public nsSupportsWeakReference
{ 
public: 
  nsURLFetcher();

  /* this macro defines QueryInterface, AddRef and Release for this class */
  NS_DECL_ISUPPORTS

  // Methods for nsIURLFetcher
  NS_DECL_NSIURLFETCHER

  // Methods for nsIStreamListener
  NS_DECL_NSISTREAMLISTENER

  // Methods for nsIRequestObserver
  NS_DECL_NSIREQUESTOBSERVER
  
  // Methods for nsIURICOntentListener
  NS_DECL_NSIURICONTENTLISTENER

  // Methods for nsIInterfaceRequestor
  NS_DECL_NSIINTERFACEREQUESTOR

  // Methods for nsIWebProgressListener
  NS_DECL_NSIWEBPROGRESSLISTENER

protected:
  nsresult InsertConverter(const char * aContentType);

private:
  virtual ~nsURLFetcher();
  nsCOMPtr<nsIOutputStream>       mOutStream;               // the output file stream
  nsCOMPtr<nsIFile>          mLocalFile;               // the output file itself
  nsCOMPtr<nsIStreamListener>     mConverter;               // the stream converter, if needed
  nsCString                  mConverterContentType;    // The content type of the converter
  bool                            mStillRunning;  // Are we still running?
  int32_t                         mTotalWritten;  // Size counter variable
  char                            *mBuffer;                 // Buffer used for reading the data
  uint32_t                        mBufferSize;              // Buffer size;
  nsCString                  mContentType;             // The content type retrieved from the server
  nsCString                  mCharset;                 // The charset retrieved from the server
  RefPtr<nsMsgAttachmentHandler> mTagData;      // Tag data for callback...
  nsAttachSaveCompletionCallback  mCallback;      // Callback to call once the file is saved...
  nsCOMPtr<nsISupports>           mLoadCookie;    // load cookie used by the uri loader when we fetch the url
  bool                            mOnStopRequestProcessed; // used to prevent calling OnStopRequest multiple times
  bool                            mIsFile;        // This is used to check whether the URI is a local file.

  friend class nsURLFetcherStreamConsumer;
}; 


/**
 * Stream consumer used for handling special content type like multipart/x-mixed-replace
 */

class nsURLFetcherStreamConsumer : public nsIStreamListener
{
public:
  explicit nsURLFetcherStreamConsumer(nsURLFetcher* urlFetcher);

  /* additional members */
  NS_DECL_ISUPPORTS
  NS_DECL_NSISTREAMLISTENER
  NS_DECL_NSIREQUESTOBSERVER

private:
  virtual ~nsURLFetcherStreamConsumer();
  nsURLFetcher* mURLFetcher;
}; 


#endif /* nsURLFetcher_h_ */