|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #include "RedirectChannelRegistrar.h" |
|
6 |
|
7 namespace mozilla { |
|
8 namespace net { |
|
9 |
|
10 NS_IMPL_ISUPPORTS(RedirectChannelRegistrar, nsIRedirectChannelRegistrar) |
|
11 |
|
12 RedirectChannelRegistrar::RedirectChannelRegistrar() |
|
13 : mRealChannels(64) |
|
14 , mParentChannels(64) |
|
15 , mId(1) |
|
16 { |
|
17 } |
|
18 |
|
19 NS_IMETHODIMP |
|
20 RedirectChannelRegistrar::RegisterChannel(nsIChannel *channel, |
|
21 uint32_t *_retval) |
|
22 { |
|
23 mRealChannels.Put(mId, channel); |
|
24 *_retval = mId; |
|
25 |
|
26 ++mId; |
|
27 |
|
28 // Ensure we always provide positive ids |
|
29 if (!mId) |
|
30 mId = 1; |
|
31 |
|
32 return NS_OK; |
|
33 } |
|
34 |
|
35 NS_IMETHODIMP |
|
36 RedirectChannelRegistrar::GetRegisteredChannel(uint32_t id, |
|
37 nsIChannel **_retval) |
|
38 { |
|
39 if (!mRealChannels.Get(id, _retval)) |
|
40 return NS_ERROR_NOT_AVAILABLE; |
|
41 |
|
42 return NS_OK; |
|
43 } |
|
44 |
|
45 NS_IMETHODIMP |
|
46 RedirectChannelRegistrar::LinkChannels(uint32_t id, |
|
47 nsIParentChannel *channel, |
|
48 nsIChannel** _retval) |
|
49 { |
|
50 if (!mRealChannels.Get(id, _retval)) |
|
51 return NS_ERROR_NOT_AVAILABLE; |
|
52 |
|
53 mParentChannels.Put(id, channel); |
|
54 return NS_OK; |
|
55 } |
|
56 |
|
57 NS_IMETHODIMP |
|
58 RedirectChannelRegistrar::GetParentChannel(uint32_t id, |
|
59 nsIParentChannel **_retval) |
|
60 { |
|
61 if (!mParentChannels.Get(id, _retval)) |
|
62 return NS_ERROR_NOT_AVAILABLE; |
|
63 |
|
64 return NS_OK; |
|
65 } |
|
66 |
|
67 NS_IMETHODIMP |
|
68 RedirectChannelRegistrar::DeregisterChannels(uint32_t id) |
|
69 { |
|
70 mRealChannels.Remove(id); |
|
71 mParentChannels.Remove(id); |
|
72 return NS_OK; |
|
73 } |
|
74 |
|
75 } |
|
76 } |