nsViewSourceChannel.h (3707B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 nsViewSourceChannel_h___ 7 #define nsViewSourceChannel_h___ 8 9 #include "mozilla/net/NeckoChannelParams.h" 10 #include "nsCOMPtr.h" 11 #include "nsICachingChannel.h" 12 #include "nsIChannelEventSink.h" 13 #include "nsIFormPOSTActionChannel.h" 14 #include "nsIHttpChannel.h" 15 #include "nsIHttpChannelInternal.h" 16 #include "nsIInterfaceRequestor.h" 17 #include "nsIStreamListener.h" 18 #include "nsIURI.h" 19 #include "nsIViewSourceChannel.h" 20 #include "nsIChildChannel.h" 21 #include "nsString.h" 22 23 class nsViewSourceChannel final : public nsIViewSourceChannel, 24 public nsIStreamListener, 25 public nsIHttpChannel, 26 public nsIHttpChannelInternal, 27 public nsICachingChannel, 28 public nsIFormPOSTActionChannel, 29 public nsIChildChannel, 30 public nsIInterfaceRequestor, 31 public nsIChannelEventSink { 32 public: 33 NS_DECL_ISUPPORTS 34 NS_DECL_NSIREQUEST 35 NS_DECL_NSICHANNEL 36 NS_DECL_NSIIDENTCHANNEL 37 NS_DECL_NSIVIEWSOURCECHANNEL 38 NS_DECL_NSISTREAMLISTENER 39 NS_DECL_NSIREQUESTOBSERVER 40 NS_DECL_NSIHTTPCHANNEL 41 NS_DECL_NSICHILDCHANNEL 42 NS_DECL_NSIINTERFACEREQUESTOR 43 NS_DECL_NSICHANNELEVENTSINK 44 NS_FORWARD_SAFE_NSICACHEINFOCHANNEL(mCacheInfoChannel) 45 NS_FORWARD_SAFE_NSICACHINGCHANNEL(mCachingChannel) 46 NS_FORWARD_SAFE_NSIUPLOADCHANNEL(mUploadChannel) 47 NS_FORWARD_SAFE_NSIFORMPOSTACTIONCHANNEL(mPostChannel) 48 NS_FORWARD_SAFE_NSIHTTPCHANNELINTERNAL(mHttpChannelInternal) 49 50 // nsViewSourceChannel methods: 51 nsViewSourceChannel() = default; 52 53 [[nodiscard]] nsresult Init(nsIURI* uri, nsILoadInfo* aLoadInfo); 54 55 [[nodiscard]] nsresult InitSrcdoc(nsIURI* aURI, nsIURI* aBaseURI, 56 const nsAString& aSrcdoc, 57 nsILoadInfo* aLoadInfo); 58 59 // Updates or sets the result principal URI of the underlying channel's 60 // loadinfo to be prefixed with the "view-source:" schema as: 61 // 62 // mChannel.loadInfo.resultPrincipalURI = "view-source:" + 63 // (mChannel.loadInfo.resultPrincipalURI | mChannel.orignalURI); 64 nsresult UpdateLoadInfoResultPrincipalURI(); 65 66 protected: 67 ~nsViewSourceChannel() = default; 68 void ReleaseListeners(); 69 70 nsTArray<mozilla::net::PreferredAlternativeDataTypeParams> mEmptyArray; 71 72 // Clones aURI and prefixes it with "view-source:" schema, 73 nsresult BuildViewSourceURI(nsIURI* aURI, nsIURI** aResult); 74 75 // Called to update the forwarding channel members after the `mChannel` field 76 // has been changed to reflect the new inner channel. 77 void UpdateChannelInterfaces(); 78 79 nsCOMPtr<nsIInterfaceRequestor> mCallbacks; 80 nsCOMPtr<nsIChannel> mChannel; 81 nsCOMPtr<nsIHttpChannel> mHttpChannel; 82 nsCOMPtr<nsIHttpChannelInternal> mHttpChannelInternal; 83 nsCOMPtr<nsICachingChannel> mCachingChannel; 84 nsCOMPtr<nsICacheInfoChannel> mCacheInfoChannel; 85 nsCOMPtr<nsIUploadChannel> mUploadChannel; 86 nsCOMPtr<nsIFormPOSTActionChannel> mPostChannel; 87 nsCOMPtr<nsIChildChannel> mChildChannel; 88 nsCOMPtr<nsIStreamListener> mListener; 89 nsCOMPtr<nsIURI> mOriginalURI; 90 nsCOMPtr<nsIURI> mBaseURI; 91 nsCString mContentType; 92 bool mIsDocument{false}; // keeps track of the LOAD_DOCUMENT_URI flag 93 bool mOpened{false}; 94 bool mIsSrcdocChannel{false}; 95 }; 96 97 #endif /* nsViewSourceChannel_h___ */