зеркало из https://github.com/mozilla/pjs.git
Fixing bug 58095, retrieving right user agent string instead of harcoded one. Goes to the trunk only as per yesterday PDT meeting. r=valeski, r=serge, sr=waterson, a=av
This commit is contained in:
Родитель
f102cde5dd
Коммит
35d797f992
|
@ -30,6 +30,7 @@
|
||||||
#include "nsIPluginStreamListener.h"
|
#include "nsIPluginStreamListener.h"
|
||||||
#include "nsIHTTPHeaderListener.h"
|
#include "nsIHTTPHeaderListener.h"
|
||||||
#include "nsIHTTPHeader.h"
|
#include "nsIHTTPHeader.h"
|
||||||
|
#include "nsIHTTPProtocolHandler.h"
|
||||||
#include "nsIStreamListener.h"
|
#include "nsIStreamListener.h"
|
||||||
#include "nsIInputStream.h"
|
#include "nsIInputStream.h"
|
||||||
#include "nsIOutputStream.h"
|
#include "nsIOutputStream.h"
|
||||||
|
@ -110,14 +111,6 @@
|
||||||
|
|
||||||
#define REL_PLUGIN_DLL "rel:" PLUGIN_DLL
|
#define REL_PLUGIN_DLL "rel:" PLUGIN_DLL
|
||||||
|
|
||||||
//uncomment this to use netlib to determine what the
|
|
||||||
//user agent string is. we really *want* to do this,
|
|
||||||
//can't today since netlib returns 4.05, but this
|
|
||||||
//version of plugin functionality really supports
|
|
||||||
//5.0 level features. once netlib is returning
|
|
||||||
//5.0x, then we can turn this on again. MMP
|
|
||||||
//#define USE_NETLIB_FOR_USER_AGENT
|
|
||||||
|
|
||||||
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
|
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
|
||||||
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
|
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
|
||||||
static NS_DEFINE_IID(kIPluginStreamInfoIID, NS_IPLUGINSTREAMINFO_IID);
|
static NS_DEFINE_IID(kIPluginStreamInfoIID, NS_IPLUGINSTREAMINFO_IID);
|
||||||
|
@ -130,6 +123,7 @@ static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
||||||
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
||||||
|
|
||||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||||
|
static NS_DEFINE_CID(kHTTPHandlerCID, NS_IHTTPHANDLER_CID);
|
||||||
|
|
||||||
static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID);
|
static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID);
|
||||||
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
|
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
|
||||||
|
@ -1543,31 +1537,45 @@ nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages)
|
||||||
return LoadPlugins();
|
return LoadPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NS_RETURN_UASTRING_SIZE 128
|
||||||
|
|
||||||
nsresult nsPluginHostImpl::UserAgent(const char **retstring)
|
nsresult nsPluginHostImpl::UserAgent(const char **retstring)
|
||||||
{
|
{
|
||||||
|
static char resultString[NS_RETURN_UASTRING_SIZE];
|
||||||
nsresult res;
|
nsresult res;
|
||||||
|
|
||||||
#ifdef USE_NETLIB_FOR_USER_AGENT
|
nsCOMPtr<nsIHTTPProtocolHandler> http = do_GetService(kHTTPHandlerCID, &res);
|
||||||
nsString ua;
|
if (NS_FAILED(res))
|
||||||
nsINetService *service = nsnull;
|
return res;
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &res);
|
PRUnichar *UAString = nsnull;
|
||||||
|
res = http->GetUserAgent(&UAString);
|
||||||
|
|
||||||
if ((NS_OK == res) && (nsnull != service))
|
if (NS_SUCCEEDED(res))
|
||||||
{
|
{
|
||||||
res = service->GetUserAgent(ua);
|
nsAutoString ua(UAString);
|
||||||
|
char * newString = ua.ToNewCString();
|
||||||
if (NS_OK == res)
|
if (!newString)
|
||||||
*retstring = ua.ToNewCString();
|
{
|
||||||
else
|
|
||||||
*retstring = nsnull;
|
*retstring = nsnull;
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(NS_RETURN_UASTRING_SIZE > PL_strlen(newString))
|
||||||
|
{
|
||||||
|
PL_strcpy(resultString, newString);
|
||||||
|
*retstring = resultString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*retstring = nsnull;
|
||||||
|
res = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
NS_RELEASE(service);
|
nsCRT::free(newString);
|
||||||
}
|
}
|
||||||
#else //TODO fix this -Gagan
|
else
|
||||||
*retstring = (const char *)"Mozilla/5.0 [en] (Windows;I)";
|
*retstring = nsnull;
|
||||||
res = NS_OK;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "nsIPluginStreamListener.h"
|
#include "nsIPluginStreamListener.h"
|
||||||
#include "nsIHTTPHeaderListener.h"
|
#include "nsIHTTPHeaderListener.h"
|
||||||
#include "nsIHTTPHeader.h"
|
#include "nsIHTTPHeader.h"
|
||||||
|
#include "nsIHTTPProtocolHandler.h"
|
||||||
#include "nsIStreamListener.h"
|
#include "nsIStreamListener.h"
|
||||||
#include "nsIInputStream.h"
|
#include "nsIInputStream.h"
|
||||||
#include "nsIOutputStream.h"
|
#include "nsIOutputStream.h"
|
||||||
|
@ -110,14 +111,6 @@
|
||||||
|
|
||||||
#define REL_PLUGIN_DLL "rel:" PLUGIN_DLL
|
#define REL_PLUGIN_DLL "rel:" PLUGIN_DLL
|
||||||
|
|
||||||
//uncomment this to use netlib to determine what the
|
|
||||||
//user agent string is. we really *want* to do this,
|
|
||||||
//can't today since netlib returns 4.05, but this
|
|
||||||
//version of plugin functionality really supports
|
|
||||||
//5.0 level features. once netlib is returning
|
|
||||||
//5.0x, then we can turn this on again. MMP
|
|
||||||
//#define USE_NETLIB_FOR_USER_AGENT
|
|
||||||
|
|
||||||
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
|
static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID);
|
||||||
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
|
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
|
||||||
static NS_DEFINE_IID(kIPluginStreamInfoIID, NS_IPLUGINSTREAMINFO_IID);
|
static NS_DEFINE_IID(kIPluginStreamInfoIID, NS_IPLUGINSTREAMINFO_IID);
|
||||||
|
@ -130,6 +123,7 @@ static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
||||||
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
||||||
|
|
||||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||||
|
static NS_DEFINE_CID(kHTTPHandlerCID, NS_IHTTPHANDLER_CID);
|
||||||
|
|
||||||
static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID);
|
static NS_DEFINE_IID(kIFileUtilitiesIID, NS_IFILEUTILITIES_IID);
|
||||||
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
|
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
|
||||||
|
@ -1543,31 +1537,45 @@ nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages)
|
||||||
return LoadPlugins();
|
return LoadPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NS_RETURN_UASTRING_SIZE 128
|
||||||
|
|
||||||
nsresult nsPluginHostImpl::UserAgent(const char **retstring)
|
nsresult nsPluginHostImpl::UserAgent(const char **retstring)
|
||||||
{
|
{
|
||||||
|
static char resultString[NS_RETURN_UASTRING_SIZE];
|
||||||
nsresult res;
|
nsresult res;
|
||||||
|
|
||||||
#ifdef USE_NETLIB_FOR_USER_AGENT
|
nsCOMPtr<nsIHTTPProtocolHandler> http = do_GetService(kHTTPHandlerCID, &res);
|
||||||
nsString ua;
|
if (NS_FAILED(res))
|
||||||
nsINetService *service = nsnull;
|
return res;
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &res);
|
PRUnichar *UAString = nsnull;
|
||||||
|
res = http->GetUserAgent(&UAString);
|
||||||
|
|
||||||
if ((NS_OK == res) && (nsnull != service))
|
if (NS_SUCCEEDED(res))
|
||||||
{
|
{
|
||||||
res = service->GetUserAgent(ua);
|
nsAutoString ua(UAString);
|
||||||
|
char * newString = ua.ToNewCString();
|
||||||
if (NS_OK == res)
|
if (!newString)
|
||||||
*retstring = ua.ToNewCString();
|
{
|
||||||
else
|
|
||||||
*retstring = nsnull;
|
*retstring = nsnull;
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(NS_RETURN_UASTRING_SIZE > PL_strlen(newString))
|
||||||
|
{
|
||||||
|
PL_strcpy(resultString, newString);
|
||||||
|
*retstring = resultString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*retstring = nsnull;
|
||||||
|
res = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
NS_RELEASE(service);
|
nsCRT::free(newString);
|
||||||
}
|
}
|
||||||
#else //TODO fix this -Gagan
|
else
|
||||||
*retstring = (const char *)"Mozilla/5.0 [en] (Windows;I)";
|
*retstring = nsnull;
|
||||||
res = NS_OK;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче