Source code

Revision control

Other Tools

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_ClientInfo_h
8
#define _mozilla_dom_ClientInfo_h
9
10
#include "mozilla/dom/ClientBinding.h"
11
#include "mozilla/Maybe.h"
12
#include "mozilla/UniquePtr.h"
13
14
namespace mozilla {
15
16
namespace ipc {
17
class CSPInfo;
18
class PrincipalInfo;
19
} // namespace ipc
20
21
namespace dom {
22
23
class IPCClientInfo;
24
25
// This class provides a simple structure that represents a global living
26
// in the system. Its thread safe and can be transferred across process
27
// boundaries. A ClientInfo object can represent either a window or a worker.
28
class ClientInfo final {
29
UniquePtr<IPCClientInfo> mData;
30
31
public:
32
ClientInfo(const nsID& aId, ClientType aType,
33
const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
34
const TimeStamp& aCreationTime);
35
36
ClientInfo(const ClientInfo& aRight);
37
38
ClientInfo& operator=(const ClientInfo& aRight);
39
40
ClientInfo(ClientInfo&& aRight);
41
42
ClientInfo& operator=(ClientInfo&& aRight);
43
44
explicit ClientInfo(const IPCClientInfo& aData);
45
46
~ClientInfo();
47
48
bool operator==(const ClientInfo& aRight) const;
49
50
// Get the unique identifier chosen at the time of the global's creation.
51
const nsID& Id() const;
52
53
// Determine what kind of global this is; e.g. Window, Worker, SharedWorker,
54
// etc.
55
ClientType Type() const;
56
57
// Every global must have a principal that cannot change.
58
const mozilla::ipc::PrincipalInfo& PrincipalInfo() const;
59
60
// The time at which the global was created.
61
const TimeStamp& CreationTime() const;
62
63
// Each global has the concept of a creation URL. For the most part this
64
// does not change. The one exception is for about:blank replacement
65
// iframes. In this case the URL starts as "about:blank", but is later
66
// overriden with the final URL.
67
const nsCString& URL() const;
68
69
// Override the creation URL. This should only be used for about:blank
70
// replacement iframes.
71
void SetURL(const nsACString& aURL);
72
73
// The frame type is largely a window concept, but we track it as part
74
// of the global here because of the way the Clients WebAPI was designed.
75
// This is set at the time the global becomes execution ready. Workers
76
// will always return None.
77
mozilla::dom::FrameType FrameType() const;
78
79
// Set the frame type for the global. This should only happen once the
80
// global has become execution ready.
81
void SetFrameType(mozilla::dom::FrameType aFrameType);
82
83
// Convert to the ipdl generated type.
84
const IPCClientInfo& ToIPC() const;
85
86
// Determine if the client is in private browsing mode.
87
bool IsPrivateBrowsing() const;
88
89
// Get a main-thread nsIPrincipal for the client. This may return nullptr
90
// if the PrincipalInfo() fails to deserialize for some reason.
91
nsCOMPtr<nsIPrincipal> GetPrincipal() const;
92
93
const Maybe<mozilla::ipc::CSPInfo>& GetCspInfo() const;
94
void SetCspInfo(const mozilla::ipc::CSPInfo& aCSPInfo);
95
96
const Maybe<mozilla::ipc::CSPInfo>& GetPreloadCspInfo() const;
97
void SetPreloadCspInfo(const mozilla::ipc::CSPInfo& aPreloadCSPInfo);
98
};
99
100
} // namespace dom
101
} // namespace mozilla
102
103
#endif // _mozilla_dom_ClientInfo_h