/src/mozilla-central/dom/workers/WorkerNavigator.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
7 | | #ifndef mozilla_dom_workernavigator_h__ |
8 | | #define mozilla_dom_workernavigator_h__ |
9 | | |
10 | | #include "WorkerCommon.h" |
11 | | #include "nsString.h" |
12 | | #include "nsWrapperCache.h" |
13 | | #include "mozilla/dom/BindingDeclarations.h" |
14 | | #include "mozilla/dom/StorageManager.h" |
15 | | #include "mozilla/dom/workerinternals/RuntimeService.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | class Promise; |
20 | | class StorageManager; |
21 | | class MediaCapabilities; |
22 | | |
23 | | namespace network { |
24 | | class Connection; |
25 | | } // namespace network |
26 | | |
27 | | class WorkerNavigator final : public nsWrapperCache |
28 | | { |
29 | | typedef struct workerinternals::RuntimeService::NavigatorProperties NavigatorProperties; |
30 | | |
31 | | NavigatorProperties mProperties; |
32 | | RefPtr<StorageManager> mStorageManager; |
33 | | RefPtr<network::Connection> mConnection; |
34 | | bool mOnline; |
35 | | |
36 | | WorkerNavigator(const NavigatorProperties& aProperties, bool aOnline); |
37 | | ~WorkerNavigator(); |
38 | | |
39 | | public: |
40 | | |
41 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WorkerNavigator) |
42 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WorkerNavigator) |
43 | | |
44 | | static already_AddRefed<WorkerNavigator> |
45 | | Create(bool aOnLine); |
46 | | |
47 | | virtual JSObject* |
48 | | WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
49 | | |
50 | | nsISupports* GetParentObject() const { |
51 | | return nullptr; |
52 | | } |
53 | | |
54 | | void GetAppCodeName(nsString& aAppCodeName, ErrorResult& /* unused */) const |
55 | | { |
56 | | aAppCodeName.AssignLiteral("Mozilla"); |
57 | | } |
58 | | void GetAppName(nsString& aAppName, CallerType aCallerType) const; |
59 | | |
60 | | void GetAppVersion(nsString& aAppVersion, CallerType aCallerType, |
61 | | ErrorResult& aRv) const; |
62 | | |
63 | | void GetPlatform(nsString& aPlatform, CallerType aCallerType, |
64 | | ErrorResult& aRv) const; |
65 | | |
66 | | void GetProduct(nsString& aProduct) const |
67 | | { |
68 | | aProduct.AssignLiteral("Gecko"); |
69 | | } |
70 | | |
71 | | bool TaintEnabled() const |
72 | | { |
73 | | return false; |
74 | | } |
75 | | |
76 | | void GetLanguage(nsString& aLanguage) const |
77 | | { |
78 | | if (mProperties.mLanguages.Length() >= 1) { |
79 | | aLanguage.Assign(mProperties.mLanguages[0]); |
80 | | } else { |
81 | | aLanguage.Truncate(); |
82 | | } |
83 | | } |
84 | | |
85 | | void GetLanguages(nsTArray<nsString>& aLanguages) const |
86 | | { |
87 | | aLanguages = mProperties.mLanguages; |
88 | | } |
89 | | |
90 | | void GetUserAgent(nsString& aUserAgent, CallerType aCallerType, |
91 | | ErrorResult& aRv) const; |
92 | | |
93 | | bool OnLine() const |
94 | | { |
95 | | return mOnline; |
96 | | } |
97 | | |
98 | | // Worker thread only! |
99 | | void SetOnLine(bool aOnline) |
100 | 0 | { |
101 | 0 | mOnline = aOnline; |
102 | 0 | } |
103 | | |
104 | | void SetLanguages(const nsTArray<nsString>& aLanguages); |
105 | | |
106 | | uint64_t HardwareConcurrency() const; |
107 | | |
108 | | StorageManager* Storage(); |
109 | | |
110 | | network::Connection* GetConnection(ErrorResult& aRv); |
111 | | |
112 | | dom::MediaCapabilities* MediaCapabilities(); |
113 | | |
114 | | private: |
115 | | RefPtr<dom::MediaCapabilities> mMediaCapabilities; |
116 | | }; |
117 | | |
118 | | } // namespace dom |
119 | | } // namespace mozilla |
120 | | |
121 | | #endif // mozilla_dom_workernavigator_h__ |