Skip to content

Commit

Permalink
Bug 1856695 - Improve how we handle MIDI port creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ponchale committed Nov 2, 2023
1 parent 97ef27d commit 4190f58
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
5 changes: 3 additions & 2 deletions dom/midi/MIDIInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class MIDIPortInfo;
*/
class MIDIInput final : public MIDIPort {
public:
static RefPtr<MIDIInput> Create(nsPIDOMWindowInner* aWindow,
static RefPtr<MIDIInput> Create(nsPIDOMWindowInner* aWindow,
MIDIAccess* aMIDIAccessParent,
const MIDIPortInfo& aPortInfo,
const bool aSysexEnabled);
~MIDIInput() = default;

JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
Expand All @@ -50,4 +51,4 @@ static RefPtr<MIDIInput> Create(nsPIDOMWindowInner* aWindow,

} // namespace mozilla::dom

#endif // mozilla_dom_MIDIInput_h
#endif // mozilla_dom_MIDIInput_h
22 changes: 17 additions & 5 deletions dom/midi/MIDIPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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> document = GetDocumentIfCurrent();
if (!document) {
return false;
}

nsCOMPtr<nsIURI> uri = document->GetDocumentURI();
if (!uri) {
return false;
}

nsAutoCString origin;
nsresult rv = nsContentUtils::GetASCIIOrigin(uri, origin);
if (NS_FAILED(rv)) {
Expand All @@ -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(),
Expand Down
5 changes: 3 additions & 2 deletions dom/midi/MIDIPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions netwerk/protocol/http/nsHttpChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nsTArray<nsCString>>();
} else if (ref->Contains(cacheKey)) {
mRedirectedCachekeys = MakeUnique<nsTArray<nsCString>>();
} else if (mRedirectedCachekeys->Contains(cacheKey)) {
doValidation = true;
}

Expand Down

0 comments on commit 4190f58

Please sign in to comment.