1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/MIDIPortChild.h"
8 #include "mozilla/dom/MIDIPort.h"
9 #include "mozilla/dom/MIDIPortInterface.h"
10 #include "nsContentUtils.h"
12 using namespace mozilla
;
13 using namespace mozilla::dom
;
15 MIDIPortChild::MIDIPortChild(const MIDIPortInfo
& aPortInfo
, bool aSysexEnabled
,
17 : MIDIPortInterface(aPortInfo
, aSysexEnabled
), mDOMPort(aPort
) {}
19 void MIDIPortChild::ActorDestroy(ActorDestroyReason aWhy
) {
21 mDOMPort
->UnsetIPCPort();
22 MOZ_ASSERT(!mDOMPort
);
24 MIDIPortInterface::Shutdown();
27 mozilla::ipc::IPCResult
MIDIPortChild::RecvReceive(
28 nsTArray
<MIDIMessage
>&& aMsgs
) {
30 mDOMPort
->Receive(aMsgs
);
35 mozilla::ipc::IPCResult
MIDIPortChild::RecvUpdateStatus(
36 const uint32_t& aDeviceState
, const uint32_t& aConnectionState
) {
37 // Either a device is connected, and can have any connection state, or a
38 // device is disconnected, and can only be closed or pending.
39 MOZ_ASSERT(mDeviceState
== MIDIPortDeviceState::Connected
||
40 (mConnectionState
== MIDIPortConnectionState::Closed
||
41 mConnectionState
== MIDIPortConnectionState::Pending
));
42 mDeviceState
= static_cast<MIDIPortDeviceState
>(aDeviceState
);
43 mConnectionState
= static_cast<MIDIPortConnectionState
>(aConnectionState
);
45 mDOMPort
->FireStateChangeEvent();
50 nsresult
MIDIPortChild::GenerateStableId(const nsACString
& aOrigin
) {
51 const size_t kIdLength
= 64;
52 mStableId
.SetCapacity(kIdLength
);
53 mStableId
.Append(Name());
54 mStableId
.Append(Manufacturer());
55 mStableId
.Append(Version());
56 nsContentUtils::AnonymizeId(mStableId
, aOrigin
,
57 nsContentUtils::OriginFormat::Plain
);