Added nsINetContainerApplication interface and a way to get the user agent, etc. from the containing application
git-svn-id: svn://10.0.0.236/trunk@4849 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
3723c3cdee
commit
eedd12e63c
@ -7,3 +7,4 @@ nsINetService.h
|
|||||||
nsIURL.h
|
nsIURL.h
|
||||||
nsIPostToServer.h
|
nsIPostToServer.h
|
||||||
nsIHttpUrl.h
|
nsIHttpUrl.h
|
||||||
|
nsINetContainerApplication.h
|
||||||
|
|||||||
@ -38,6 +38,7 @@ EXPORTS = nsIStreamListener.h \
|
|||||||
nsIURL.h \
|
nsIURL.h \
|
||||||
nsIPostToServer.h \
|
nsIPostToServer.h \
|
||||||
nsIHttpUrl.h \
|
nsIHttpUrl.h \
|
||||||
|
nsINetContainerApplication.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
include $(DEPTH)/config/config.mk
|
include $(DEPTH)/config/config.mk
|
||||||
|
|||||||
@ -27,6 +27,7 @@ EXPORTS = nsIStreamListener.h \
|
|||||||
nsIURL.h \
|
nsIURL.h \
|
||||||
nsIPostToServer.h \
|
nsIPostToServer.h \
|
||||||
nsIHttpUrl.h \
|
nsIHttpUrl.h \
|
||||||
|
nsINetContainerApplication.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
DIRS = tests
|
DIRS = tests
|
||||||
|
|||||||
78
mozilla/network/module/nsINetContainerApplication.h
Normal file
78
mozilla/network/module/nsINetContainerApplication.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsINetContainerApplication_h__
|
||||||
|
#define nsINetContainerApplication_h__
|
||||||
|
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
|
||||||
|
#define NS_INETCONTAINERAPPLICATION_IID \
|
||||||
|
{ 0xca2610f0, 0x1054, 0x11d2, \
|
||||||
|
{ 0xb3, 0x26, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59 } }
|
||||||
|
|
||||||
|
class nsINetContainerApplication : public nsISupports {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the application name string that will be used as part
|
||||||
|
* of a HTTP request.
|
||||||
|
*
|
||||||
|
* @param aAppCodeName The application name string.
|
||||||
|
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||||
|
*/
|
||||||
|
NS_IMETHOD GetAppCodeName(nsString& aAppCodeName)=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the application version string that will be used as part
|
||||||
|
* of a HTTP request.
|
||||||
|
*
|
||||||
|
* @param aAppVersion The application version string.
|
||||||
|
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||||
|
*/
|
||||||
|
NS_IMETHOD GetAppVersion(nsString& aAppVersion)=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the application name.
|
||||||
|
*
|
||||||
|
* @param aAppName The application name.
|
||||||
|
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||||
|
*/
|
||||||
|
NS_IMETHOD GetAppName(nsString& aAppName)=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the translation of the application. The value for language
|
||||||
|
* is usually a 2-letter code such as "en" and occasionally a
|
||||||
|
* five-character code to indicate a language subtype, such as "zh_CN".
|
||||||
|
*
|
||||||
|
* @param aLanguage The application language.
|
||||||
|
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||||
|
*/
|
||||||
|
NS_IMETHOD GetLanguage(nsString& aLanguage)=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current platform (machine type).
|
||||||
|
*
|
||||||
|
* @param aPlatform The current platform.
|
||||||
|
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||||
|
*/
|
||||||
|
NS_IMETHOD GetPlatform(nsString& aPlatform)=0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsINetContainerApplication_h__
|
||||||
@ -34,6 +34,7 @@
|
|||||||
{ 0xcfb1a480, 0xc78f, 0x11d1, \
|
{ 0xcfb1a480, 0xc78f, 0x11d1, \
|
||||||
{0xbe, 0xa2, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
|
{0xbe, 0xa2, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
|
||||||
|
|
||||||
|
class nsINetContainerApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The nsINetService interface provides an API to the networking service.
|
* The nsINetService interface provides an API to the networking service.
|
||||||
@ -67,6 +68,15 @@ struct nsINetService : public nsISupports
|
|||||||
NS_IMETHOD OpenBlockingStream(nsIURL *aUrl,
|
NS_IMETHOD OpenBlockingStream(nsIURL *aUrl,
|
||||||
nsIStreamListener *aConsumer,
|
nsIStreamListener *aConsumer,
|
||||||
nsIInputStream **aNewStream) = 0;
|
nsIInputStream **aNewStream) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the container application for the net service.
|
||||||
|
*
|
||||||
|
* @param aContainer An output parameter to receive the container
|
||||||
|
* application.
|
||||||
|
* @return Returns NS_OK if successful, or NS_FALSE if an error occurred.
|
||||||
|
*/
|
||||||
|
NS_IMETHOD GetContainerApplication(nsINetContainerApplication **aContainer)=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -77,4 +87,8 @@ struct nsINetService : public nsISupports
|
|||||||
extern "C" NS_NET nsresult NS_NewINetService(nsINetService** aInstancePtrResult,
|
extern "C" NS_NET nsresult NS_NewINetService(nsINetService** aInstancePtrResult,
|
||||||
nsISupports* aOuter);
|
nsISupports* aOuter);
|
||||||
|
|
||||||
|
extern "C" NS_NET nsresult NS_InitINetService(nsINetContainerApplication *aContainer);
|
||||||
|
|
||||||
|
extern "C" NS_NET nsresult NS_ShutdownINetService();
|
||||||
|
|
||||||
#endif /* nsINetService_h___ */
|
#endif /* nsINetService_h___ */
|
||||||
|
|||||||
@ -20,9 +20,11 @@
|
|||||||
#include "nsNetStream.h"
|
#include "nsNetStream.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "mktrace.h"
|
#include "mktrace.h"
|
||||||
|
#include "plstr.h"
|
||||||
|
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsIProtocolConnection.h"
|
#include "nsIProtocolConnection.h"
|
||||||
|
#include "nsINetContainerApplication.h"
|
||||||
|
|
||||||
/* XXX: Legacy definitions... */
|
/* XXX: Legacy definitions... */
|
||||||
MWContext *new_stub_context();
|
MWContext *new_stub_context();
|
||||||
@ -64,10 +66,10 @@ extern "C" void NET_ClientProtocolInitialize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NS_DEFINE_IID(kIProtocolConnectionIID, NS_IPROTOCOLCONNECTION_IID);
|
static NS_DEFINE_IID(kIProtocolConnectionIID, NS_IPROTOCOLCONNECTION_IID);
|
||||||
|
static NS_DEFINE_IID(kINetContainerApplicationIID, NS_INETCONTAINERAPPLICATION_IID);
|
||||||
|
|
||||||
|
|
||||||
|
nsNetlibService::nsNetlibService(nsINetContainerApplication *aContainerApp)
|
||||||
nsNetlibService::nsNetlibService()
|
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
|
||||||
@ -76,9 +78,42 @@ nsNetlibService::nsNetlibService()
|
|||||||
/* Initialize netlib with 32 sockets... */
|
/* Initialize netlib with 32 sockets... */
|
||||||
NET_InitNetLib(0, 32);
|
NET_InitNetLib(0, 32);
|
||||||
|
|
||||||
/* XXX: How should the User Agent get initialized? */
|
mContainer = aContainerApp;
|
||||||
XP_AppCodeName = strdup("Mozilla");
|
NS_IF_ADDREF(mContainer);
|
||||||
XP_AppVersion = strdup("5.0 Netscape/5.0 (Windows;I;x86;en)");
|
if (NULL != mContainer) {
|
||||||
|
nsAutoString str;
|
||||||
|
|
||||||
|
mContainer->GetAppCodeName(str);
|
||||||
|
XP_AppCodeName = str.ToNewCString();
|
||||||
|
mContainer->GetAppVersion(str);
|
||||||
|
XP_AppVersion = str.ToNewCString();
|
||||||
|
mContainer->GetAppName(str);
|
||||||
|
XP_AppName = str.ToNewCString();
|
||||||
|
mContainer->GetPlatform(str);
|
||||||
|
XP_AppPlatform = str.ToNewCString();
|
||||||
|
mContainer->GetLanguage(str);
|
||||||
|
XP_AppLanguage = str.ToNewCString();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// XXX: Where should the defaults really come from
|
||||||
|
XP_AppCodeName = PL_strdup("Mozilla");
|
||||||
|
XP_AppVersion = PL_strdup("5.0 Netscape/5.0 (Windows;I;x86;en)");
|
||||||
|
XP_AppName = PL_strdup("Netscape");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX: Some of these should come from resources and/or
|
||||||
|
* platform-specific code.
|
||||||
|
*/
|
||||||
|
XP_AppLanguage = PL_strdup("en");
|
||||||
|
#ifdef XP_WIN
|
||||||
|
XP_AppPlatform = PL_strdup("Win32");
|
||||||
|
#elif defined(XP_MAC)
|
||||||
|
XP_AppPlatform = PL_strdup("MacPPC");
|
||||||
|
#elif defined(XP_UNIX)
|
||||||
|
/* XXX: Need to differentiate between various Unisys */
|
||||||
|
XP_AppPlatform = PL_strdup("Unix");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -94,7 +129,8 @@ nsNetlibService::~nsNetlibService()
|
|||||||
free_stub_context((MWContext *)m_stubContext);
|
free_stub_context((MWContext *)m_stubContext);
|
||||||
m_stubContext = NULL;
|
m_stubContext = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IF_RELEASE(mContainer);
|
||||||
NET_ShutdownNetLib();
|
NET_ShutdownNetLib();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,32 +291,99 @@ loser:
|
|||||||
return NS_FALSE;
|
return NS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsNetlibService::GetContainerApplication(nsINetContainerApplication **aContainer)
|
||||||
|
{
|
||||||
|
*aContainer = mContainer;
|
||||||
|
|
||||||
|
NS_IF_ADDREF(mContainer);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsNetlibService::SetContainerApplication(nsINetContainerApplication *aContainer)
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mContainer);
|
||||||
|
|
||||||
|
mContainer = aContainer;
|
||||||
|
|
||||||
|
NS_IF_ADDREF(mContainer);
|
||||||
|
|
||||||
|
if (mContainer) {
|
||||||
|
nsAutoString str;
|
||||||
|
|
||||||
|
PR_FREEIF(XP_AppCodeName);
|
||||||
|
mContainer->GetAppCodeName(str);
|
||||||
|
XP_AppCodeName = str.ToNewCString();
|
||||||
|
PR_FREEIF(XP_AppVersion);
|
||||||
|
mContainer->GetAppVersion(str);
|
||||||
|
XP_AppVersion = str.ToNewCString();
|
||||||
|
PR_FREEIF(XP_AppName);
|
||||||
|
mContainer->GetAppName(str);
|
||||||
|
XP_AppName = str.ToNewCString();
|
||||||
|
PR_FREEIF(XP_AppPlatform);
|
||||||
|
mContainer->GetPlatform(str);
|
||||||
|
XP_AppPlatform = str.ToNewCString();
|
||||||
|
PR_FREEIF(XP_AppLanguage);
|
||||||
|
mContainer->GetLanguage(str);
|
||||||
|
XP_AppLanguage = str.ToNewCString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
static nsNetlibService *pNetlib = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Factory for creating instance of the NetlibService...
|
* Factory for creating instance of the NetlibService...
|
||||||
*/
|
*/
|
||||||
NS_NET nsresult NS_NewINetService(nsINetService** aInstancePtrResult,
|
NS_NET nsresult NS_NewINetService(nsINetService** aInstancePtrResult,
|
||||||
nsISupports* aOuter)
|
nsISupports* aOuter)
|
||||||
{
|
{
|
||||||
static nsNetlibService *pNetlib = NULL;
|
|
||||||
|
|
||||||
if (NULL != aOuter) {
|
if (NULL != aOuter) {
|
||||||
return NS_ERROR_NO_AGGREGATION;
|
return NS_ERROR_NO_AGGREGATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: For now only allow a single instance of the Netlib Service */
|
|
||||||
if (NULL == pNetlib) {
|
if (NULL == pNetlib) {
|
||||||
pNetlib = new nsNetlibService();
|
nsresult res;
|
||||||
}
|
res = NS_InitINetService(NULL);
|
||||||
|
if (NS_OK != res) {
|
||||||
if (NULL == pNetlib) {
|
return res;
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pNetlib->QueryInterface(kINetServiceIID, (void**)aInstancePtrResult);
|
return pNetlib->QueryInterface(kINetServiceIID, (void**)aInstancePtrResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_NET nsresult NS_InitINetService(nsINetContainerApplication *aContainer)
|
||||||
|
{
|
||||||
|
/* XXX: For now only allow a single instance of the Netlib Service */
|
||||||
|
if (NULL == pNetlib) {
|
||||||
|
pNetlib = new nsNetlibService(aContainer);
|
||||||
|
if (NULL == pNetlib) {
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pNetlib->SetContainerApplication(aContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_ADDREF(pNetlib);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_NET nsresult NS_ShutdownINetService()
|
||||||
|
{
|
||||||
|
nsNetlibService *service = pNetlib;
|
||||||
|
|
||||||
|
NS_IF_RELEASE(service);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
}; /* extern "C" */
|
}; /* extern "C" */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -22,12 +22,14 @@
|
|||||||
#include "nspr.h"
|
#include "nspr.h"
|
||||||
#include "nsINetService.h"
|
#include "nsINetService.h"
|
||||||
|
|
||||||
|
class nsINetContainerApplication;
|
||||||
|
|
||||||
class nsNetlibService : public nsINetService {
|
class nsNetlibService : public nsINetService {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
nsNetlibService();
|
nsNetlibService(nsINetContainerApplication *aContainer);
|
||||||
|
|
||||||
/* Implementation of the nsINetService interface */
|
/* Implementation of the nsINetService interface */
|
||||||
NS_IMETHOD OpenStream(nsIURL *aUrl, nsIStreamListener *aConsumer);
|
NS_IMETHOD OpenStream(nsIURL *aUrl, nsIStreamListener *aConsumer);
|
||||||
@ -35,12 +37,16 @@ public:
|
|||||||
nsIStreamListener *aConsumer,
|
nsIStreamListener *aConsumer,
|
||||||
nsIInputStream **aNewStream);
|
nsIInputStream **aNewStream);
|
||||||
|
|
||||||
|
NS_IMETHOD GetContainerApplication(nsINetContainerApplication **aContainer);
|
||||||
|
nsresult SetContainerApplication(nsINetContainerApplication *aContainer);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~nsNetlibService();
|
virtual ~nsNetlibService();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* XXX: This is temporary until bamwrap.cpp is removed... */
|
/* XXX: This is temporary until bamwrap.cpp is removed... */
|
||||||
void *m_stubContext;
|
void *m_stubContext;
|
||||||
|
nsINetContainerApplication *mContainer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user