Attachment #8844481: part 4 - Navigator for bug #1299500

View | Details | Raw Unified | Return to bug 1299500
Collapse All | Expand All

(-)a/dom/base/Navigator.cpp (-116 lines)
Line     Link Here 
 Lines 61-77    Link Here 
61
#include "nsMimeTypes.h"
61
#include "nsMimeTypes.h"
62
#include "nsNetUtil.h"
62
#include "nsNetUtil.h"
63
#include "nsStringStream.h"
63
#include "nsStringStream.h"
64
#include "nsComponentManagerUtils.h"
64
#include "nsComponentManagerUtils.h"
65
#include "nsIStringStream.h"
65
#include "nsIStringStream.h"
66
#include "nsIHttpChannel.h"
66
#include "nsIHttpChannel.h"
67
#include "nsIHttpChannelInternal.h"
67
#include "nsIHttpChannelInternal.h"
68
#include "TimeManager.h"
68
#include "TimeManager.h"
69
#include "DeviceStorage.h"
70
#include "nsStreamUtils.h"
69
#include "nsStreamUtils.h"
71
#include "WidgetUtils.h"
70
#include "WidgetUtils.h"
72
#include "nsIPresentationService.h"
71
#include "nsIPresentationService.h"
73
72
74
#include "mozilla/dom/MediaDevices.h"
73
#include "mozilla/dom/MediaDevices.h"
75
#include "MediaManager.h"
74
#include "MediaManager.h"
76
75
77
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
76
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
 Lines 272-296   Navigator::Invalidate() Link Here 
272
  mMediaDevices = nullptr;
271
  mMediaDevices = nullptr;
273
272
274
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
273
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
275
  if (mAudioChannelManager) {
274
  if (mAudioChannelManager) {
276
    mAudioChannelManager = nullptr;
275
    mAudioChannelManager = nullptr;
277
  }
276
  }
278
#endif
277
#endif
279
278
280
  uint32_t len = mDeviceStorageStores.Length();
281
  for (uint32_t i = 0; i < len; ++i) {
282
    RefPtr<nsDOMDeviceStorage> ds = do_QueryReferent(mDeviceStorageStores[i]);
283
    if (ds) {
284
      ds->Shutdown();
285
    }
286
  }
287
  mDeviceStorageStores.Clear();
288
289
  if (mTimeManager) {
279
  if (mTimeManager) {
290
    mTimeManager = nullptr;
280
    mTimeManager = nullptr;
291
  }
281
  }
292
282
293
  if (mPresentation) {
283
  if (mPresentation) {
294
    mPresentation = nullptr;
284
    mPresentation = nullptr;
295
  }
285
  }
296
286
 Lines 1020-1141   Navigator::RegisterProtocolHandler(const Link Here 
1020
  if (!registrar) {
1010
  if (!registrar) {
1021
    return;
1011
    return;
1022
  }
1012
  }
1023
1013
1024
  aRv = registrar->RegisterProtocolHandler(aProtocol, aURI, aTitle,
1014
  aRv = registrar->RegisterProtocolHandler(aProtocol, aURI, aTitle,
1025
                                           mWindow->GetOuterWindow());
1015
                                           mWindow->GetOuterWindow());
1026
}
1016
}
1027
1017
1028
already_AddRefed<nsDOMDeviceStorage>
1029
Navigator::FindDeviceStorage(const nsAString& aName, const nsAString& aType)
1030
{
1031
  auto i = mDeviceStorageStores.Length();
1032
  while (i > 0) {
1033
    --i;
1034
    RefPtr<nsDOMDeviceStorage> storage =
1035
      do_QueryReferent(mDeviceStorageStores[i]);
1036
    if (storage) {
1037
      if (storage->Equals(mWindow, aName, aType)) {
1038
        return storage.forget();
1039
      }
1040
    } else {
1041
      mDeviceStorageStores.RemoveElementAt(i);
1042
    }
1043
  }
1044
  return nullptr;
1045
}
1046
1047
already_AddRefed<nsDOMDeviceStorage>
1048
Navigator::GetDeviceStorage(const nsAString& aType, ErrorResult& aRv)
1049
{
1050
  if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
1051
    aRv.Throw(NS_ERROR_FAILURE);
1052
    return nullptr;
1053
  }
1054
1055
  nsString name;
1056
  nsDOMDeviceStorage::GetDefaultStorageName(aType, name);
1057
  RefPtr<nsDOMDeviceStorage> storage = FindDeviceStorage(name, aType);
1058
  if (storage) {
1059
    return storage.forget();
1060
  }
1061
1062
  nsDOMDeviceStorage::CreateDeviceStorageFor(mWindow, aType,
1063
                                             getter_AddRefs(storage));
1064
1065
  if (!storage) {
1066
    return nullptr;
1067
  }
1068
1069
  mDeviceStorageStores.AppendElement(
1070
    do_GetWeakReference(static_cast<DOMEventTargetHelper*>(storage)));
1071
  return storage.forget();
1072
}
1073
1074
void
1075
Navigator::GetDeviceStorages(const nsAString& aType,
1076
                             nsTArray<RefPtr<nsDOMDeviceStorage> >& aStores,
1077
                             ErrorResult& aRv)
1078
{
1079
  if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
1080
    aRv.Throw(NS_ERROR_FAILURE);
1081
    return;
1082
  }
1083
1084
  nsDOMDeviceStorage::VolumeNameArray volumes;
1085
  nsDOMDeviceStorage::GetOrderedVolumeNames(aType, volumes);
1086
  if (volumes.IsEmpty()) {
1087
    RefPtr<nsDOMDeviceStorage> storage = GetDeviceStorage(aType, aRv);
1088
    if (storage) {
1089
      aStores.AppendElement(storage.forget());
1090
    }
1091
  } else {
1092
    uint32_t len = volumes.Length();
1093
    aStores.SetCapacity(len);
1094
    for (uint32_t i = 0; i < len; ++i) {
1095
      RefPtr<nsDOMDeviceStorage> storage =
1096
        GetDeviceStorageByNameAndType(volumes[i], aType, aRv);
1097
      if (aRv.Failed()) {
1098
        break;
1099
      }
1100
1101
      if (storage) {
1102
        aStores.AppendElement(storage.forget());
1103
      }
1104
    }
1105
  }
1106
}
1107
1108
already_AddRefed<nsDOMDeviceStorage>
1109
Navigator::GetDeviceStorageByNameAndType(const nsAString& aName,
1110
                                         const nsAString& aType,
1111
                                         ErrorResult& aRv)
1112
{
1113
  if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
1114
    aRv.Throw(NS_ERROR_FAILURE);
1115
    return nullptr;
1116
  }
1117
1118
  RefPtr<nsDOMDeviceStorage> storage = FindDeviceStorage(aName, aType);
1119
  if (storage) {
1120
    return storage.forget();
1121
  }
1122
  nsDOMDeviceStorage::CreateDeviceStorageByNameAndType(mWindow, aName, aType,
1123
                                                       getter_AddRefs(storage));
1124
1125
  if (!storage) {
1126
    return nullptr;
1127
  }
1128
1129
  mDeviceStorageStores.AppendElement(
1130
    do_GetWeakReference(static_cast<DOMEventTargetHelper*>(storage)));
1131
  return storage.forget();
1132
}
1133
1134
Geolocation*
1018
Geolocation*
1135
Navigator::GetGeolocation(ErrorResult& aRv)
1019
Navigator::GetGeolocation(ErrorResult& aRv)
1136
{
1020
{
1137
  if (mGeolocation) {
1021
  if (mGeolocation) {
1138
    return mGeolocation;
1022
    return mGeolocation;
1139
  }
1023
  }
1140
1024
1141
  if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
1025
  if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
(-)a/dom/base/Navigator.h (-16 lines)
Line     Link Here 
 Lines 21-37    Link Here 
21
#include "nsTArray.h"
21
#include "nsTArray.h"
22
#include "nsWeakPtr.h"
22
#include "nsWeakPtr.h"
23
#include "mozilla/dom/MediaKeySystemAccessManager.h"
23
#include "mozilla/dom/MediaKeySystemAccessManager.h"
24
24
25
class nsPluginArray;
25
class nsPluginArray;
26
class nsMimeTypeArray;
26
class nsMimeTypeArray;
27
class nsPIDOMWindowInner;
27
class nsPIDOMWindowInner;
28
class nsIDOMNavigatorSystemMessages;
28
class nsIDOMNavigatorSystemMessages;
29
class nsDOMDeviceStorage;
30
class nsIPrincipal;
29
class nsIPrincipal;
31
class nsIURI;
30
class nsIURI;
32
31
33
namespace mozilla {
32
namespace mozilla {
34
namespace dom {
33
namespace dom {
35
class BodyExtractorBase;
34
class BodyExtractorBase;
36
class Geolocation;
35
class Geolocation;
37
class systemMessageCallback;
36
class systemMessageCallback;
 Lines 190-216   public: Link Here 
190
  {
189
  {
191
    return false;
190
    return false;
192
  }
191
  }
193
  void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
192
  void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
194
  void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
193
  void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
195
  already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic,
194
  already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic,
196
                                             ErrorResult& aRv);
195
                                             ErrorResult& aRv);
197
196
198
  already_AddRefed<nsDOMDeviceStorage> GetDeviceStorage(const nsAString& aType,
199
                                                        ErrorResult& aRv);
200
201
  void GetDeviceStorages(const nsAString& aType,
202
                         nsTArray<RefPtr<nsDOMDeviceStorage> >& aStores,
203
                         ErrorResult& aRv);
204
205
  already_AddRefed<nsDOMDeviceStorage>
206
  GetDeviceStorageByNameAndType(const nsAString& aName, const nsAString& aType,
207
                                ErrorResult& aRv);
208
209
  DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv);
197
  DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv);
210
  already_AddRefed<LegacyMozTCPSocket> MozTCPSocket();
198
  already_AddRefed<LegacyMozTCPSocket> MozTCPSocket();
211
  network::Connection* GetConnection(ErrorResult& aRv);
199
  network::Connection* GetConnection(ErrorResult& aRv);
212
  MediaDevices* GetMediaDevices(ErrorResult& aRv);
200
  MediaDevices* GetMediaDevices(ErrorResult& aRv);
213
201
214
  void GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
202
  void GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads, ErrorResult& aRv);
215
  GamepadServiceTest* RequestGamepadServiceTest();
203
  GamepadServiceTest* RequestGamepadServiceTest();
216
  already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
204
  already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
 Lines 284-302   public: Link Here 
284
  void NotifyActiveVRDisplaysChanged();
272
  void NotifyActiveVRDisplaysChanged();
285
273
286
private:
274
private:
287
  virtual ~Navigator();
275
  virtual ~Navigator();
288
276
289
  bool CheckPermission(const char* type);
277
  bool CheckPermission(const char* type);
290
  static bool CheckPermission(nsPIDOMWindowInner* aWindow, const char* aType);
278
  static bool CheckPermission(nsPIDOMWindowInner* aWindow, const char* aType);
291
279
292
  already_AddRefed<nsDOMDeviceStorage> FindDeviceStorage(const nsAString& aName,
293
                                                         const nsAString& aType);
294
295
  // This enum helps SendBeaconInternal to apply different behaviors to body
280
  // This enum helps SendBeaconInternal to apply different behaviors to body
296
  // types.
281
  // types.
297
  enum BeaconType {
282
  enum BeaconType {
298
    eBeaconTypeBlob,
283
    eBeaconTypeBlob,
299
    eBeaconTypeArrayBuffer,
284
    eBeaconTypeArrayBuffer,
300
    eBeaconTypeOther
285
    eBeaconTypeOther
301
  };
286
  };
302
287
 Lines 314-330   private: Link Here 
314
  RefPtr<Promise> mBatteryPromise;
299
  RefPtr<Promise> mBatteryPromise;
315
  RefPtr<PowerManager> mPowerManager;
300
  RefPtr<PowerManager> mPowerManager;
316
  RefPtr<network::Connection> mConnection;
301
  RefPtr<network::Connection> mConnection;
317
  RefPtr<WebAuthentication> mAuthentication;
302
  RefPtr<WebAuthentication> mAuthentication;
318
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
303
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
319
  RefPtr<system::AudioChannelManager> mAudioChannelManager;
304
  RefPtr<system::AudioChannelManager> mAudioChannelManager;
320
#endif
305
#endif
321
  RefPtr<MediaDevices> mMediaDevices;
306
  RefPtr<MediaDevices> mMediaDevices;
322
  nsTArray<nsWeakPtr> mDeviceStorageStores;
323
  RefPtr<time::TimeManager> mTimeManager;
307
  RefPtr<time::TimeManager> mTimeManager;
324
  RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
308
  RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
325
  nsCOMPtr<nsPIDOMWindowInner> mWindow;
309
  nsCOMPtr<nsPIDOMWindowInner> mWindow;
326
  RefPtr<Presentation> mPresentation;
310
  RefPtr<Presentation> mPresentation;
327
  RefPtr<GamepadServiceTest> mGamepadServiceTest;
311
  RefPtr<GamepadServiceTest> mGamepadServiceTest;
328
  nsTArray<RefPtr<Promise> > mVRGetDisplaysPromises;
312
  nsTArray<RefPtr<Promise> > mVRGetDisplaysPromises;
329
  nsTArray<uint32_t> mRequestedVibrationPattern;
313
  nsTArray<uint32_t> mRequestedVibrationPattern;
330
  RefPtr<StorageManager> mStorageManager;
314
  RefPtr<StorageManager> mStorageManager;
(-)a/dom/webidl/Navigator.webidl (-10 lines)
Line     Link Here 
 Lines 240-265   partial interface Navigator { Link Here 
240
240
241
  /**
241
  /**
242
   * Make CPU instruction subset information available for UpdateUtils.
242
   * Make CPU instruction subset information available for UpdateUtils.
243
   */
243
   */
244
  [ChromeOnly]
244
  [ChromeOnly]
245
  readonly attribute boolean cpuHasSSE2;
245
  readonly attribute boolean cpuHasSSE2;
246
};
246
};
247
247
248
// nsIDOMNavigatorDeviceStorage
249
partial interface Navigator {
250
  [Throws, Pref="device.storage.enabled"]
251
  DeviceStorage? getDeviceStorage(DOMString type);
252
  [Throws, Pref="device.storage.enabled"]
253
  sequence<DeviceStorage> getDeviceStorages(DOMString type);
254
  [Throws, Pref="device.storage.enabled"]
255
  DeviceStorage? getDeviceStorageByNameAndType(DOMString name, DOMString type);
256
};
257
258
// nsIDOMNavigatorDesktopNotification
248
// nsIDOMNavigatorDesktopNotification
259
partial interface Navigator {
249
partial interface Navigator {
260
  [Throws, Pref="notification.feature.enabled", UnsafeInPrerendering]
250
  [Throws, Pref="notification.feature.enabled", UnsafeInPrerendering]
261
  readonly attribute DesktopNotificationCenter mozNotification;
251
  readonly attribute DesktopNotificationCenter mozNotification;
262
};
252
};
263
253
264
// NetworkInformation
254
// NetworkInformation
265
partial interface Navigator {
255
partial interface Navigator {

Return to bug 1299500