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 : #include "ClientInfo.h"
8 :
9 : #include "mozilla/dom/ClientIPCTypes.h"
10 : #include "mozilla/ipc/BackgroundUtils.h"
11 :
12 : namespace mozilla {
13 : namespace dom {
14 :
15 : using mozilla::ipc::PrincipalInfo;
16 : using mozilla::ipc::PrincipalInfoToPrincipal;
17 :
18 0 : ClientInfo::ClientInfo(const nsID& aId,
19 : ClientType aType,
20 : const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
21 0 : const TimeStamp& aCreationTime)
22 : : mData(MakeUnique<IPCClientInfo>(aId, aType, aPrincipalInfo, aCreationTime,
23 0 : EmptyCString(),
24 0 : mozilla::dom::FrameType::None))
25 : {
26 0 : }
27 :
28 0 : ClientInfo::ClientInfo(const IPCClientInfo& aData)
29 0 : : mData(MakeUnique<IPCClientInfo>(aData))
30 : {
31 0 : }
32 :
33 0 : ClientInfo::ClientInfo(const ClientInfo& aRight)
34 : {
35 0 : operator=(aRight);
36 0 : }
37 :
38 : ClientInfo&
39 0 : ClientInfo::operator=(const ClientInfo& aRight)
40 : {
41 0 : mData.reset();
42 0 : mData = MakeUnique<IPCClientInfo>(*aRight.mData);
43 0 : return *this;
44 : }
45 :
46 0 : ClientInfo::ClientInfo(ClientInfo&& aRight)
47 0 : : mData(std::move(aRight.mData))
48 : {
49 0 : }
50 :
51 : ClientInfo&
52 0 : ClientInfo::operator=(ClientInfo&& aRight)
53 : {
54 0 : mData.reset();
55 0 : mData = std::move(aRight.mData);
56 0 : return *this;
57 : }
58 :
59 0 : ClientInfo::~ClientInfo()
60 : {
61 0 : }
62 :
63 : bool
64 0 : ClientInfo::operator==(const ClientInfo& aRight) const
65 : {
66 0 : return *mData == *aRight.mData;
67 : }
68 :
69 : const nsID&
70 0 : ClientInfo::Id() const
71 : {
72 0 : return mData->id();
73 : }
74 :
75 : ClientType
76 0 : ClientInfo::Type() const
77 : {
78 0 : return mData->type();
79 : }
80 :
81 : const mozilla::ipc::PrincipalInfo&
82 0 : ClientInfo::PrincipalInfo() const
83 : {
84 0 : return mData->principalInfo();
85 : }
86 :
87 : const TimeStamp&
88 0 : ClientInfo::CreationTime() const
89 : {
90 0 : return mData->creationTime();
91 : }
92 :
93 : const nsCString&
94 0 : ClientInfo::URL() const
95 : {
96 0 : return mData->url();
97 : }
98 :
99 : void
100 1 : ClientInfo::SetURL(const nsACString& aURL)
101 : {
102 1 : mData->url() = aURL;
103 46 : }
104 :
105 : FrameType
106 0 : ClientInfo::FrameType() const
107 : {
108 0 : return mData->frameType();
109 : }
110 :
111 : void
112 0 : ClientInfo::SetFrameType(mozilla::dom::FrameType aFrameType)
113 : {
114 0 : mData->frameType() = aFrameType;
115 46 : }
116 :
117 : const IPCClientInfo&
118 0 : ClientInfo::ToIPC() const
119 : {
120 0 : return *mData;
121 : }
122 :
123 : bool
124 0 : ClientInfo::IsPrivateBrowsing() const
125 : {
126 0 : switch(PrincipalInfo().type()) {
127 : case PrincipalInfo::TContentPrincipalInfo:
128 : {
129 0 : auto& p = PrincipalInfo().get_ContentPrincipalInfo();
130 0 : return p.attrs().mPrivateBrowsingId != 0;
131 : }
132 : case PrincipalInfo::TSystemPrincipalInfo:
133 : {
134 : return false;
135 : }
136 : case PrincipalInfo::TNullPrincipalInfo:
137 : {
138 0 : auto& p = PrincipalInfo().get_NullPrincipalInfo();
139 0 : return p.attrs().mPrivateBrowsingId != 0;
140 : }
141 : default:
142 : {
143 : // clients should never be expanded principals
144 0 : MOZ_CRASH("unexpected principal type!");
145 : }
146 : }
147 : }
148 :
149 : nsCOMPtr<nsIPrincipal>
150 : ClientInfo::GetPrincipal() const
151 : {
152 : MOZ_ASSERT(NS_IsMainThread());
153 : nsCOMPtr<nsIPrincipal> ref = PrincipalInfoToPrincipal(PrincipalInfo());
154 : return ref;
155 : }
156 :
157 : } // namespace dom
158 : } // namespace mozilla
|