Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / workers / WorkerNavigator.h
blobda66d98a38acc9a798c356cfde9f7006fcd04b77
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/. */
7 #ifndef mozilla_dom_workernavigator_h__
8 #define mozilla_dom_workernavigator_h__
10 #include <stdint.h>
11 #include "js/RootingAPI.h"
12 #include "mozilla/AlreadyAddRefed.h"
13 #include "mozilla/Assertions.h"
14 #include "mozilla/RefPtr.h"
15 #include "mozilla/dom/BindingDeclarations.h"
16 #include "mozilla/dom/workerinternals/RuntimeService.h"
17 #include "mozilla/StaticPrefs_privacy.h"
18 #include "nsCycleCollectionParticipant.h"
19 #include "nsISupports.h"
20 #include "nsStringFwd.h"
21 #include "nsTArray.h"
22 #include "nsWrapperCache.h"
24 namespace mozilla {
25 class ErrorResult;
27 namespace webgpu {
28 class Instance;
29 } // namespace webgpu
30 namespace dom {
31 class StorageManager;
32 class MediaCapabilities;
33 class LockManager;
34 class Permissions;
35 class ServiceWorkerContainer;
37 namespace network {
38 class Connection;
39 } // namespace network
41 class WorkerNavigator final : public nsWrapperCache {
42 using NavigatorProperties =
43 workerinternals::RuntimeService::NavigatorProperties;
45 NavigatorProperties mProperties;
46 RefPtr<StorageManager> mStorageManager;
47 RefPtr<network::Connection> mConnection;
48 RefPtr<dom::MediaCapabilities> mMediaCapabilities;
49 RefPtr<webgpu::Instance> mWebGpu;
50 RefPtr<dom::LockManager> mLocks;
51 RefPtr<dom::Permissions> mPermissions;
52 RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
53 bool mOnline;
55 WorkerNavigator(const NavigatorProperties& aProperties, bool aOnline);
56 ~WorkerNavigator();
58 public:
59 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WorkerNavigator)
60 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(WorkerNavigator)
62 static already_AddRefed<WorkerNavigator> Create(bool aOnLine);
64 void Invalidate();
66 virtual JSObject* WrapObject(JSContext* aCx,
67 JS::Handle<JSObject*> aGivenProto) override;
69 nsISupports* GetParentObject() const { return nullptr; }
71 void GetAppCodeName(nsString& aAppCodeName, ErrorResult& /* unused */) const {
72 aAppCodeName.AssignLiteral("Mozilla");
74 void GetAppName(nsString& aAppName) const {
75 aAppName.AssignLiteral("Netscape");
78 void GetAppVersion(nsString& aAppVersion, CallerType aCallerType,
79 ErrorResult& aRv) const;
81 void GetPlatform(nsString& aPlatform, CallerType aCallerType,
82 ErrorResult& aRv) const;
84 void GetProduct(nsString& aProduct) const { aProduct.AssignLiteral("Gecko"); }
86 bool TaintEnabled() const { return false; }
88 void GetLanguage(nsString& aLanguage) const {
89 MOZ_ASSERT(mProperties.mLanguages.Length() >= 1);
90 aLanguage.Assign(mProperties.mLanguages[0]);
93 void GetLanguages(nsTArray<nsString>& aLanguages) const {
94 aLanguages = mProperties.mLanguages.Clone();
97 void GetUserAgent(nsString& aUserAgent, CallerType aCallerType,
98 ErrorResult& aRv) const;
100 bool OnLine() const { return mOnline; }
102 // Worker thread only!
103 void SetOnLine(bool aOnline) { mOnline = aOnline; }
105 bool GlobalPrivacyControl() const;
107 void SetLanguages(const nsTArray<nsString>& aLanguages);
109 uint64_t HardwareConcurrency() const;
111 StorageManager* Storage();
113 network::Connection* GetConnection(ErrorResult& aRv);
115 dom::MediaCapabilities* MediaCapabilities();
117 webgpu::Instance* Gpu();
119 dom::LockManager* Locks();
121 dom::Permissions* Permissions();
123 already_AddRefed<ServiceWorkerContainer> ServiceWorker();
126 } // namespace dom
127 } // namespace mozilla
129 #endif // mozilla_dom_workernavigator_h__