michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "RedirectChannelRegistrar.h" michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: NS_IMPL_ISUPPORTS(RedirectChannelRegistrar, nsIRedirectChannelRegistrar) michael@0: michael@0: RedirectChannelRegistrar::RedirectChannelRegistrar() michael@0: : mRealChannels(64) michael@0: , mParentChannels(64) michael@0: , mId(1) michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: RedirectChannelRegistrar::RegisterChannel(nsIChannel *channel, michael@0: uint32_t *_retval) michael@0: { michael@0: mRealChannels.Put(mId, channel); michael@0: *_retval = mId; michael@0: michael@0: ++mId; michael@0: michael@0: // Ensure we always provide positive ids michael@0: if (!mId) michael@0: mId = 1; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: RedirectChannelRegistrar::GetRegisteredChannel(uint32_t id, michael@0: nsIChannel **_retval) michael@0: { michael@0: if (!mRealChannels.Get(id, _retval)) michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: RedirectChannelRegistrar::LinkChannels(uint32_t id, michael@0: nsIParentChannel *channel, michael@0: nsIChannel** _retval) michael@0: { michael@0: if (!mRealChannels.Get(id, _retval)) michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: michael@0: mParentChannels.Put(id, channel); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: RedirectChannelRegistrar::GetParentChannel(uint32_t id, michael@0: nsIParentChannel **_retval) michael@0: { michael@0: if (!mParentChannels.Get(id, _retval)) michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: RedirectChannelRegistrar::DeregisterChannels(uint32_t id) michael@0: { michael@0: mRealChannels.Remove(id); michael@0: mParentChannels.Remove(id); michael@0: return NS_OK; michael@0: } michael@0: michael@0: } michael@0: }