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__
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"
22 #include "nsWrapperCache.h"
32 class MediaCapabilities
;
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
;
51 WorkerNavigator(const NavigatorProperties
& aProperties
, bool aOnline
);
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
);
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();
119 } // namespace mozilla
121 #endif // mozilla_dom_workernavigator_h__