Added nsINetContainerApplication interface and a way to get the user agent, etc. from the containing application

This commit is contained in:
vidur 1998-07-01 23:56:20 +00:00
parent e611df65a1
commit 243f875b26
7 changed files with 219 additions and 15 deletions

View File

@ -7,3 +7,4 @@ nsINetService.h
nsIURL.h
nsIPostToServer.h
nsIHttpUrl.h
nsINetContainerApplication.h

View File

@ -38,6 +38,7 @@ EXPORTS = nsIStreamListener.h \
nsIURL.h \
nsIPostToServer.h \
nsIHttpUrl.h \
nsINetContainerApplication.h \
$(NULL)
include $(DEPTH)/config/config.mk

View File

@ -27,6 +27,7 @@ EXPORTS = nsIStreamListener.h \
nsIURL.h \
nsIPostToServer.h \
nsIHttpUrl.h \
nsINetContainerApplication.h \
$(NULL)
DIRS = tests

View 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__

View File

@ -34,6 +34,7 @@
{ 0xcfb1a480, 0xc78f, 0x11d1, \
{0xbe, 0xa2, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
class nsINetContainerApplication;
/**
* The nsINetService interface provides an API to the networking service.
@ -67,6 +68,15 @@ struct nsINetService : public nsISupports
NS_IMETHOD OpenBlockingStream(nsIURL *aUrl,
nsIStreamListener *aConsumer,
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,
nsISupports* aOuter);
extern "C" NS_NET nsresult NS_InitINetService(nsINetContainerApplication *aContainer);
extern "C" NS_NET nsresult NS_ShutdownINetService();
#endif /* nsINetService_h___ */

View File

@ -20,9 +20,11 @@
#include "nsNetStream.h"
#include "net.h"
#include "mktrace.h"
#include "plstr.h"
#include "nsString.h"
#include "nsIProtocolConnection.h"
#include "nsINetContainerApplication.h"
/* XXX: Legacy definitions... */
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(kINetContainerApplicationIID, NS_INETCONTAINERAPPLICATION_IID);
nsNetlibService::nsNetlibService()
nsNetlibService::nsNetlibService(nsINetContainerApplication *aContainerApp)
{
NS_INIT_REFCNT();
@ -76,9 +78,42 @@ nsNetlibService::nsNetlibService()
/* Initialize netlib with 32 sockets... */
NET_InitNetLib(0, 32);
/* XXX: How should the User Agent get initialized? */
XP_AppCodeName = strdup("Mozilla");
XP_AppVersion = strdup("5.0 Netscape/5.0 (Windows;I;x86;en)");
mContainer = aContainerApp;
NS_IF_ADDREF(mContainer);
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);
m_stubContext = NULL;
}
NS_IF_RELEASE(mContainer);
NET_ShutdownNetLib();
}
@ -255,32 +291,99 @@ loser:
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" {
static nsNetlibService *pNetlib = NULL;
/*
* Factory for creating instance of the NetlibService...
*/
NS_NET nsresult NS_NewINetService(nsINetService** aInstancePtrResult,
nsISupports* aOuter)
{
static nsNetlibService *pNetlib = NULL;
if (NULL != aOuter) {
return NS_ERROR_NO_AGGREGATION;
}
/* XXX: For now only allow a single instance of the Netlib Service */
if (NULL == pNetlib) {
pNetlib = new nsNetlibService();
}
if (NULL == pNetlib) {
return NS_ERROR_OUT_OF_MEMORY;
nsresult res;
res = NS_InitINetService(NULL);
if (NS_OK != res) {
return res;
}
}
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" */

View File

@ -22,12 +22,14 @@
#include "nspr.h"
#include "nsINetService.h"
class nsINetContainerApplication;
class nsNetlibService : public nsINetService {
public:
NS_DECL_ISUPPORTS
nsNetlibService();
nsNetlibService(nsINetContainerApplication *aContainer);
/* Implementation of the nsINetService interface */
NS_IMETHOD OpenStream(nsIURL *aUrl, nsIStreamListener *aConsumer);
@ -35,12 +37,16 @@ public:
nsIStreamListener *aConsumer,
nsIInputStream **aNewStream);
NS_IMETHOD GetContainerApplication(nsINetContainerApplication **aContainer);
nsresult SetContainerApplication(nsINetContainerApplication *aContainer);
protected:
virtual ~nsNetlibService();
private:
/* XXX: This is temporary until bamwrap.cpp is removed... */
void *m_stubContext;
nsINetContainerApplication *mContainer;
};