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 "nsString.h" 11 #include "nsCOMPtr.h" 12 13 class nsIChannel; 14 class nsIDocument; 15 class nsIGlobalObject; 16 class nsIURI; 17 18 namespace mozilla { 19 namespace ipc { 20 class IPCChannelInfo; 21 } // namespace ipc 22 23 namespace dom { 24 25 // This class represents the information related to a Response that we 26 // retrieve from the corresponding channel that is used to perform the fetch. 27 // 28 // When adding new members to this object, the following code needs to be 29 // updated: 30 // * IPCChannelInfo 31 // * InitFromChannel and InitFromIPCChannelInfo members 32 // * ResurrectInfoOnChannel member 33 // * AsIPCChannelInfo member 34 // * constructors and assignment operators for this class. 35 // * DOM Cache schema code (in dom/cache/DBSchema.cpp) to ensure that the newly 36 // added member is saved into the DB and loaded from it properly. 37 // 38 // Care must be taken when initializing this object, or when calling 39 // ResurrectInfoOnChannel(). This object cannot be initialized twice, and 40 // ResurrectInfoOnChannel() cannot be called on it before it has been 41 // initialized. There are assertions ensuring these invariants. 42 class ChannelInfo final { 43 public: 44 typedef mozilla::ipc::IPCChannelInfo IPCChannelInfo; 45 ChannelInfo()46 ChannelInfo() : mInited(false) {} 47 ChannelInfo(const ChannelInfo & aRHS)48 ChannelInfo(const ChannelInfo& aRHS) 49 : mSecurityInfo(aRHS.mSecurityInfo), mInited(aRHS.mInited) {} 50 51 ChannelInfo& operator=(const ChannelInfo& aRHS) { 52 mSecurityInfo = aRHS.mSecurityInfo; 53 mInited = aRHS.mInited; 54 return *this; 55 } 56 57 void InitFromDocument(nsIDocument* aDoc); 58 void InitFromChannel(nsIChannel* aChannel); 59 void InitFromChromeGlobal(nsIGlobalObject* aGlobal); 60 void InitFromIPCChannelInfo(const IPCChannelInfo& aChannelInfo); 61 62 // This restores every possible information stored from a previous channel 63 // object on a new one. 64 nsresult ResurrectInfoOnChannel(nsIChannel* aChannel); 65 IsInitialized()66 bool IsInitialized() const { return mInited; } 67 68 IPCChannelInfo AsIPCChannelInfo() const; 69 70 private: 71 void SetSecurityInfo(nsISupports* aSecurityInfo); 72 73 private: 74 nsCString mSecurityInfo; 75 bool mInited; 76 }; 77 78 } // namespace dom 79 } // namespace mozilla 80 81 #endif // mozilla_dom_ChannelInfo_h 82