docshell/base/ChildProcessChannelListener.h
author Steven MacLeod <steven@smacleod.ca>
Wed, 23 Sep 2020 20:59:15 +0000
changeset 550148 6d45a17995e220d26df280d6af6c3bf81b69b348
parent 537688 9404dd36d892589b8478352b988c5704c7c352e4
permissions -rw-r--r--
Bug 1665941 - expand cross-origin requestFullscreen mochitest to test ESC exit. r=smaug This expands the current `requestFullscreen()` mochitest to check the result of exiting fullscreen using the ESC key, since it follows a separate code path from `document.exitFullscreen()`. Depends on D90928 Differential Revision: https://phabricator.services.mozilla.com/D90940

/* -*- 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_ChildProcessChannelListener_h
#define mozilla_dom_ChildProcessChannelListener_h

#include <functional>

#include "mozilla/extensions/StreamFilterParent.h"
#include "mozilla/net/NeckoChannelParams.h"
#include "nsDOMNavigationTiming.h"
#include "nsDataHashtable.h"
#include "nsIChannel.h"
#include "BackgroundUtils.h"

namespace mozilla {
namespace dom {

class ChildProcessChannelListener final {
  NS_INLINE_DECL_REFCOUNTING(ChildProcessChannelListener)

  using Endpoint = mozilla::ipc::Endpoint<extensions::PStreamFilterParent>;
  using Resolver = std::function<void(const nsresult&)>;
  using Callback = std::function<nsresult(
      nsDocShellLoadState*, nsTArray<Endpoint>&&, nsDOMNavigationTiming*)>;

  void RegisterCallback(uint64_t aIdentifier, Callback&& aCallback);

  void OnChannelReady(nsDocShellLoadState* aLoadState, uint64_t aIdentifier,
                      nsTArray<Endpoint>&& aStreamFilterEndpoints,
                      nsDOMNavigationTiming* aTiming, Resolver&& aResolver);

  static already_AddRefed<ChildProcessChannelListener> GetSingleton();

 private:
  ChildProcessChannelListener() = default;
  ~ChildProcessChannelListener();
  struct CallbackArgs {
    RefPtr<nsDocShellLoadState> mLoadState;
    nsTArray<Endpoint> mStreamFilterEndpoints;
    RefPtr<nsDOMNavigationTiming> mTiming;
    Resolver mResolver;
  };

  // TODO Backtrack.
  nsDataHashtable<nsUint64HashKey, Callback> mCallbacks;
  nsDataHashtable<nsUint64HashKey, CallbackArgs> mChannelArgs;
};

}  // namespace dom
}  // namespace mozilla

#endif  // !defined(mozilla_dom_ChildProcessChannelListener_h)