Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / workers / WorkerNavigator.h
blob0db9292d78815c8c560c171bc655690ca68c4e88
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;
35 namespace network {
36 class Connection;
37 } // namespace network
39 class WorkerNavigator final : public nsWrapperCache {
40 using NavigatorProperties =
41 workerinternals::RuntimeService::NavigatorProperties;
43 NavigatorProperties mProperties;
44 RefPtr<StorageManager> mStorageManager;
45 RefPtr<network::Connection> mConnection;
46 RefPtr<dom::MediaCapabilities> mMediaCapabilities;
47 RefPtr<webgpu::Instance> mWebGpu;
48 RefPtr<dom::LockManager> mLocks;
49 bool mOnline;
51 WorkerNavigator(const NavigatorProperties& aProperties, bool aOnline);
52 ~WorkerNavigator();
54 public:
55 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WorkerNavigator)
56 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(WorkerNavigator)
58 static already_AddRefed<WorkerNavigator> Create(bool aOnLine);
60 void Invalidate();
62 virtual JSObject* WrapObject(JSContext* aCx,
63 JS::Handle<JSObject*> aGivenProto) override;
65 nsISupports* GetParentObject() const { return nullptr; }
67 void GetAppCodeName(nsString& aAppCodeName, ErrorResult& /* unused */) const {
68 aAppCodeName.AssignLiteral("Mozilla");
70 void GetAppName(nsString& aAppName) const {
71 aAppName.AssignLiteral("Netscape");
74 void GetAppVersion(nsString& aAppVersion, CallerType aCallerType,
75 ErrorResult& aRv) const;
77 void GetPlatform(nsString& aPlatform, CallerType aCallerType,
78 ErrorResult& aRv) const;
80 void GetProduct(nsString& aProduct) const { aProduct.AssignLiteral("Gecko"); }
82 bool TaintEnabled() const { return false; }
84 void GetLanguage(nsString& aLanguage) const {
85 MOZ_ASSERT(mProperties.mLanguages.Length() >= 1);
86 aLanguage.Assign(mProperties.mLanguages[0]);
89 void GetLanguages(nsTArray<nsString>& aLanguages) const {
90 aLanguages = mProperties.mLanguages.Clone();
93 void GetUserAgent(nsString& aUserAgent, CallerType aCallerType,
94 ErrorResult& aRv) const;
96 bool OnLine() const { return mOnline; }
98 // Worker thread only!
99 void SetOnLine(bool aOnline) { mOnline = aOnline; }
101 bool GlobalPrivacyControl() const;
103 void SetLanguages(const nsTArray<nsString>& aLanguages);
105 uint64_t HardwareConcurrency() const;
107 StorageManager* Storage();
109 network::Connection* GetConnection(ErrorResult& aRv);
111 dom::MediaCapabilities* MediaCapabilities();
113 webgpu::Instance* Gpu();
115 dom::LockManager* Locks();
118 } // namespace dom
119 } // namespace mozilla
121 #endif // mozilla_dom_workernavigator_h__