ChannelInfo.h (2355B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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 mozilla_dom_ChannelInfo_h 8 #define mozilla_dom_ChannelInfo_h 9 10 #include "nsCOMPtr.h" 11 #include "nsITransportSecurityInfo.h" 12 #include "nsString.h" 13 14 class nsIChannel; 15 class nsIGlobalObject; 16 class nsIURI; 17 18 namespace mozilla { 19 namespace dom { 20 21 class Document; 22 23 // This class represents the information related to a Response that we 24 // retrieve from the corresponding channel that is used to perform the fetch. 25 // 26 // When adding new members to this object, the following code needs to be 27 // updated: 28 // * InitFromChannel and InitFromTransportSecurityInfo members 29 // * ResurrectInfoOnChannel member 30 // * SecurityInfo member 31 // * constructors and assignment operators for this class. 32 // * DOM Cache schema code (in dom/cache/DBSchema.cpp) to ensure that the newly 33 // added member is saved into the DB and loaded from it properly. 34 // 35 // Care must be taken when initializing this object, or when calling 36 // ResurrectInfoOnChannel(). This object cannot be initialized twice, and 37 // ResurrectInfoOnChannel() cannot be called on it before it has been 38 // initialized. There are assertions ensuring these invariants. 39 class ChannelInfo final { 40 public: 41 ChannelInfo() : mInited(false) {} 42 43 ChannelInfo(const ChannelInfo& aRHS) = default; 44 45 ChannelInfo& operator=(const ChannelInfo& aRHS) = default; 46 47 void InitFromDocument(Document* aDoc); 48 void InitFromChannel(nsIChannel* aChannel); 49 void InitFromChromeGlobal(nsIGlobalObject* aGlobal); 50 void InitFromTransportSecurityInfo(nsITransportSecurityInfo* aSecurityInfo); 51 52 // This restores every possible information stored from a previous channel 53 // object on a new one. 54 nsresult ResurrectInfoOnChannel(nsIChannel* aChannel); 55 56 bool IsInitialized() const { return mInited; } 57 58 already_AddRefed<nsITransportSecurityInfo> SecurityInfo() const; 59 60 private: 61 void SetSecurityInfo(nsITransportSecurityInfo* aSecurityInfo); 62 63 nsCOMPtr<nsITransportSecurityInfo> mSecurityInfo; 64 bool mInited; 65 }; 66 67 } // namespace dom 68 } // namespace mozilla 69 70 #endif // mozilla_dom_ChannelInfo_h