tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MIDIPortChild.cpp (2158B)


      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/. */
      6 
      7 #include "mozilla/dom/MIDIPortChild.h"
      8 
      9 #include "mozilla/dom/MIDIPort.h"
     10 #include "mozilla/dom/MIDIPortInterface.h"
     11 #include "nsContentUtils.h"
     12 
     13 using namespace mozilla;
     14 using namespace mozilla::dom;
     15 
     16 MIDIPortChild::MIDIPortChild(const MIDIPortInfo& aPortInfo, bool aSysexEnabled,
     17                             MIDIPort* aPort)
     18    : MIDIPortInterface(aPortInfo, aSysexEnabled), mDOMPort(aPort) {}
     19 
     20 void MIDIPortChild::ActorDestroy(ActorDestroyReason aWhy) {
     21  if (mDOMPort) {
     22    mDOMPort->UnsetIPCPort();
     23    MOZ_ASSERT(!mDOMPort);
     24  }
     25  MIDIPortInterface::Shutdown();
     26 }
     27 
     28 mozilla::ipc::IPCResult MIDIPortChild::RecvReceive(
     29    nsTArray<MIDIMessage>&& aMsgs) {
     30  if (mDOMPort) {
     31    mDOMPort->Receive(aMsgs);
     32  }
     33  return IPC_OK();
     34 }
     35 
     36 mozilla::ipc::IPCResult MIDIPortChild::RecvUpdateStatus(
     37    const uint32_t& aDeviceState, const uint32_t& aConnectionState) {
     38  // Either a device is connected, and can have any connection state, or a
     39  // device is disconnected, and can only be closed or pending.
     40  MOZ_ASSERT(mDeviceState == MIDIPortDeviceState::Connected ||
     41             (mConnectionState == MIDIPortConnectionState::Closed ||
     42              mConnectionState == MIDIPortConnectionState::Pending));
     43  mDeviceState = static_cast<MIDIPortDeviceState>(aDeviceState);
     44  mConnectionState = static_cast<MIDIPortConnectionState>(aConnectionState);
     45  if (mDOMPort) {
     46    RefPtr<MIDIPort> self(mDOMPort);
     47    self->FireStateChangeEvent();
     48  }
     49  return IPC_OK();
     50 }
     51 
     52 nsresult MIDIPortChild::GenerateStableId(const nsACString& aOrigin) {
     53  const size_t kIdLength = 64;
     54  mStableId.SetCapacity(kIdLength);
     55  mStableId.Append(Name());
     56  mStableId.Append(Manufacturer());
     57  mStableId.Append(Version());
     58  nsContentUtils::AnonymizeId(mStableId, aOrigin,
     59                              nsContentUtils::OriginFormat::Plain);
     60  return NS_OK;
     61 }