2010-08-05 06:15:55 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-07-28 22:33:06 +04:00
|
|
|
|
|
|
|
#ifndef nsAsyncRedirectVerifyHelper_h
|
|
|
|
#define nsAsyncRedirectVerifyHelper_h
|
|
|
|
|
|
|
|
#include "nsIRunnable.h"
|
2010-08-05 06:15:55 +04:00
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2010-07-28 22:33:06 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2010-08-05 06:15:55 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-07-28 22:33:06 +04:00
|
|
|
|
|
|
|
class nsIChannel;
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2010-07-28 22:33:06 +04:00
|
|
|
/**
|
|
|
|
* This class simplifies call of OnChannelRedirect of IOService and
|
|
|
|
* the sink bound with the channel being redirected while the result of
|
|
|
|
* redirect decision is returned through the callback.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsAsyncRedirectVerifyHelper final : public nsIRunnable,
|
2017-05-10 02:19:37 +03:00
|
|
|
public nsINamed,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIAsyncVerifyRedirectCallback
|
2010-07-28 22:33:06 +04:00
|
|
|
{
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2010-07-28 22:33:06 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
2017-05-10 02:19:37 +03:00
|
|
|
NS_DECL_NSINAMED
|
2010-08-05 06:15:55 +04:00
|
|
|
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
2010-07-28 22:33:06 +04:00
|
|
|
|
|
|
|
public:
|
2010-08-05 06:15:55 +04:00
|
|
|
nsAsyncRedirectVerifyHelper();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calls AsyncOnChannelRedirect() on the given sink with the given
|
|
|
|
* channels and flags. Keeps track of number of async callbacks to expect.
|
|
|
|
*/
|
|
|
|
nsresult DelegateOnChannelRedirect(nsIChannelEventSink *sink,
|
|
|
|
nsIChannel *oldChannel,
|
|
|
|
nsIChannel *newChannel,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags);
|
2010-08-05 06:15:55 +04:00
|
|
|
|
2010-07-28 22:33:06 +04:00
|
|
|
/**
|
2010-08-05 06:15:55 +04:00
|
|
|
* Initialize and run the chain of AsyncOnChannelRedirect calls. OldChannel
|
2010-07-28 22:33:06 +04:00
|
|
|
* is QI'ed for nsIAsyncVerifyRedirectCallback. The result of the redirect
|
|
|
|
* decision is passed through this interface back to the oldChannel.
|
|
|
|
*
|
|
|
|
* @param oldChan
|
|
|
|
* channel being redirected, MUST implement
|
|
|
|
* nsIAsyncVerifyRedirectCallback
|
|
|
|
* @param newChan
|
|
|
|
* target of the redirect channel
|
|
|
|
* @param flags
|
|
|
|
* redirect flags
|
2017-07-05 01:47:00 +03:00
|
|
|
* @param mainThreadEventTarget
|
|
|
|
* a labeled event target for dispatching runnables
|
2010-07-28 22:33:06 +04:00
|
|
|
* @param synchronize
|
|
|
|
* set to TRUE if you want the Init method wait synchronously for
|
|
|
|
* all redirect callbacks
|
|
|
|
*/
|
|
|
|
nsresult Init(nsIChannel* oldChan,
|
|
|
|
nsIChannel* newChan,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags,
|
2017-07-05 01:47:00 +03:00
|
|
|
nsIEventTarget* mainThreadEventTarget,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool synchronize = false);
|
2010-07-28 22:33:06 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIChannel> mOldChan;
|
|
|
|
nsCOMPtr<nsIChannel> mNewChan;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mFlags;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mWaitingForRedirectCallback;
|
2017-06-01 23:43:44 +03:00
|
|
|
nsCOMPtr<nsIEventTarget> mCallbackEventTarget;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mCallbackInitiated;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mExpectedCallbacks;
|
2010-08-05 06:15:55 +04:00
|
|
|
nsresult mResult; // value passed to callback
|
2010-07-28 22:33:06 +04:00
|
|
|
|
2010-08-05 06:15:55 +04:00
|
|
|
void InitCallback();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls back to |oldChan| as described in Init()
|
|
|
|
*/
|
|
|
|
void ExplicitCallback(nsresult result);
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsAsyncRedirectVerifyHelper();
|
|
|
|
|
|
|
|
bool IsOldChannelCanceled();
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper to make the call-stack handle some control-flow for us
|
|
|
|
*/
|
|
|
|
class nsAsyncRedirectAutoCallback
|
|
|
|
{
|
|
|
|
public:
|
2014-08-05 17:20:50 +04:00
|
|
|
explicit nsAsyncRedirectAutoCallback(nsIAsyncVerifyRedirectCallback* aCallback)
|
2010-08-05 06:15:55 +04:00
|
|
|
: mCallback(aCallback)
|
|
|
|
{
|
|
|
|
mResult = NS_OK;
|
|
|
|
}
|
|
|
|
~nsAsyncRedirectAutoCallback()
|
|
|
|
{
|
|
|
|
if (mCallback)
|
|
|
|
mCallback->OnRedirectVerifyCallback(mResult);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Call this is you want it to call back with a different result-code
|
|
|
|
*/
|
|
|
|
void SetResult(nsresult aRes)
|
|
|
|
{
|
|
|
|
mResult = aRes;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Call this is you want to avoid the callback
|
|
|
|
*/
|
|
|
|
void DontCallback()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mCallback = nullptr;
|
2010-08-05 06:15:55 +04:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsIAsyncVerifyRedirectCallback* mCallback;
|
|
|
|
nsresult mResult;
|
2010-07-28 22:33:06 +04:00
|
|
|
};
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2010-07-28 22:33:06 +04:00
|
|
|
#endif
|