2005-03-25 03:41:33 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 11:12:37 +00: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/. */
|
2005-03-25 03:41:33 +00:00
|
|
|
|
|
|
|
#ifndef nsPACMan_h__
|
|
|
|
#define nsPACMan_h__
|
|
|
|
|
|
|
|
#include "nsIStreamLoader.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2005-06-30 20:21:34 +00:00
|
|
|
#include "nsIChannelEventSink.h"
|
2005-03-25 03:41:33 +00:00
|
|
|
#include "nsIProxyAutoConfig.h"
|
2005-06-30 20:21:34 +00:00
|
|
|
#include "nsIURI.h"
|
2005-03-25 03:41:33 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "prclist.h"
|
2012-06-06 03:18:25 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2005-03-25 03:41:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class defines a callback interface used by AsyncGetProxyForURI.
|
|
|
|
*/
|
|
|
|
class NS_NO_VTABLE nsPACManCallback : public nsISupports
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* This method is invoked on the same thread that called AsyncGetProxyForURI.
|
|
|
|
*
|
|
|
|
* @param status
|
|
|
|
* This parameter indicates whether or not the PAC query succeeded.
|
|
|
|
* @param pacString
|
|
|
|
* This parameter holds the value of the PAC string. It is empty when
|
|
|
|
* status is a failure code.
|
|
|
|
*/
|
|
|
|
virtual void OnQueryComplete(nsresult status, const nsCString &pacString) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides an abstraction layer above the PAC thread. The methods
|
|
|
|
* defined on this class are intended to be called on the main thread only.
|
|
|
|
*/
|
2012-06-06 03:18:25 +00:00
|
|
|
class nsPACMan MOZ_FINAL : public nsIStreamLoaderObserver
|
|
|
|
, public nsIInterfaceRequestor
|
|
|
|
, public nsIChannelEventSink
|
2005-03-25 03:41:33 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsPACMan();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method may be called to shutdown the PAC manager. Any async queries
|
|
|
|
* that have not yet completed will either finish normally or be canceled by
|
|
|
|
* the time this method returns.
|
|
|
|
*/
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method queries a PAC result synchronously.
|
|
|
|
*
|
|
|
|
* @param uri
|
|
|
|
* The URI to query.
|
|
|
|
* @param result
|
|
|
|
* Holds the PAC result string upon return.
|
|
|
|
*
|
2005-06-24 23:58:25 +00:00
|
|
|
* @return NS_ERROR_IN_PROGRESS if the PAC file is not yet loaded.
|
|
|
|
* @return NS_ERROR_NOT_AVAILABLE if the PAC file could not be loaded.
|
2005-03-25 03:41:33 +00:00
|
|
|
*/
|
|
|
|
nsresult GetProxyForURI(nsIURI *uri, nsACString &result);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method queries a PAC result asynchronously. The callback runs on the
|
|
|
|
* calling thread. If the PAC file has not yet been loaded, then this method
|
|
|
|
* will queue up the request, and complete it once the PAC file has been
|
|
|
|
* loaded.
|
|
|
|
*
|
|
|
|
* @param uri
|
|
|
|
* The URI to query.
|
|
|
|
* @param callback
|
|
|
|
* The callback to run once the PAC result is available.
|
|
|
|
*/
|
|
|
|
nsresult AsyncGetProxyForURI(nsIURI *uri, nsPACManCallback *callback);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method may be called to reload the PAC file. While we are loading
|
|
|
|
* the PAC file, any asynchronous PAC queries will be queued up to be
|
|
|
|
* processed once the PAC file finishes loading.
|
|
|
|
*
|
2005-06-30 20:21:34 +00:00
|
|
|
* @param pacURI
|
2006-06-13 01:14:20 +00:00
|
|
|
* The nsIURI of the PAC file to load. If this parameter is null,
|
|
|
|
* then the previous PAC URI is simply reloaded.
|
2005-03-25 03:41:33 +00:00
|
|
|
*/
|
2005-06-30 20:21:34 +00:00
|
|
|
nsresult LoadPACFromURI(nsIURI *pacURI);
|
2005-03-25 03:41:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if we are currently loading the PAC file.
|
|
|
|
*/
|
2012-07-30 14:20:58 +00:00
|
|
|
bool IsLoading() { return mLoader != nullptr; }
|
2005-03-25 03:41:33 +00:00
|
|
|
|
2008-01-29 18:38:15 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the given URI matches the URI of our PAC file.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsPACURI(nsIURI *uri) {
|
|
|
|
bool result;
|
2008-01-29 18:38:15 +00:00
|
|
|
return mPACURI && NS_SUCCEEDED(mPACURI->Equals(uri, &result)) && result;
|
|
|
|
}
|
|
|
|
|
2005-03-25 03:41:33 +00:00
|
|
|
private:
|
|
|
|
NS_DECL_NSISTREAMLOADEROBSERVER
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2005-06-30 20:21:34 +00:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
2005-03-25 03:41:33 +00:00
|
|
|
|
|
|
|
~nsPACMan();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancel any existing load if any.
|
|
|
|
*/
|
|
|
|
void CancelExistingLoad();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process mPendingQ. If status is a failure code, then the pending queue
|
|
|
|
* will be emptied. If status is a success code, then the pending requests
|
|
|
|
* will be processed (i.e., their Start method will be called).
|
|
|
|
*/
|
|
|
|
void ProcessPendingQ(nsresult status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start loading the PAC file.
|
|
|
|
*/
|
2006-05-10 17:30:15 +00:00
|
|
|
void StartLoading();
|
2005-03-25 03:41:33 +00:00
|
|
|
|
2006-06-13 01:14:20 +00:00
|
|
|
/**
|
|
|
|
* Reload the PAC file if there is reason to.
|
|
|
|
*/
|
|
|
|
void MaybeReloadPAC();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when we fail to load the PAC file.
|
|
|
|
*/
|
|
|
|
void OnLoadFailure();
|
|
|
|
|
2005-03-25 03:41:33 +00:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIProxyAutoConfig> mPAC;
|
2005-06-30 20:21:34 +00:00
|
|
|
nsCOMPtr<nsIURI> mPACURI;
|
2005-03-25 03:41:33 +00:00
|
|
|
PRCList mPendingQ;
|
|
|
|
nsCOMPtr<nsIStreamLoader> mLoader;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mLoadPending;
|
|
|
|
bool mShutdown;
|
2006-06-13 01:14:20 +00:00
|
|
|
PRTime mScheduledReload;
|
|
|
|
PRUint32 mLoadFailureCount;
|
2005-03-25 03:41:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsPACMan_h__
|