Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/Navigator.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_Navigator_h
8
#define mozilla_dom_Navigator_h
9
10
#include "mozilla/MemoryReporting.h"
11
#include "mozilla/dom/BindingDeclarations.h"
12
#include "mozilla/dom/Fetch.h"
13
#include "mozilla/dom/Nullable.h"
14
#include "mozilla/ErrorResult.h"
15
#include "nsWrapperCache.h"
16
#include "nsHashKeys.h"
17
#include "nsInterfaceHashtable.h"
18
#include "nsString.h"
19
#include "nsTArray.h"
20
#include "nsWeakPtr.h"
21
#include "mozilla/dom/MediaKeySystemAccessManager.h"
22
23
class nsPluginArray;
24
class nsMimeTypeArray;
25
class nsPIDOMWindowInner;
26
class nsIDOMNavigatorSystemMessages;
27
class nsINetworkProperties;
28
class nsIPrincipal;
29
class nsIURI;
30
31
namespace mozilla {
32
namespace dom {
33
class BodyExtractorBase;
34
class Geolocation;
35
class systemMessageCallback;
36
class MediaDevices;
37
struct MediaStreamConstraints;
38
class WakeLock;
39
class ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
40
class ServiceWorkerContainer;
41
class DOMRequest;
42
class CredentialsContainer;
43
class Clipboard;
44
} // namespace dom
45
} // namespace mozilla
46
47
//*****************************************************************************
48
// Navigator: Script "navigator" object
49
//*****************************************************************************
50
51
namespace mozilla {
52
namespace dom {
53
54
class Permissions;
55
56
namespace battery {
57
class BatteryManager;
58
} // namespace battery
59
60
class Promise;
61
62
class MozIdleObserver;
63
class Gamepad;
64
class GamepadServiceTest;
65
class NavigatorUserMediaSuccessCallback;
66
class NavigatorUserMediaErrorCallback;
67
class MozGetUserMediaDevicesSuccessCallback;
68
69
struct MIDIOptions;
70
71
namespace network {
72
class Connection;
73
} // namespace network
74
75
class Presentation;
76
class LegacyMozTCPSocket;
77
class VRDisplay;
78
class VRServiceTest;
79
class StorageManager;
80
class MediaCapabilities;
81
82
class Navigator final : public nsISupports
83
                      , public nsWrapperCache
84
{
85
public:
86
  explicit Navigator(nsPIDOMWindowInner* aInnerWindow);
87
88
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
89
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Navigator)
90
91
  static void Init();
92
93
  void Invalidate();
94
  nsPIDOMWindowInner *GetWindow() const
95
0
  {
96
0
    return mWindow;
97
0
  }
98
99
  void RefreshMIMEArray();
100
101
  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
102
103
  /**
104
   * For use during document.write where our inner window changes.
105
   */
106
  void SetWindow(nsPIDOMWindowInner *aInnerWindow);
107
108
  /**
109
   * Called when the inner window navigates to a new page.
110
   */
111
  void OnNavigation();
112
113
  void GetProduct(nsAString& aProduct);
114
  void GetLanguage(nsAString& aLanguage);
115
  void GetAppName(nsAString& aAppName, CallerType aCallerType) const;
116
  void GetAppVersion(nsAString& aAppName, CallerType aCallerType,
117
                     ErrorResult& aRv) const;
118
  void GetPlatform(nsAString& aPlatform, CallerType aCallerType,
119
                   ErrorResult& aRv) const;
120
  void GetUserAgent(nsAString& aUserAgent, CallerType aCallerType,
121
                    ErrorResult& aRv) const;
122
  bool OnLine();
123
  void RegisterProtocolHandler(const nsAString& aScheme, const nsAString& aURL,
124
                               const nsAString& aTitle, ErrorResult& aRv);
125
  void RegisterContentHandler(const nsAString& aMIMEType, const nsAString& aURL,
126
                              const nsAString& aTitle, ErrorResult& aRv);
127
  nsMimeTypeArray* GetMimeTypes(ErrorResult& aRv);
128
  nsPluginArray* GetPlugins(ErrorResult& aRv);
129
  Permissions* GetPermissions(ErrorResult& aRv);
130
  void GetDoNotTrack(nsAString& aResult);
131
  Geolocation* GetGeolocation(ErrorResult& aRv);
132
  Promise* GetBattery(ErrorResult& aRv);
133
134
  static void AppName(nsAString& aAppName, bool aUsePrefOverriddenValue);
135
136
  static nsresult GetPlatform(nsAString& aPlatform,
137
                              bool aUsePrefOverriddenValue);
138
139
  static nsresult GetAppVersion(nsAString& aAppVersion,
140
                                bool aUsePrefOverriddenValue);
141
142
  static nsresult GetUserAgent(nsPIDOMWindowInner* aWindow,
143
                               bool aIsCallerChrome,
144
                               nsAString& aUserAgent);
145
146
  // Clears the user agent cache by calling:
147
  // Navigator_Binding::ClearCachedUserAgentValue(this);
148
  void ClearUserAgentCache();
149
150
  bool Vibrate(uint32_t aDuration);
151
  bool Vibrate(const nsTArray<uint32_t>& aDuration);
152
  void SetVibrationPermission(bool aPermitted, bool aPersistent);
153
  uint32_t MaxTouchPoints();
154
  void GetAppCodeName(nsAString& aAppCodeName, ErrorResult& aRv);
155
  void GetOscpu(nsAString& aOscpu, CallerType aCallerType,
156
                ErrorResult& aRv) const;
157
  void GetVendorSub(nsAString& aVendorSub);
158
  void GetVendor(nsAString& aVendor);
159
  void GetProductSub(nsAString& aProductSub);
160
  bool CookieEnabled();
161
  void GetBuildID(nsAString& aBuildID, CallerType aCallerType,
162
                  ErrorResult& aRv) const;
163
  bool JavaEnabled()
164
  {
165
    return false;
166
  }
167
  uint64_t HardwareConcurrency();
168
  bool TaintEnabled()
169
  {
170
    return false;
171
  }
172
  void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
173
  void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
174
175
  already_AddRefed<LegacyMozTCPSocket> MozTCPSocket();
176
  network::Connection* GetConnection(ErrorResult& aRv);
177
  MediaDevices* GetMediaDevices(ErrorResult& aRv);
178
179
  void GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
180
  GamepadServiceTest* RequestGamepadServiceTest();
181
  already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
182
  void GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const;
183
  VRServiceTest* RequestVRServiceTest();
184
  bool IsWebVRContentDetected() const;
185
  bool IsWebVRContentPresenting() const;
186
  void RequestVRPresentation(VRDisplay& aDisplay);
187
  nsINetworkProperties* GetNetworkProperties();
188
  already_AddRefed<Promise> RequestMIDIAccess(const MIDIOptions& aOptions, ErrorResult& aRv);
189
190
  Presentation* GetPresentation(ErrorResult& aRv);
191
192
  bool SendBeacon(const nsAString& aUrl,
193
                  const Nullable<fetch::BodyInit>& aData,
194
                  ErrorResult& aRv);
195
196
  void MozGetUserMedia(const MediaStreamConstraints& aConstraints,
197
                       NavigatorUserMediaSuccessCallback& aOnSuccess,
198
                       NavigatorUserMediaErrorCallback& aOnError,
199
                       CallerType aCallerType,
200
                       ErrorResult& aRv);
201
  void MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints,
202
                              MozGetUserMediaDevicesSuccessCallback& aOnSuccess,
203
                              NavigatorUserMediaErrorCallback& aOnError,
204
                              uint64_t aInnerWindowID,
205
                              const nsAString& aCallID,
206
                              ErrorResult& aRv);
207
208
  already_AddRefed<ServiceWorkerContainer> ServiceWorker();
209
210
  mozilla::dom::CredentialsContainer* Credentials();
211
  dom::Clipboard* Clipboard();
212
213
  static bool Webdriver();
214
215
  void GetLanguages(nsTArray<nsString>& aLanguages);
216
217
  StorageManager* Storage();
218
219
  static void GetAcceptLanguages(nsTArray<nsString>& aLanguages);
220
221
  dom::MediaCapabilities* MediaCapabilities();
222
223
  // WebIDL helper methods
224
  static bool HasUserMediaSupport(JSContext* /* unused */,
225
                                  JSObject* /* unused */);
226
227
  nsPIDOMWindowInner* GetParentObject() const
228
  {
229
    return GetWindow();
230
  }
231
232
  virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
233
234
  // GetWindowFromGlobal returns the inner window for this global, if
235
  // any, else null.
236
  static already_AddRefed<nsPIDOMWindowInner> GetWindowFromGlobal(JSObject* aGlobal);
237
238
  already_AddRefed<Promise>
239
  RequestMediaKeySystemAccess(const nsAString& aKeySystem,
240
                              const Sequence<MediaKeySystemConfiguration>& aConfig,
241
                              ErrorResult& aRv);
242
private:
243
  RefPtr<MediaKeySystemAccessManager> mMediaKeySystemAccessManager;
244
245
public:
246
  void NotifyVRDisplaysUpdated();
247
  void NotifyActiveVRDisplaysChanged();
248
249
private:
250
  virtual ~Navigator();
251
252
  // This enum helps SendBeaconInternal to apply different behaviors to body
253
  // types.
254
  enum BeaconType {
255
    eBeaconTypeBlob,
256
    eBeaconTypeArrayBuffer,
257
    eBeaconTypeOther
258
  };
259
260
  bool SendBeaconInternal(const nsAString& aUrl,
261
                          BodyExtractorBase* aBody,
262
                          BeaconType aType,
263
                          ErrorResult& aRv);
264
265
  RefPtr<nsMimeTypeArray> mMimeTypes;
266
  RefPtr<nsPluginArray> mPlugins;
267
  RefPtr<Permissions> mPermissions;
268
  RefPtr<Geolocation> mGeolocation;
269
  RefPtr<battery::BatteryManager> mBatteryManager;
270
  RefPtr<Promise> mBatteryPromise;
271
  RefPtr<network::Connection> mConnection;
272
  RefPtr<CredentialsContainer> mCredentials;
273
  RefPtr<dom::Clipboard> mClipboard;
274
  RefPtr<MediaDevices> mMediaDevices;
275
  RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
276
  nsCOMPtr<nsPIDOMWindowInner> mWindow;
277
  RefPtr<Presentation> mPresentation;
278
  RefPtr<GamepadServiceTest> mGamepadServiceTest;
279
  nsTArray<RefPtr<Promise> > mVRGetDisplaysPromises;
280
  RefPtr<VRServiceTest> mVRServiceTest;
281
  nsTArray<uint32_t> mRequestedVibrationPattern;
282
  RefPtr<StorageManager> mStorageManager;
283
  RefPtr<dom::MediaCapabilities> mMediaCapabilities;
284
};
285
286
} // namespace dom
287
} // namespace mozilla
288
289
#endif // mozilla_dom_Navigator_h