Skip to content

Commit c27d26e

Browse files
committed
Backed out 2 changesets (bug 1758468) for causing web midi related mochitest failures. CLOSED TREE
Backed out changeset cfba299e5067 (bug 1758468) Backed out changeset c0eb987d0f76 (bug 1758468)
1 parent c951f55 commit c27d26e

17 files changed

+77
-271
lines changed

dom/base/nsContentUtils.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@
269269
#include "nsIContentSecurityPolicy.h"
270270
#include "nsIContentSink.h"
271271
#include "nsIContentViewer.h"
272-
#include "nsICryptoHMAC.h"
273272
#include "nsIDOMWindowUtils.h"
274273
#include "nsIDocShell.h"
275274
#include "nsIDocShellTreeItem.h"
@@ -290,7 +289,6 @@
290289
#include "nsIInputStream.h"
291290
#include "nsIInterfaceRequestor.h"
292291
#include "nsIInterfaceRequestorUtils.h"
293-
#include "nsIKeyModule.h"
294292
#include "nsILoadContext.h"
295293
#include "nsILoadGroup.h"
296294
#include "nsILoadInfo.h"
@@ -10626,48 +10624,6 @@ nsCString nsContentUtils::TruncatedURLForDisplay(nsIURI* aURL, size_t aMaxLen) {
1062610624
return spec;
1062710625
}
1062810626

10629-
/* static */
10630-
nsresult nsContentUtils::AnonymizeId(nsAString& aId,
10631-
const nsACString& aOriginKey,
10632-
OriginFormat aFormat) {
10633-
MOZ_ASSERT(NS_IsMainThread());
10634-
10635-
nsresult rv;
10636-
nsCOMPtr<nsIKeyObjectFactory> factory =
10637-
do_GetService("@mozilla.org/security/keyobjectfactory;1", &rv);
10638-
NS_ENSURE_SUCCESS(rv, rv);
10639-
10640-
nsCString rawKey;
10641-
if (aFormat == OriginFormat::Base64) {
10642-
rv = Base64Decode(aOriginKey, rawKey);
10643-
NS_ENSURE_SUCCESS(rv, rv);
10644-
} else {
10645-
rawKey = aOriginKey;
10646-
}
10647-
10648-
nsCOMPtr<nsIKeyObject> key;
10649-
rv = factory->KeyFromString(nsIKeyObject::HMAC, rawKey, getter_AddRefs(key));
10650-
NS_ENSURE_SUCCESS(rv, rv);
10651-
10652-
nsCOMPtr<nsICryptoHMAC> hasher =
10653-
do_CreateInstance(NS_CRYPTO_HMAC_CONTRACTID, &rv);
10654-
NS_ENSURE_SUCCESS(rv, rv);
10655-
10656-
rv = hasher->Init(nsICryptoHMAC::SHA256, key);
10657-
NS_ENSURE_SUCCESS(rv, rv);
10658-
10659-
NS_ConvertUTF16toUTF8 id(aId);
10660-
rv = hasher->Update(reinterpret_cast<const uint8_t*>(id.get()), id.Length());
10661-
NS_ENSURE_SUCCESS(rv, rv);
10662-
10663-
nsCString mac;
10664-
rv = hasher->Finish(true, mac);
10665-
NS_ENSURE_SUCCESS(rv, rv);
10666-
10667-
CopyUTF8toUTF16(mac, aId);
10668-
return NS_OK;
10669-
}
10670-
1067110627
namespace mozilla {
1067210628
std::ostream& operator<<(std::ostream& aOut,
1067310629
const PreventDefaultResult aPreventDefaultResult) {

dom/base/nsContentUtils.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,18 +3318,6 @@ class nsContentUtils {
33183318
*/
33193319
static nsCString TruncatedURLForDisplay(nsIURI* aURL, size_t aMaxLen = 128);
33203320

3321-
/**
3322-
* Anonymize the given id by hashing it with the provided origin. The
3323-
* resulting id will have the same length as the one that was passed in.
3324-
*/
3325-
enum class OriginFormat {
3326-
Base64,
3327-
Plain,
3328-
};
3329-
3330-
static nsresult AnonymizeId(nsAString& aId, const nsACString& aOriginKey,
3331-
OriginFormat aFormat = OriginFormat::Base64);
3332-
33333321
private:
33343322
static bool InitializeEventTable();
33353323

dom/media/MediaManager.cpp

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,7 +2870,7 @@ RefPtr<LocalDeviceSetPromise> MediaManager::AnonymizeDevices(
28702870
RefPtr anonymized = new LocalMediaDeviceSetRefCnt();
28712871
for (const RefPtr<MediaDevice>& device : *rawDevices) {
28722872
nsString id = device->mRawID;
2873-
nsContentUtils::AnonymizeId(id, aOriginKey);
2873+
AnonymizeId(id, aOriginKey);
28742874

28752875
nsString groupId = device->mRawGroupID;
28762876
// Use window id to salt group id in order to make it session
@@ -2879,7 +2879,7 @@ RefPtr<LocalDeviceSetPromise> MediaManager::AnonymizeDevices(
28792879
// against the spec. Furthermore, since device ids are the same
28802880
// after a browser restart the fingerprint is not bigger.
28812881
groupId.AppendInt(windowId);
2882-
nsContentUtils::AnonymizeId(groupId, aOriginKey);
2882+
AnonymizeId(groupId, aOriginKey);
28832883

28842884
nsString name = device->mRawName;
28852885
if (name.Find(u"AirPods"_ns) != -1) {
@@ -2899,6 +2899,52 @@ RefPtr<LocalDeviceSetPromise> MediaManager::AnonymizeDevices(
28992899
});
29002900
}
29012901

2902+
/* static */
2903+
nsresult MediaManager::AnonymizeId(nsAString& aId,
2904+
const nsACString& aOriginKey) {
2905+
MOZ_ASSERT(NS_IsMainThread());
2906+
2907+
nsresult rv;
2908+
nsCOMPtr<nsIKeyObjectFactory> factory =
2909+
do_GetService("@mozilla.org/security/keyobjectfactory;1", &rv);
2910+
if (NS_FAILED(rv)) {
2911+
return rv;
2912+
}
2913+
nsCString rawKey;
2914+
rv = Base64Decode(aOriginKey, rawKey);
2915+
if (NS_FAILED(rv)) {
2916+
return rv;
2917+
}
2918+
nsCOMPtr<nsIKeyObject> key;
2919+
rv = factory->KeyFromString(nsIKeyObject::HMAC, rawKey, getter_AddRefs(key));
2920+
if (NS_FAILED(rv)) {
2921+
return rv;
2922+
}
2923+
2924+
nsCOMPtr<nsICryptoHMAC> hasher =
2925+
do_CreateInstance(NS_CRYPTO_HMAC_CONTRACTID, &rv);
2926+
if (NS_FAILED(rv)) {
2927+
return rv;
2928+
}
2929+
rv = hasher->Init(nsICryptoHMAC::SHA256, key);
2930+
if (NS_FAILED(rv)) {
2931+
return rv;
2932+
}
2933+
NS_ConvertUTF16toUTF8 id(aId);
2934+
rv = hasher->Update(reinterpret_cast<const uint8_t*>(id.get()), id.Length());
2935+
if (NS_FAILED(rv)) {
2936+
return rv;
2937+
}
2938+
nsCString mac;
2939+
rv = hasher->Finish(true, mac);
2940+
if (NS_FAILED(rv)) {
2941+
return rv;
2942+
}
2943+
2944+
CopyUTF8toUTF16(mac, aId);
2945+
return NS_OK;
2946+
}
2947+
29022948
RefPtr<LocalDeviceSetPromise> MediaManager::EnumerateDevicesImpl(
29032949
nsPIDOMWindowInner* aWindow, MediaSourceEnum aVideoInputType,
29042950
MediaSourceEnum aAudioInputType, EnumerationFlags aFlags) {

dom/media/MediaManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ class MediaManager final : public nsIMediaManagerService,
300300

301301
private:
302302
static nsresult GenerateUUID(nsAString& aResult);
303+
static nsresult AnonymizeId(nsAString& aId, const nsACString& aOriginKey);
303304

304305
public:
305306
/**

dom/midi/MIDIAccess.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,12 @@ void MIDIAccess::FireConnectionEvent(MIDIPort* aPort) {
8989
aPort->GetId(id);
9090
ErrorResult rv;
9191
if (aPort->State() == MIDIPortDeviceState::Disconnected) {
92-
if (aPort->Type() == MIDIPortType::Input && mInputMap->Has(id)) {
93-
MIDIInputMap_Binding::MaplikeHelpers::Delete(mInputMap, aPort->StableId(),
94-
rv);
95-
mInputMap->Remove(id);
96-
} else if (aPort->Type() == MIDIPortType::Output && mOutputMap->Has(id)) {
97-
MIDIOutputMap_Binding::MaplikeHelpers::Delete(mOutputMap,
98-
aPort->StableId(), rv);
99-
mOutputMap->Remove(id);
92+
if (aPort->Type() == MIDIPortType::Input &&
93+
MIDIInputMap_Binding::MaplikeHelpers::Has(mInputMap, id, rv)) {
94+
MIDIInputMap_Binding::MaplikeHelpers::Delete(mInputMap, id, rv);
95+
} else if (aPort->Type() == MIDIPortType::Output &&
96+
MIDIOutputMap_Binding::MaplikeHelpers::Has(mOutputMap, id, rv)) {
97+
MIDIOutputMap_Binding::MaplikeHelpers::Delete(mOutputMap, id, rv);
10098
}
10199
// Check to make sure Has()/Delete() calls haven't failed.
102100
if (NS_WARN_IF(rv.Failed())) {
@@ -108,31 +106,31 @@ void MIDIAccess::FireConnectionEvent(MIDIPort* aPort) {
108106
// this means a port that was disconnected has been reconnected, with the
109107
// port owner holding the object during that time, and we should add that
110108
// port object to our maps again.
111-
if (aPort->Type() == MIDIPortType::Input && !mInputMap->Has(id)) {
109+
if (aPort->Type() == MIDIPortType::Input &&
110+
!MIDIInputMap_Binding::MaplikeHelpers::Has(mInputMap, id, rv)) {
112111
if (NS_WARN_IF(rv.Failed())) {
113112
LOG("Input port not found");
114113
return;
115114
}
116115
MIDIInputMap_Binding::MaplikeHelpers::Set(
117-
mInputMap, aPort->StableId(), *(static_cast<MIDIInput*>(aPort)), rv);
116+
mInputMap, id, *(static_cast<MIDIInput*>(aPort)), rv);
118117
if (NS_WARN_IF(rv.Failed())) {
119118
LOG("Map Set failed for input port");
120119
return;
121120
}
122-
mInputMap->Insert(id, aPort);
123-
} else if (aPort->Type() == MIDIPortType::Output && mOutputMap->Has(id)) {
121+
} else if (aPort->Type() == MIDIPortType::Output &&
122+
!MIDIOutputMap_Binding::MaplikeHelpers::Has(mOutputMap, id,
123+
rv)) {
124124
if (NS_WARN_IF(rv.Failed())) {
125125
LOG("Output port not found");
126126
return;
127127
}
128128
MIDIOutputMap_Binding::MaplikeHelpers::Set(
129-
mOutputMap, aPort->StableId(), *(static_cast<MIDIOutput*>(aPort)),
130-
rv);
129+
mOutputMap, id, *(static_cast<MIDIOutput*>(aPort)), rv);
131130
if (NS_WARN_IF(rv.Failed())) {
132131
LOG("Map set failed for output port");
133132
return;
134133
}
135-
mOutputMap->Insert(id, aPort);
136134
}
137135
}
138136
RefPtr<MIDIConnectionEvent> event =
@@ -146,7 +144,9 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
146144
MIDIPortType type = static_cast<MIDIPortType>(aInfo.type());
147145
RefPtr<MIDIPort> port;
148146
if (type == MIDIPortType::Input) {
149-
if (mInputMap->Has(id) || NS_WARN_IF(aRv.Failed())) {
147+
bool hasPort =
148+
MIDIInputMap_Binding::MaplikeHelpers::Has(mInputMap, id, aRv);
149+
if (hasPort || NS_WARN_IF(aRv.Failed())) {
150150
// We already have the port in our map.
151151
return;
152152
}
@@ -157,15 +157,15 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
157157
return;
158158
}
159159
MIDIInputMap_Binding::MaplikeHelpers::Set(
160-
mInputMap, port->StableId(), *(static_cast<MIDIInput*>(port.get())),
161-
aRv);
160+
mInputMap, id, *(static_cast<MIDIInput*>(port.get())), aRv);
162161
if (NS_WARN_IF(aRv.Failed())) {
163162
LOG("Coudld't set input port in map");
164163
return;
165164
}
166-
mInputMap->Insert(id, port);
167165
} else if (type == MIDIPortType::Output) {
168-
if (mOutputMap->Has(id) || NS_WARN_IF(aRv.Failed())) {
166+
bool hasPort =
167+
MIDIOutputMap_Binding::MaplikeHelpers::Has(mOutputMap, id, aRv);
168+
if (hasPort || NS_WARN_IF(aRv.Failed())) {
169169
// We already have the port in our map.
170170
return;
171171
}
@@ -176,13 +176,11 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
176176
return;
177177
}
178178
MIDIOutputMap_Binding::MaplikeHelpers::Set(
179-
mOutputMap, port->StableId(), *(static_cast<MIDIOutput*>(port.get())),
180-
aRv);
179+
mOutputMap, id, *(static_cast<MIDIOutput*>(port.get())), aRv);
181180
if (NS_WARN_IF(aRv.Failed())) {
182181
LOG("Coudld't set output port in map");
183182
return;
184183
}
185-
mOutputMap->Insert(id, port);
186184
} else {
187185
// If we hit this, then we have some port that is neither input nor output.
188186
// That is bad.

dom/midi/MIDIInputMap.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#ifndef mozilla_dom_MIDIInputMap_h
88
#define mozilla_dom_MIDIInputMap_h
99

10-
#include "mozilla/dom/MIDIPort.h"
1110
#include "nsCOMPtr.h"
12-
#include "nsTHashMap.h"
1311
#include "nsWrapperCache.h"
1412

1513
class nsPIDOMWindowInner;
@@ -29,15 +27,9 @@ class MIDIInputMap final : public nsISupports, public nsWrapperCache {
2927
explicit MIDIInputMap(nsPIDOMWindowInner* aParent);
3028
JSObject* WrapObject(JSContext* aCx,
3129
JS::Handle<JSObject*> aGivenProto) override;
32-
bool Has(nsAString& aId) { return mPorts.Get(aId) != nullptr; }
33-
void Insert(nsAString& aId, RefPtr<MIDIPort> aPort) {
34-
mPorts.InsertOrUpdate(aId, aPort);
35-
}
36-
void Remove(nsAString& aId) { mPorts.Remove(aId); }
3730

3831
private:
3932
~MIDIInputMap() = default;
40-
nsTHashMap<nsString, RefPtr<MIDIPort>> mPorts;
4133
nsCOMPtr<nsPIDOMWindowInner> mParent;
4234
};
4335

dom/midi/MIDIOutputMap.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#ifndef mozilla_dom_MIDIOutputMap_h
88
#define mozilla_dom_MIDIOutputMap_h
99

10-
#include "mozilla/dom/MIDIPort.h"
1110
#include "nsCOMPtr.h"
12-
#include "nsTHashMap.h"
1311
#include "nsWrapperCache.h"
1412

1513
class nsPIDOMWindowInner;
@@ -32,15 +30,9 @@ class MIDIOutputMap final : public nsISupports, public nsWrapperCache {
3230

3331
JSObject* WrapObject(JSContext* aCx,
3432
JS::Handle<JSObject*> aGivenProto) override;
35-
bool Has(nsAString& aId) { return mPorts.Get(aId) != nullptr; }
36-
void Insert(nsAString& aId, RefPtr<MIDIPort> aPort) {
37-
mPorts.InsertOrUpdate(aId, aPort);
38-
}
39-
void Remove(nsAString& aId) { mPorts.Remove(aId); }
4033

4134
private:
4235
~MIDIOutputMap() = default;
43-
nsTHashMap<nsString, RefPtr<MIDIPort>> mPorts;
4436
nsCOMPtr<nsPIDOMWindowInner> mParent;
4537
};
4638

dom/midi/MIDIPort.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "mozilla/dom/Document.h"
1515
#include "mozilla/dom/Promise.h"
1616
#include "mozilla/Unused.h"
17-
#include "nsContentUtils.h"
1817
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
1918
#include "MIDILog.h"
2019

@@ -64,17 +63,8 @@ MIDIPort::~MIDIPort() {
6463
}
6564

6665
bool MIDIPort::Initialize(const MIDIPortInfo& aPortInfo, bool aSysexEnabled) {
67-
nsIURI* uri = GetDocumentIfCurrent()->GetDocumentURI();
68-
nsAutoCString origin;
69-
nsresult rv = nsContentUtils::GetASCIIOrigin(uri, origin);
70-
if (NS_FAILED(rv)) {
71-
return false;
72-
}
7366
RefPtr<MIDIPortChild> port =
7467
new MIDIPortChild(aPortInfo, aSysexEnabled, this);
75-
if (NS_FAILED(port->GenerateStableId(origin))) {
76-
return false;
77-
}
7868
PBackgroundChild* b = BackgroundChild::GetForCurrentThread();
7969
MOZ_ASSERT(b,
8070
"Should always have a valid BackgroundChild when creating a port "
@@ -101,7 +91,7 @@ void MIDIPort::UnsetIPCPort() {
10191

10292
void MIDIPort::GetId(nsString& aRetVal) const {
10393
MOZ_ASSERT(mPort);
104-
aRetVal = mPort->StableId();
94+
aRetVal = mPort->MIDIPortInterface::Id();
10595
}
10696

10797
void MIDIPort::GetManufacturer(nsString& aRetVal) const {
@@ -262,6 +252,4 @@ void MIDIPort::DontKeepAliveOnStatechange() {
262252
}
263253
}
264254

265-
const nsString& MIDIPort::StableId() { return mPort->StableId(); }
266-
267255
} // namespace mozilla::dom

dom/midi/MIDIPort.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class MIDIPort : public DOMEventTargetHelper,
7373
IMPL_EVENT_HANDLER(statechange)
7474

7575
void DisconnectFromOwner() override;
76-
const nsString& StableId();
7776

7877
protected:
7978
// IPC Actor corresponding to this class

dom/midi/MIDIPortChild.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "mozilla/dom/MIDIPortChild.h"
88
#include "mozilla/dom/MIDIPort.h"
99
#include "mozilla/dom/MIDIPortInterface.h"
10-
#include "nsContentUtils.h"
1110

1211
using namespace mozilla;
1312
using namespace mozilla::dom;
@@ -56,19 +55,3 @@ void MIDIPortChild::SetActorAlive() {
5655
mActorWasAlive = true;
5756
AddRef();
5857
}
59-
60-
nsresult MIDIPortChild::GenerateStableId(const nsACString& aOrigin) {
61-
const size_t kIdLength = 64;
62-
mStableId.SetCapacity(kIdLength);
63-
mStableId.Append(Name());
64-
mStableId.Append(Manufacturer());
65-
mStableId.Append(Version());
66-
// Extend to at least 64 characters
67-
while (mStableId.Length() < kIdLength) {
68-
mStableId.Append(' ');
69-
}
70-
nsContentUtils::AnonymizeId(mStableId, aOrigin,
71-
nsContentUtils::OriginFormat::Plain);
72-
mStableId.Truncate(kIdLength);
73-
return NS_OK;
74-
}

0 commit comments

Comments
 (0)