From 4190f58ad4614d888419e9b23e30221b8a4c0967 Mon Sep 17 00:00:00 2001 From: Alfonso Hernandez Date: Thu, 2 Nov 2023 13:19:54 -0500 Subject: [PATCH] Bug 1856695 - Improve how we handle MIDI port creation --- dom/midi/MIDIInput.h | 5 +++-- dom/midi/MIDIPort.cpp | 22 +++++++++++++++++----- dom/midi/MIDIPort.h | 5 +++-- netwerk/protocol/http/nsHttpChannel.cpp | 4 +--- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/dom/midi/MIDIInput.h b/dom/midi/MIDIInput.h index 6cc1f19b0b9..adbe3d2e2ce 100644 --- a/dom/midi/MIDIInput.h +++ b/dom/midi/MIDIInput.h @@ -21,10 +21,11 @@ class MIDIPortInfo; */ class MIDIInput final : public MIDIPort { public: -static RefPtr Create(nsPIDOMWindowInner* aWindow, + static RefPtr Create(nsPIDOMWindowInner* aWindow, MIDIAccess* aMIDIAccessParent, const MIDIPortInfo& aPortInfo, const bool aSysexEnabled); + ~MIDIInput() = default; JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; @@ -50,4 +51,4 @@ static RefPtr Create(nsPIDOMWindowInner* aWindow, } // namespace mozilla::dom -#endif // mozilla_dom_MIDIInput_h +#endif // mozilla_dom_MIDIInput_h \ No newline at end of file diff --git a/dom/midi/MIDIPort.cpp b/dom/midi/MIDIPort.cpp index 596a3e562fc..8e1fbb62ccc 100644 --- a/dom/midi/MIDIPort.cpp +++ b/dom/midi/MIDIPort.cpp @@ -36,12 +36,11 @@ NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) NS_IMPL_ADDREF_INHERITED(MIDIPort, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(MIDIPort, DOMEventTargetHelper) -MIDIPort::MIDIPort(nsPIDOMWindowInner* aWindow, MIDIAccess* aMIDIAccessParent) +MIDIPort::MIDIPort(nsPIDOMWindowInner* aWindow) : DOMEventTargetHelper(aWindow), - mMIDIAccessParent(aMIDIAccessParent), + mMIDIAccessParent(nullptr), mKeepAlive(false) { MOZ_ASSERT(aWindow); - MOZ_ASSERT(aMIDIAccessParent); Document* aDoc = GetOwner()->GetExtantDoc(); if (aDoc) { @@ -62,8 +61,19 @@ MIDIPort::~MIDIPort() { } } -bool MIDIPort::Initialize(const MIDIPortInfo& aPortInfo, bool aSysexEnabled) { - nsIURI* uri = GetDocumentIfCurrent()->GetDocumentURI(); +bool MIDIPort::Initialize(const MIDIPortInfo& aPortInfo, bool aSysexEnabled, + MIDIAccess* aMIDIAccessParent) { + MOZ_ASSERT(aMIDIAccessParent); + nsCOMPtr document = GetDocumentIfCurrent(); + if (!document) { + return false; + } + + nsCOMPtr uri = document->GetDocumentURI(); + if (!uri) { + return false; + } + nsAutoCString origin; nsresult rv = nsContentUtils::GetASCIIOrigin(uri, origin); if (NS_FAILED(rv)) { @@ -90,6 +100,8 @@ bool MIDIPort::Initialize(const MIDIPortInfo& aPortInfo, bool aSysexEnabled) { aSysexEnabled)) { return false; } + + mMIDIAccessParent = aMIDIAccessParent; mPortHolder.Init(port.forget()); LOG("MIDIPort::Initialize (%s, %s)", NS_ConvertUTF16toUTF8(Port()->Name()).get(), diff --git a/dom/midi/MIDIPort.h b/dom/midi/MIDIPort.h index 68a3aa0f340..d6b0e7ac86a 100644 --- a/dom/midi/MIDIPort.h +++ b/dom/midi/MIDIPort.h @@ -38,8 +38,9 @@ class MIDIPort : public DOMEventTargetHelper, NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(MIDIPort, DOMEventTargetHelper) protected: - MIDIPort(nsPIDOMWindowInner* aWindow, MIDIAccess* aMIDIAccessParent); - bool Initialize(const MIDIPortInfo& aPortInfo, bool aSysexEnabled); +explicit MIDIPort(nsPIDOMWindowInner* aWindow); + bool Initialize(const MIDIPortInfo& aPortInfo, bool aSysexEnabled, + MIDIAccess* aMIDIAccessParent); virtual ~MIDIPort(); public: diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 2abcc4a36a0..6ec735bf879 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -3969,13 +3969,11 @@ nsHttpChannel::OnCacheEntryCheck(nsICacheEntry* entry, uint32_t* aResult) { rv = GenerateCacheKey(mPostID, cacheKey); MOZ_ASSERT(NS_SUCCEEDED(rv)); - auto redirectedCachekeys = mRedirectedCachekeys.Lock(); + auto redirectedCachekeys = mRedirectedCachekeys.Lock(); auto& ref = redirectedCachekeys.ref(); if (!ref) { ref = MakeUnique>(); } else if (ref->Contains(cacheKey)) { - mRedirectedCachekeys = MakeUnique>(); - } else if (mRedirectedCachekeys->Contains(cacheKey)) { doValidation = true; }