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 "nsCycleCollectionParticipant.h"
18 #include "nsISupports.h"
19 #include "nsStringFwd.h"
21 #include "nsWrapperCache.h"
31 class MediaCapabilities
;
36 } // namespace network
38 class WorkerNavigator final
: public nsWrapperCache
{
39 using NavigatorProperties
=
40 workerinternals::RuntimeService::NavigatorProperties
;
42 NavigatorProperties mProperties
;
43 RefPtr
<StorageManager
> mStorageManager
;
44 RefPtr
<network::Connection
> mConnection
;
45 RefPtr
<dom::MediaCapabilities
> mMediaCapabilities
;
46 RefPtr
<webgpu::Instance
> mWebGpu
;
47 RefPtr
<dom::LockManager
> mLocks
;
50 WorkerNavigator(const NavigatorProperties
& aProperties
, bool aOnline
);
54 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WorkerNavigator
)
55 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WorkerNavigator
)
57 static already_AddRefed
<WorkerNavigator
> Create(bool aOnLine
);
59 virtual JSObject
* WrapObject(JSContext
* aCx
,
60 JS::Handle
<JSObject
*> aGivenProto
) override
;
62 nsISupports
* GetParentObject() const { return nullptr; }
64 void GetAppCodeName(nsString
& aAppCodeName
, ErrorResult
& /* unused */) const {
65 aAppCodeName
.AssignLiteral("Mozilla");
67 void GetAppName(nsString
& aAppName
, CallerType aCallerType
) const;
69 void GetAppVersion(nsString
& aAppVersion
, CallerType aCallerType
,
70 ErrorResult
& aRv
) const;
72 void GetPlatform(nsString
& aPlatform
, CallerType aCallerType
,
73 ErrorResult
& aRv
) const;
75 void GetProduct(nsString
& aProduct
) const { aProduct
.AssignLiteral("Gecko"); }
77 bool TaintEnabled() const { return false; }
79 void GetLanguage(nsString
& aLanguage
) const {
80 MOZ_ASSERT(mProperties
.mLanguages
.Length() >= 1);
81 aLanguage
.Assign(mProperties
.mLanguages
[0]);
84 void GetLanguages(nsTArray
<nsString
>& aLanguages
) const {
85 aLanguages
= mProperties
.mLanguages
.Clone();
88 void GetUserAgent(nsString
& aUserAgent
, CallerType aCallerType
,
89 ErrorResult
& aRv
) const;
91 bool OnLine() const { return mOnline
; }
93 // Worker thread only!
94 void SetOnLine(bool aOnline
) { mOnline
= aOnline
; }
96 void SetLanguages(const nsTArray
<nsString
>& aLanguages
);
98 uint64_t HardwareConcurrency() const;
100 StorageManager
* Storage();
102 network::Connection
* GetConnection(ErrorResult
& aRv
);
104 dom::MediaCapabilities
* MediaCapabilities();
106 webgpu::Instance
* Gpu();
108 dom::LockManager
* Locks();
112 } // namespace mozilla
114 #endif // mozilla_dom_workernavigator_h__