Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / dom / midi / MIDIPortChild.cpp
blobd649d5540e956549d0ac8aa45ca070a54a1ff5e0
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,
16 MIDIPort* aPort)
17 : MIDIPortInterface(aPortInfo, aSysexEnabled), mDOMPort(aPort) {}
19 void MIDIPortChild::ActorDestroy(ActorDestroyReason aWhy) {
20 if (mDOMPort) {
21 mDOMPort->UnsetIPCPort();
22 MOZ_ASSERT(!mDOMPort);
24 MIDIPortInterface::Shutdown();
27 mozilla::ipc::IPCResult MIDIPortChild::RecvReceive(
28 nsTArray<MIDIMessage>&& aMsgs) {
29 if (mDOMPort) {
30 mDOMPort->Receive(aMsgs);
32 return IPC_OK();
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);
44 if (mDOMPort) {
45 mDOMPort->FireStateChangeEvent();
47 return IPC_OK();
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);
58 return NS_OK;