dom/messagechannel/MessagePortService.h
author Sebastian Hengst <archaeopteryx@coole-files.de>
Mon, 27 Jan 2020 15:04:16 +0000
changeset 511851 df59b74d33d74c9e4fda377616b20c40da832a71
parent 511616 75c53240406730b7c38f4258f2762c4973e0b67f
permissions -rw-r--r--
Bug 1611454 - browser_devices_get_user_media_in_frame.js: enable dom.security.featurePolicy.enabled and permissions.delegation.enabled. r=mjf These prefs got disabled for Late Beta and Release in bug 1611454 but the test uses the feature (access to media devices from frame). Differential Revision: https://phabricator.services.mozilla.com/D61093

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_MessagePortService_h
#define mozilla_dom_MessagePortService_h

#include "nsClassHashtable.h"
#include "nsHashKeys.h"
#include "nsISupportsImpl.h"

namespace mozilla {
namespace dom {

class MessagePortParent;
class SharedMessageBody;

class MessagePortService final {
 public:
  NS_INLINE_DECL_REFCOUNTING(MessagePortService)

  // Needs to be public for the DECLARE_USE_COPY_CONSTRUCTORS macro.
  struct NextParent;

  static MessagePortService* Get();
  static MessagePortService* GetOrCreate();

  bool RequestEntangling(MessagePortParent* aParent,
                         const nsID& aDestinationUUID,
                         const uint32_t& aSequenceID);

  bool DisentanglePort(MessagePortParent* aParent,
                       FallibleTArray<RefPtr<SharedMessageBody>>& aMessages);

  bool ClosePort(MessagePortParent* aParent);

  bool PostMessages(MessagePortParent* aParent,
                    FallibleTArray<RefPtr<SharedMessageBody>>& aMessages);

  void ParentDestroy(MessagePortParent* aParent);

  bool ForceClose(const nsID& aUUID, const nsID& aDestinationUUID,
                  const uint32_t& aSequenceID);

 private:
  ~MessagePortService() {}

  void CloseAll(const nsID& aUUID, bool aForced = false);
  void MaybeShutdown();

  class MessagePortServiceData;

  nsClassHashtable<nsIDHashKey, MessagePortServiceData> mPorts;
};

}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_MessagePortService_h