From 78dddd29b1c266951e87eb801691ed46fff9a96b Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Tue, 1 Sep 1998 00:17:25 +0000 Subject: [PATCH] Added FindProxyForURL. git-svn-id: svn://10.0.0.236/trunk@8916 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/plugin/bad/badapter.cpp | 8 ++ .../plugin/base/public/nsINetworkManager.h | 16 +++ .../plugin/base/src/nsPluginHostImpl.cpp | 8 +- .../plugin/base/src/nsPluginHostImpl.h | 3 + .../plugin/nglsrc/nsPluginHostImpl.cpp | 8 +- .../modules/plugin/nglsrc/nsPluginHostImpl.h | 3 + .../modules/plugin/public/nsINetworkManager.h | 16 +++ .../plugin/samples/backward/badapter.cpp | 8 ++ mozilla/modules/plugin/src/npglue.h | 10 +- mozilla/modules/plugin/src/nsplugin.cpp | 115 +++++++++++------- 10 files changed, 148 insertions(+), 47 deletions(-) diff --git a/mozilla/modules/plugin/bad/badapter.cpp b/mozilla/modules/plugin/bad/badapter.cpp index 2c96269ba27..15f3cb3a263 100644 --- a/mozilla/modules/plugin/bad/badapter.cpp +++ b/mozilla/modules/plugin/bad/badapter.cpp @@ -85,6 +85,9 @@ public: PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); + NS_IMETHOD + FindProxyForURL(const char* url, char* *result); + }; //////////////////////////////////////////////////////////////////////////////// @@ -1006,6 +1009,11 @@ CPluginManager::PostURL(nsISupports* peer, const char* url, const char* target, return fromNPError[err]; } +NS_METHOD +CPluginManager::FindProxyForURL(const char* url, char* *result) +{ + return NS_ERROR_FAILURE; +} //+++++++++++++++++++++++++++++++++++++++++++++++++ // UserAgent: diff --git a/mozilla/modules/plugin/base/public/nsINetworkManager.h b/mozilla/modules/plugin/base/public/nsINetworkManager.h index 0e67c56e6f0..202f358e12c 100644 --- a/mozilla/modules/plugin/base/public/nsINetworkManager.h +++ b/mozilla/modules/plugin/base/public/nsINetworkManager.h @@ -103,6 +103,22 @@ public: PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0; + /** + * Returns the proxy info for a given URL. The caller is required to + * free the resulting memory with nsIMalloc::Free. The result will be in the + * following format + * + * i) "DIRECT" -- no proxy + * ii) "PROXY xxx.xxx.xxx.xxx" -- use proxy + * iii) "SOCKS xxx.xxx.xxx.xxx" -- use SOCKS + * iv) Mixed. e.g. "PROXY 111.111.111.111;PROXY 112.112.112.112", + * "PROXY 111.111.111.111;SOCKS 112.112.112.112".... + * + * Which proxy/SOCKS to use is determined by the plugin. + */ + NS_IMETHOD + FindProxyForURL(const char* url, char* *result) = 0; + }; #define NS_INETWORKMANAGER_IID \ diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 79ad458e027..bedaee55505 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -515,7 +515,13 @@ NS_IMETHODIMP nsPluginHostImpl :: PostURL(nsISupports* peer, PRBool forceJSEnabled, PRUint32 postHeadersLength, const char* postHeaders) { - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginHostImpl::FindProxyForURL(const char* url, char* *result) +{ + return NS_ERROR_NOT_IMPLEMENTED; } nsresult nsPluginHostImpl :: Init(void) diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h index 8dd27edfd3e..28d7c527d65 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.h @@ -98,6 +98,9 @@ public: PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); + NS_IMETHOD + FindProxyForURL(const char* url, char* *result); + //nsIPluginHost interface NS_IMETHOD diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp index 79ad458e027..bedaee55505 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp @@ -515,7 +515,13 @@ NS_IMETHODIMP nsPluginHostImpl :: PostURL(nsISupports* peer, PRBool forceJSEnabled, PRUint32 postHeadersLength, const char* postHeaders) { - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginHostImpl::FindProxyForURL(const char* url, char* *result) +{ + return NS_ERROR_NOT_IMPLEMENTED; } nsresult nsPluginHostImpl :: Init(void) diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h index 8dd27edfd3e..28d7c527d65 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.h @@ -98,6 +98,9 @@ public: PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); + NS_IMETHOD + FindProxyForURL(const char* url, char* *result); + //nsIPluginHost interface NS_IMETHOD diff --git a/mozilla/modules/plugin/public/nsINetworkManager.h b/mozilla/modules/plugin/public/nsINetworkManager.h index 0e67c56e6f0..202f358e12c 100644 --- a/mozilla/modules/plugin/public/nsINetworkManager.h +++ b/mozilla/modules/plugin/public/nsINetworkManager.h @@ -103,6 +103,22 @@ public: PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL) = 0; + /** + * Returns the proxy info for a given URL. The caller is required to + * free the resulting memory with nsIMalloc::Free. The result will be in the + * following format + * + * i) "DIRECT" -- no proxy + * ii) "PROXY xxx.xxx.xxx.xxx" -- use proxy + * iii) "SOCKS xxx.xxx.xxx.xxx" -- use SOCKS + * iv) Mixed. e.g. "PROXY 111.111.111.111;PROXY 112.112.112.112", + * "PROXY 111.111.111.111;SOCKS 112.112.112.112".... + * + * Which proxy/SOCKS to use is determined by the plugin. + */ + NS_IMETHOD + FindProxyForURL(const char* url, char* *result) = 0; + }; #define NS_INETWORKMANAGER_IID \ diff --git a/mozilla/modules/plugin/samples/backward/badapter.cpp b/mozilla/modules/plugin/samples/backward/badapter.cpp index 2c96269ba27..15f3cb3a263 100644 --- a/mozilla/modules/plugin/samples/backward/badapter.cpp +++ b/mozilla/modules/plugin/samples/backward/badapter.cpp @@ -85,6 +85,9 @@ public: PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); + NS_IMETHOD + FindProxyForURL(const char* url, char* *result); + }; //////////////////////////////////////////////////////////////////////////////// @@ -1006,6 +1009,11 @@ CPluginManager::PostURL(nsISupports* peer, const char* url, const char* target, return fromNPError[err]; } +NS_METHOD +CPluginManager::FindProxyForURL(const char* url, char* *result) +{ + return NS_ERROR_FAILURE; +} //+++++++++++++++++++++++++++++++++++++++++++++++++ // UserAgent: diff --git a/mozilla/modules/plugin/src/npglue.h b/mozilla/modules/plugin/src/npglue.h index 987ce4af373..d90bfdb9714 100644 --- a/mozilla/modules/plugin/src/npglue.h +++ b/mozilla/modules/plugin/src/npglue.h @@ -366,6 +366,9 @@ public: PRBool forceJSEnabled = PR_FALSE, PRUint32 postHeadersLength = 0, const char* postHeaders = NULL); + NS_IMETHOD + FindProxyForURL(const char* url, char* *result); + //////////////////////////////////////////////////////////////////////////// // nsPluginManager specific methods: @@ -379,10 +382,10 @@ protected: virtual ~nsPluginManager(void); // aggregated interfaces: - nsIJVMManager* GetJVMMgr(const nsIID& aIID); - nsISupports* fJVMMgr; nsISupports* fMalloc; + nsISupports* fFileUtils; + PRUint16 fWaiting; void* fOldCursor; @@ -416,6 +419,9 @@ public: NS_DECL_AGGREGATED + static NS_METHOD + Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr); + void SetProgramPath(const char* path) { fProgramPath = path; } protected: diff --git a/mozilla/modules/plugin/src/nsplugin.cpp b/mozilla/modules/plugin/src/nsplugin.cpp index f25416a4edf..0ffc29cd078 100644 --- a/mozilla/modules/plugin/src/nsplugin.cpp +++ b/mozilla/modules/plugin/src/nsplugin.cpp @@ -100,17 +100,25 @@ nsresult fromNPError[] = { nsPluginManager* thePluginManager = NULL; nsPluginManager::nsPluginManager(nsISupports* outer) - : fJVMMgr(NULL), fMalloc(NULL), fAllocatedMenuIDs(NULL) + : fJVMMgr(NULL), fMalloc(NULL), fFileUtils(NULL), fAllocatedMenuIDs(NULL) { NS_INIT_AGGREGATED(outer); } nsPluginManager::~nsPluginManager(void) { - fJVMMgr->Release(); - fJVMMgr = NULL; - fMalloc->Release(); - fMalloc = NULL; + if (fJVMMgr) { + fJVMMgr->Release(); + fJVMMgr = NULL; + } + if (fMalloc) { + fMalloc->Release(); + fMalloc = NULL; + } + if (fFileUtils) { + fFileUtils->Release(); + fFileUtils = NULL; + } #ifdef XP_MAC if (fAllocatedMenuIDs != NULL) { @@ -128,11 +136,11 @@ nsPluginManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInstanceP if (outer && !aIID.Equals(kISupportsIID)) return NS_NOINTERFACE; // XXX right error? nsPluginManager* mgr = new nsPluginManager(outer); - nsresult result = mgr->QueryInterface(aIID, aInstancePtr); - if (result != NS_OK) { - delete mgr; - } - return result; + if (mgr == NULL) + return NS_ERROR_OUT_OF_MEMORY; + mgr->AddRef(); + *aInstancePtr = mgr->GetInner(); + return NS_OK; } NS_METHOD @@ -198,35 +206,28 @@ nsPluginManager::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr return NS_OK; } #endif - // Aggregates... - nsIJVMManager* jvmMgr = GetJVMMgr(aIID); - if (jvmMgr) { - *aInstancePtr = (void*) ((nsISupports*)jvmMgr); - return NS_OK; - } - if (fMalloc == NULL) { - if (nsMalloc::Create((nsIPluginManager*)this, kISupportsIID, - (void**)&fMalloc) != NS_OK) - return NS_NOINTERFACE; - } - return fMalloc->QueryInterface(aIID, aInstancePtr); -} -nsIJVMManager* -nsPluginManager::GetJVMMgr(const nsIID& aIID) -{ - nsIJVMManager* result = NULL; + // Aggregates... #ifdef OJI - if (fJVMMgr == NULL) { - // The plugin manager is the outer of the JVM manager - if (nsJVMMgr::Create((nsIPluginManager*)this, kISupportsIID, - (void**)&fJVMMgr) != NS_OK) - return NULL; - } - if (fJVMMgr->QueryInterface(aIID, (void**)&result) != NS_OK) - return NULL; + if (fJVMMgr == NULL) + nsJVMMgr::Create((nsIPluginManager*)this, kISupportsIID, + (void**)&fJVMMgr); + if (fJVMMgr && fJVMMgr->QueryInterface(aIID, aInstancePtr) == NS_OK) + return NS_OK; #endif - return result; + if (fMalloc == NULL) + nsMalloc::Create((nsIPluginManager*)this, kISupportsIID, + (void**)&fMalloc); + if (fMalloc && fMalloc->QueryInterface(aIID, aInstancePtr) == NS_OK) + return NS_OK; + + if (fFileUtils == NULL) + nsFileUtilities::Create((nsIPluginManager*)this, kISupportsIID, + (void**)&fFileUtils); + if (fFileUtils && fFileUtils->QueryInterface(aIID, aInstancePtr) == NS_OK) + return NS_OK; + + return NS_NOINTERFACE; } NS_METHOD @@ -630,6 +631,22 @@ nsPluginManager::PostURL(nsISupports* peer, const char* url, const char* target, return fromNPError[rslt]; } +extern "C" char *pacf_find_proxies_for_url(MWContext *context, + URL_Struct *URL_s); + +NS_METHOD +nsPluginManager::FindProxyForURL(const char* url, char* *result) +{ + // Warning: Looking at the code in mkautocf.c, the context can + // (fortunately) be NULL. + URL_Struct* urls = NET_CreateURLStruct(url, NET_DONT_RELOAD); + if (urls == NULL) + return NS_ERROR_OUT_OF_MEMORY; + *result = pacf_find_proxies_for_url(NULL, urls); + NET_FreeURLStruct(urls); + return NS_OK; +} + //////////////////////////////////////////////////////////////////////////////// // File Utilities Interface @@ -660,6 +677,18 @@ nsFileUtilities::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr return NS_NOINTERFACE; } +NS_METHOD +nsFileUtilities::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) +{ + if (outer && !aIID.Equals(kISupportsIID)) + return NS_NOINTERFACE; // XXX right error? + nsFileUtilities* fu = new nsFileUtilities(outer); + if (fu == NULL) + return NS_ERROR_OUT_OF_MEMORY; + fu->AddRef(); + *aInstancePtr = fu->GetInner(); + return NS_OK; +} NS_METHOD nsFileUtilities::GetProgramPath(const char* *result) @@ -933,14 +962,14 @@ nsPluginTagInfo::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr } #ifdef OJI // Aggregates... - if (fJVMPluginTagInfo == NULL) { - nsresult result = - nsJVMPluginTagInfo::Create((nsISupports*)this, kISupportsIID, - (void**)&fJVMPluginTagInfo, this); - if (result != NS_OK) return result; - } + if (fJVMPluginTagInfo == NULL) + nsJVMPluginTagInfo::Create((nsISupports*)this, kISupportsIID, + (void**)&fJVMPluginTagInfo, this); + if (fJVMPluginTagInfo && + fJVMPluginTagInfo->QueryInterface(aIID, aInstancePtr) == NS_OK) + return NS_OK; #endif - return fJVMPluginTagInfo->QueryInterface(aIID, aInstancePtr); + return NS_NOINTERFACE; } static char* empty_list[] = { "", NULL };