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