Bug 1213453 - Session-unique group id. r=pehrsons
authorAlex Chronopoulos <achronop@gmail.com>
Fri, 08 Mar 2019 11:52:06 +0000
changeset 521024 1cac58480c6a9a8acc8a11219c8c230e8ff921bb
parent 521023 7e561fa634f7c69adcd45dd78adcb2d516166f04
child 521025 a90a2cb536f39a37905aeb7c19ae5c04014b290a
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1213453
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1213453 - Session-unique group id. r=pehrsons Spec in [1] mentions: "The browsing session-unique group identifier for the source of the MediaStreamTrack." [1] https://www.w3.org/TR/mediacapture-streams/#constrainable-properties Differential Revision: https://phabricator.services.mozilla.com/D20371
dom/media/MediaManager.cpp
dom/media/MediaManager.h
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -3010,26 +3010,34 @@ RefPtr<MediaManager::StreamPromise> Medi
   vc.mMediaSource.AssignASCII(EnumToASCII(dom::MediaSourceEnumValues::strings,
                                           MediaSourceEnum::Screen));
 
   return MediaManager::GetUserMedia(aWindow, c, aCallerType);
 }
 
 /* static */
 void MediaManager::AnonymizeDevices(MediaDeviceSet& aDevices,
-                                    const nsACString& aOriginKey) {
+                                    const nsACString& aOriginKey,
+                                    const uint64_t aWindowId) {
+
   if (!aOriginKey.IsEmpty()) {
     for (RefPtr<MediaDevice>& device : aDevices) {
       nsString id;
       device->GetId(id);
       nsString rawId(id);
       AnonymizeId(id, aOriginKey);
 
       nsString groupId;
       device->GetGroupId(groupId);
+      // Use window id to salt group id in order to make it session based as
+      // required by the spec. This does not provide unique group ids through
+      // out a browser restart. However, this is not agaist the spec.
+      // Furtermore, since device ids are the same after a browser restart the
+      // fingerprint is not bigger.
+      groupId.AppendInt(aWindowId);
       AnonymizeId(groupId, aOriginKey);
 
       device = new MediaDevice(device, id, groupId, rawId);
     }
   }
 }
 
 /* static */
@@ -3201,17 +3209,18 @@ RefPtr<MediaManager::MgrPromise> MediaMa
                    }
                  }
                }
                if (!mgr->IsWindowStillActive(aWindowId)) {
                  return MgrPromise::CreateAndReject(
                      MakeRefPtr<MediaMgrError>(MediaMgrError::Name::AbortError),
                      __func__);
                }
-               MediaManager::AnonymizeDevices(*aOutDevices, *originKey);
+               MediaManager::AnonymizeDevices(*aOutDevices, *originKey,
+                                              aWindowId);
                return MgrPromise::CreateAndResolve(false, __func__);
              },
              [](RefPtr<MediaMgrError>&& aError) {
                return MgrPromise::CreateAndReject(std::move(aError), __func__);
              });
 }
 
 RefPtr<MediaManager::DevicesPromise> MediaManager::EnumerateDevices(
--- a/dom/media/MediaManager.h
+++ b/dom/media/MediaManager.h
@@ -271,17 +271,18 @@ class MediaManager final : public nsIMed
   virtual void OnDeviceChange() override;
 
  private:
   static nsresult GenerateUUID(nsAString& aResult);
   static nsresult AnonymizeId(nsAString& aId, const nsACString& aOriginKey);
 
  public:  // TODO: make private once we upgrade to GCC 4.8+ on linux.
   static void AnonymizeDevices(MediaDeviceSet& aDevices,
-                               const nsACString& aOriginKey);
+                               const nsACString& aOriginKey,
+                               const uint64_t aWindowId);
   static already_AddRefed<nsIWritableVariant> ToJSArray(
       MediaDeviceSet& aDevices);
 
  private:
   enum class DeviceEnumerationType : uint8_t {
     Normal,  // Enumeration should not return loopback or fake devices
     Fake,    // Enumeration should return fake device(s)
     Loopback /* Enumeration should return loopback device(s) (possibly in