Bug 1732409 let fake:true getUserMedia() parameter override loopback prefs r=jib
[gecko.git] / dom / serviceworkers / ServiceWorkerDescriptor.h
blobb85890089b369aa41dc4fb42c7d3f89d8bc2c20f
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
9 #include "mozilla/UniquePtr.h"
10 #include "nsCOMPtr.h"
11 #include "nsString.h"
13 class nsIPrincipal;
15 namespace mozilla {
17 namespace ipc {
18 class PrincipalInfo;
19 } // namespace ipc
21 namespace dom {
23 class IPCServiceWorkerDescriptor;
24 enum class ServiceWorkerState : uint8_t;
26 // This class represents a snapshot of a particular ServiceWorkerInfo object.
27 // It is threadsafe and can be transferred across processes. This is useful
28 // because most of its values are immutable and can be relied upon to be
29 // accurate. Currently the only variable field is the ServiceWorkerState.
30 class ServiceWorkerDescriptor final {
31 // This class is largely a wrapper around an IPDL generated struct. We
32 // need the wrapper class since IPDL generated code includes windows.h
33 // which is in turn incompatible with bindings code.
34 UniquePtr<IPCServiceWorkerDescriptor> mData;
36 public:
37 ServiceWorkerDescriptor(uint64_t aId, uint64_t aRegistrationId,
38 uint64_t aRegistrationVersion,
39 nsIPrincipal* aPrincipal, const nsACString& aScope,
40 const nsACString& aScriptURL,
41 ServiceWorkerState aState);
43 ServiceWorkerDescriptor(uint64_t aId, uint64_t aRegistrationId,
44 uint64_t aRegistrationVersion,
45 const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
46 const nsACString& aScope,
47 const nsACString& aScriptURL,
48 ServiceWorkerState aState);
50 explicit ServiceWorkerDescriptor(
51 const IPCServiceWorkerDescriptor& aDescriptor);
53 ServiceWorkerDescriptor(const ServiceWorkerDescriptor& aRight);
55 ServiceWorkerDescriptor& operator=(const ServiceWorkerDescriptor& aRight);
57 ServiceWorkerDescriptor(ServiceWorkerDescriptor&& aRight);
59 ServiceWorkerDescriptor& operator=(ServiceWorkerDescriptor&& aRight);
61 ~ServiceWorkerDescriptor();
63 bool operator==(const ServiceWorkerDescriptor& aRight) const;
65 uint64_t Id() const;
67 uint64_t RegistrationId() const;
69 uint64_t RegistrationVersion() const;
71 const mozilla::ipc::PrincipalInfo& PrincipalInfo() const;
73 Result<nsCOMPtr<nsIPrincipal>, nsresult> GetPrincipal() const;
75 const nsCString& Scope() const;
77 const nsCString& ScriptURL() const;
79 ServiceWorkerState State() const;
81 void SetState(ServiceWorkerState aState);
83 void SetRegistrationVersion(uint64_t aVersion);
85 bool HandlesFetch() const;
87 void SetHandlesFetch(bool aHandlesFetch);
89 // Try to determine if two workers match each other. This is less strict
90 // than an operator==() call since it ignores mutable values like State().
91 bool Matches(const ServiceWorkerDescriptor& aDescriptor) const;
93 // Expose the underlying IPC type so that it can be passed via IPC.
94 const IPCServiceWorkerDescriptor& ToIPC() const;
97 } // namespace dom
98 } // namespace mozilla
100 #endif // _mozilla_dom_ServiceWorkerDescriptor_h