Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
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
#ifndef mozilla_dom_ChildProcessChannelListener_h
8
#define mozilla_dom_ChildProcessChannelListener_h
9
10
#include <functional>
11
12
#include "mozilla/net/NeckoChannelParams.h"
13
#include "nsDOMNavigationTiming.h"
14
#include "nsDataHashtable.h"
15
#include "nsIChannel.h"
16
#include "BackgroundUtils.h"
17
18
namespace mozilla {
19
namespace dom {
20
21
class ChildProcessChannelListener final {
22
NS_INLINE_DECL_REFCOUNTING(ChildProcessChannelListener)
23
24
using Resolver = std::function<void(const nsresult&)>;
25
using Callback = std::function<nsresult(
26
nsDocShellLoadState*, nsTArray<net::DocumentChannelRedirect>&&,
27
nsDOMNavigationTiming*)>;
28
29
void RegisterCallback(uint64_t aIdentifier, Callback&& aCallback);
30
31
void OnChannelReady(nsDocShellLoadState* aLoadState, uint64_t aIdentifier,
32
nsTArray<net::DocumentChannelRedirect>&& aRedirects,
33
nsDOMNavigationTiming* aTiming, Resolver&& aResolver);
34
35
static already_AddRefed<ChildProcessChannelListener> GetSingleton();
36
37
private:
38
ChildProcessChannelListener() = default;
39
~ChildProcessChannelListener() = default;
40
struct CallbackArgs {
41
RefPtr<nsDocShellLoadState> mLoadState;
42
nsTArray<net::DocumentChannelRedirect> mRedirects;
43
RefPtr<nsDOMNavigationTiming> mTiming;
44
Resolver mResolver;
45
};
46
47
// TODO Backtrack.
48
nsDataHashtable<nsUint64HashKey, Callback> mCallbacks;
49
nsDataHashtable<nsUint64HashKey, CallbackArgs> mChannelArgs;
50
};
51
52
} // namespace dom
53
} // namespace mozilla
54
55
#endif // !defined(mozilla_dom_ChildProcessChannelListener_h)