tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ClientInfo.h (4027B)


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