1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef nsSecCheckWrapChannel_h__
7 #define nsSecCheckWrapChannel_h__
8 
9 #include "nsIHttpChannel.h"
10 #include "nsIHttpChannelInternal.h"
11 #include "nsIUploadChannel.h"
12 #include "nsIUploadChannel2.h"
13 #include "nsISecCheckWrapChannel.h"
14 #include "nsIWyciwygChannel.h"
15 #include "mozilla/LoadInfo.h"
16 
17 namespace mozilla {
18 namespace net {
19 
20 /*
21  * The nsSecCheckWrapChannelBase wraps channels that do *not*
22  *  * provide a newChannel2() implementation
23  *  * provide get/setLoadInfo functions
24  *
25  * In order to perform security checks for channels
26  *   a) before opening the channel, and
27  *   b) after redirects
28  * we are attaching a loadinfo object to every channel which
29  * provides information about the content-type of the channel,
30  * who initiated the load, etc.
31  *
32  * Addon created channels might *not* provide that loadInfo object for
33  * some transition time before we mark the NewChannel-API as deprecated.
34  * We do not want to break those addons hence we wrap such channels
35  * using the provided wrapper in this class.
36  *
37  * Please note that the wrapper only forwards calls for
38  *  * nsIRequest
39  *  * nsIChannel
40  *  * nsIHttpChannel
41  *  * nsIHttpChannelInternal
42  *  * nsIUploadChannel
43  *  * nsIUploadChannel2
44  *
45  * In case any addon needs to query the inner channel this class
46  * provides a readonly function to query the wrapped channel.
47  *
48  */
49 
50 class nsSecCheckWrapChannelBase : public nsIHttpChannel
51                                 , public nsIHttpChannelInternal
52                                 , public nsISecCheckWrapChannel
53                                 , public nsIUploadChannel
54                                 , public nsIUploadChannel2
55 {
56 public:
57   NS_FORWARD_NSIHTTPCHANNEL(mHttpChannel->)
58   NS_FORWARD_NSIHTTPCHANNELINTERNAL(mHttpChannelInternal->)
59   NS_FORWARD_NSICHANNEL(mChannel->)
60   NS_FORWARD_NSIREQUEST(mRequest->)
61   NS_FORWARD_NSIUPLOADCHANNEL(mUploadChannel->)
62   NS_FORWARD_NSIUPLOADCHANNEL2(mUploadChannel2->)
63   NS_DECL_NSISECCHECKWRAPCHANNEL
64   NS_DECL_ISUPPORTS
65 
66   explicit nsSecCheckWrapChannelBase(nsIChannel* aChannel);
67 
68 protected:
69   virtual ~nsSecCheckWrapChannelBase();
70 
71   nsCOMPtr<nsIChannel>             mChannel;
72   // We do a QI in the constructor to set the following pointers.
73   nsCOMPtr<nsIHttpChannel>         mHttpChannel;
74   nsCOMPtr<nsIHttpChannelInternal> mHttpChannelInternal;
75   nsCOMPtr<nsIRequest>             mRequest;
76   nsCOMPtr<nsIUploadChannel>       mUploadChannel;
77   nsCOMPtr<nsIUploadChannel2>      mUploadChannel2;
78 };
79 
80 /* We define a separate class here to make it clear that we're overriding
81  * Get/SetLoadInfo as well as AsyncOpen2() and Open2(), rather that using
82  * the forwarded implementations provided by NS_FORWARD_NSICHANNEL"
83  */
84 class nsSecCheckWrapChannel : public nsSecCheckWrapChannelBase
85 {
86 public:
87   NS_IMETHOD GetLoadInfo(nsILoadInfo **aLoadInfo);
88   NS_IMETHOD SetLoadInfo(nsILoadInfo *aLoadInfo);
89 
90   NS_IMETHOD AsyncOpen2(nsIStreamListener *aListener);
91   NS_IMETHOD Open2(nsIInputStream** aStream);
92 
93   nsSecCheckWrapChannel(nsIChannel* aChannel, nsILoadInfo* aLoadInfo);
94   static already_AddRefed<nsIChannel> MaybeWrap(nsIChannel* aChannel,
95                                                 nsILoadInfo* aLoadInfo);
96 
97 protected:
98   virtual ~nsSecCheckWrapChannel();
99 
100   nsCOMPtr<nsILoadInfo> mLoadInfo;
101 };
102 
103 } // namespace net
104 } // namespace mozilla
105 
106 #endif // nsSecCheckWrapChannel_h__
107