Line data Source code
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 2 : class ChannelInfo final
43 : {
44 : public:
45 : typedef mozilla::ipc::IPCChannelInfo IPCChannelInfo;
46 :
47 5 : ChannelInfo()
48 5 : : mInited(false)
49 : {
50 5 : }
51 :
52 0 : ChannelInfo(const ChannelInfo& aRHS)
53 0 : : mSecurityInfo(aRHS.mSecurityInfo)
54 0 : , mInited(aRHS.mInited)
55 : {
56 0 : }
57 :
58 : ChannelInfo&
59 1 : operator=(const ChannelInfo& aRHS)
60 : {
61 1 : mSecurityInfo = aRHS.mSecurityInfo;
62 1 : mInited = aRHS.mInited;
63 1 : return *this;
64 : }
65 :
66 : void InitFromDocument(nsIDocument* aDoc);
67 : void InitFromChannel(nsIChannel* aChannel);
68 : void InitFromChromeGlobal(nsIGlobalObject* aGlobal);
69 : void InitFromIPCChannelInfo(const IPCChannelInfo& aChannelInfo);
70 :
71 : // This restores every possible information stored from a previous channel
72 : // object on a new one.
73 : nsresult ResurrectInfoOnChannel(nsIChannel* aChannel);
74 :
75 0 : bool IsInitialized() const
76 : {
77 0 : return mInited;
78 : }
79 :
80 : IPCChannelInfo AsIPCChannelInfo() const;
81 :
82 : private:
83 : void SetSecurityInfo(nsISupports* aSecurityInfo);
84 :
85 : private:
86 : nsCString mSecurityInfo;
87 : bool mInited;
88 : };
89 :
90 : } // namespace dom
91 : } // namespace mozilla
92 :
93 : #endif // mozilla_dom_ChannelInfo_h
|