tor-browser

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

ServiceWorkerDescriptor.h (3478B)


      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 #ifndef _mozilla_dom_ServiceWorkerDescriptor_h
      7 #define _mozilla_dom_ServiceWorkerDescriptor_h
      8 
      9 #include "mozilla/UniquePtr.h"
     10 #include "nsCOMPtr.h"
     11 #include "nsString.h"
     12 
     13 class nsIPrincipal;
     14 
     15 namespace mozilla {
     16 
     17 namespace ipc {
     18 class PrincipalInfo;
     19 }  // namespace ipc
     20 
     21 namespace dom {
     22 
     23 class IPCServiceWorkerDescriptor;
     24 enum class WorkerType : uint8_t;
     25 enum class ServiceWorkerState : uint8_t;
     26 
     27 // This class represents a snapshot of a particular ServiceWorkerInfo object.
     28 // It is threadsafe and can be transferred across processes.  This is useful
     29 // because most of its values are immutable and can be relied upon to be
     30 // accurate. Currently the only variable field is the ServiceWorkerState.
     31 class ServiceWorkerDescriptor final {
     32  // This class is largely a wrapper around an IPDL generated struct.  We
     33  // need the wrapper class since IPDL generated code includes windows.h
     34  // which is in turn incompatible with bindings code.
     35  UniquePtr<IPCServiceWorkerDescriptor> mData;
     36 
     37 public:
     38  ServiceWorkerDescriptor(uint64_t aId, uint64_t aRegistrationId,
     39                          uint64_t aRegistrationVersion,
     40                          nsIPrincipal* aPrincipal, const nsACString& aScope,
     41                          WorkerType aType, const nsACString& aScriptURL,
     42                          ServiceWorkerState aState);
     43 
     44  ServiceWorkerDescriptor(uint64_t aId, uint64_t aRegistrationId,
     45                          uint64_t aRegistrationVersion,
     46                          const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
     47                          const nsACString& aScope, WorkerType aType,
     48                          const nsACString& aScriptURL,
     49                          ServiceWorkerState aState);
     50 
     51  explicit ServiceWorkerDescriptor(
     52      const IPCServiceWorkerDescriptor& aDescriptor);
     53 
     54  ServiceWorkerDescriptor(const ServiceWorkerDescriptor& aRight);
     55 
     56  ServiceWorkerDescriptor& operator=(const ServiceWorkerDescriptor& aRight);
     57 
     58  ServiceWorkerDescriptor(ServiceWorkerDescriptor&& aRight);
     59 
     60  ServiceWorkerDescriptor& operator=(ServiceWorkerDescriptor&& aRight);
     61 
     62  ~ServiceWorkerDescriptor();
     63 
     64  bool operator==(const ServiceWorkerDescriptor& aRight) const;
     65 
     66  uint64_t Id() const;
     67 
     68  uint64_t RegistrationId() const;
     69 
     70  uint64_t RegistrationVersion() const;
     71 
     72  const mozilla::ipc::PrincipalInfo& PrincipalInfo() const;
     73 
     74  Result<nsCOMPtr<nsIPrincipal>, nsresult> GetPrincipal() const;
     75 
     76  const nsCString& Scope() const;
     77 
     78  WorkerType Type() const;
     79 
     80  const nsCString& ScriptURL() const;
     81 
     82  ServiceWorkerState State() const;
     83 
     84  void SetState(ServiceWorkerState aState);
     85 
     86  void SetRegistrationVersion(uint64_t aVersion);
     87 
     88  bool HandlesFetch() const;
     89 
     90  void SetHandlesFetch(bool aHandlesFetch);
     91 
     92  // Try to determine if two workers match each other.  This is less strict
     93  // than an operator==() call since it ignores mutable values like State().
     94  bool Matches(const ServiceWorkerDescriptor& aDescriptor) const;
     95 
     96  // Expose the underlying IPC type so that it can be passed via IPC.
     97  const IPCServiceWorkerDescriptor& ToIPC() const;
     98 };
     99 
    100 }  // namespace dom
    101 }  // namespace mozilla
    102 
    103 #endif  // _mozilla_dom_ServiceWorkerDescriptor_h