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