nsSecCheckWrapChannel.h 3.5 KB

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