Implemented about:blank.

This commit is contained in:
warren%netscape.com 1999-07-03 04:05:14 +00:00
parent 246d9f8ee8
commit 7284413878
12 changed files with 195 additions and 7 deletions

View File

@ -140,6 +140,16 @@ interface nsIIOService : nsISupports
* a convenience for the caller.
*/
nsILoadGroup NewLoadGroup(in nsILoadGroup parent);
/**
* Returns a simple channel implementation that uses the given input
* stream and content type. A URI may also be supplied which will be returned
* by the channel's GetURI method. This routine is a convenience facililty
* for protocol writers.
*/
nsIChannel NewInputStreamChannel(in nsIURI uri,
in string contentType,
in nsIInputStream inStr);
};
%{C++

View File

@ -36,6 +36,7 @@ CPPSRCS = \
nsNetModuleMgr.cpp \
nsNetModRegEntry.cpp \
nsLoadGroup.cpp \
nsInputStreamChannel.cpp \
$(NULL)
include $(topsrcdir)/config/config.mk

View File

@ -38,6 +38,7 @@ CPP_OBJS = \
.\$(OBJDIR)\nsNetModuleMgr.obj \
.\$(OBJDIR)\nsNetModRegEntry.obj \
.\$(OBJDIR)\nsLoadGroup.obj \
.\$(OBJDIR)\nsInputStreamChannel.obj \
$(NULL)
INCS = $(INCS) \

View File

@ -32,6 +32,7 @@
#include "nsIFileProtocolHandler.h" // for NewChannelFromNativePath
#include "nsLoadGroup.h"
#include "nsIFileChannel.h"
#include "nsInputStreamChannel.h"
static NS_DEFINE_CID(kFileTransportService, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
@ -339,6 +340,24 @@ nsIOService::NewLoadGroup(nsILoadGroup* parent, nsILoadGroup **result)
return NS_OK;
}
NS_IMETHODIMP
nsIOService::NewInputStreamChannel(nsIURI* uri, const char *contentType,
nsIInputStream *inStr, nsIChannel **result)
{
nsresult rv;
nsInputStreamChannel* channel;
rv = nsInputStreamChannel::Create(nsnull, nsCOMTypeInfo<nsIChannel>::GetIID(),
(void**)&channel);
if (NS_FAILED(rv)) return rv;
rv = channel->Init(uri, contentType, inStr);
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
return rv;
}
*result = channel;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -53,6 +53,7 @@ public:
NS_IMETHOD NewSyncStreamListener(nsIInputStream **inStream, nsIBufferOutputStream **outStream, nsIStreamListener **_retval);
NS_IMETHOD NewChannelFromNativePath(const char *nativePath, nsIFileChannel **_retval);
NS_IMETHOD NewLoadGroup(nsILoadGroup* parent, nsILoadGroup **result);
NS_IMETHOD NewInputStreamChannel(nsIURI* uri, const char *contentType, nsIInputStream *inStr, nsIChannel **result);
// nsIOService methods:
nsIOService();

View File

@ -28,6 +28,7 @@
#include "nsSimpleURI.h"
#include "nsDnsService.h"
#include "nsLoadGroup.h"
#include "nsInputStreamChannel.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
@ -38,6 +39,7 @@ static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kExternalModuleManagerCID, NS_NETMODULEMGR_CID);
static NS_DEFINE_CID(kDNSServiceCID, NS_DNSSERVICE_CID);
static NS_DEFINE_CID(kLoadGroupCID, NS_LOADGROUP_CID);
static NS_DEFINE_CID(kInputStreamChannelCID, NS_INPUTSTREAMCHANNEL_CID);
////////////////////////////////////////////////////////////////////////////////
@ -82,6 +84,9 @@ NSGetFactory(nsISupports* aServMgr,
else if (aClass.Equals(kLoadGroupCID)) {
rv = NS_NewGenericFactory(&fact, nsLoadGroup::Create);
}
else if (aClass.Equals(kInputStreamChannelCID)) {
rv = NS_NewGenericFactory(&fact, nsInputStreamChannel::Create);
}
else {
rv = NS_ERROR_FAILURE;
}
@ -139,6 +144,12 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
"External Module Manager",
"component://netscape/network/net-extern-mod",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kInputStreamChannelCID,
"Input Stream Channel",
"component://netscape/network/input-stream-channel",
aPath, PR_TRUE, PR_TRUE);
return rv;
}
@ -169,6 +180,9 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kExternalModuleManagerCID, aPath);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kInputStreamChannelCID, aPath);
return rv;
}

View File

@ -30,6 +30,7 @@ include $(DEPTH)/config/autoconf.mk
CPPSRCS = \
nsAboutProtocolHandler.cpp \
nsAboutProtocolFactory.cpp \
nsAboutBlank.cpp \
$(NULL)
REQUIRES = xpcom necko

View File

@ -37,6 +37,7 @@ LLIBS= $(LLIBS) \
CPP_OBJS= \
.\$(OBJDIR)\nsAboutProtocolHandler.obj \
.\$(OBJDIR)\nsAboutProtocolFactory.obj \
.\$(OBJDIR)\nsAboutBlank.obj \
$(NULL)
LOCAL_INCLUDES=-I.

View File

@ -0,0 +1,70 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
#include "nsAboutBlank.h"
#include "nsIIOService.h"
#include "nsIServiceManager.h"
#include "nsIStringStream.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
NS_IMPL_ISUPPORTS(nsAboutBlank, nsCOMTypeInfo<nsIAboutModule>::GetIID());
static const char kBlankPage[] = "<h3>This page intentionally left blank.</h3>";
NS_IMETHODIMP
nsAboutBlank::NewChannel(const char *verb,
nsIURI *aURI,
nsIEventSinkGetter *eventSinkGetter,
nsIEventQueue *eventQueue,
nsIChannel **result)
{
nsresult rv;
nsIChannel* channel;
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
nsISupports* s;
rv = NS_NewStringInputStream(&s, kBlankPage);
if (NS_FAILED(rv)) return rv;
nsIInputStream* in;
rv = CallQueryInterface(s, &in);
NS_RELEASE(s);
if (NS_FAILED(rv)) return rv;
rv = serv->NewInputStreamChannel(aURI, "text/html", in, &channel);
NS_RELEASE(in);
if (NS_FAILED(rv)) return rv;
*result = channel;
return rv;
}
NS_METHOD
nsAboutBlank::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsAboutBlank* about = new nsAboutBlank();
if (about == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(about);
nsresult rv = about->QueryInterface(aIID, aResult);
NS_RELEASE(about);
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 nsAboutBlank_h__
#define nsAboutBlank_h__
#include "nsIAboutModule.h"
class nsAboutBlank : public nsIAboutModule
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD NewChannel(const char *verb,
nsIURI *aURI,
nsIEventSinkGetter *eventSinkGetter,
nsIEventQueue *eventQueue,
nsIChannel **result);
nsAboutBlank() { NS_INIT_REFCNT(); }
virtual ~nsAboutBlank() {}
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
protected:
};
#define NS_ABOUT_BLANK_MODULE_CID \
{ /* 3decd6c8-30ef-11d3-8cd0-0060b0fc14a3 */ \
0x3decd6c8, \
0x30ef, \
0x11d3, \
{0x8c, 0xd0, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
}
#endif // nsAboutBlank_h__

View File

@ -20,10 +20,12 @@
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsAboutProtocolHandler.h"
#include "nsAboutBlank.h"
#include "nscore.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kAboutProtocolHandlerCID, NS_ABOUTPROTOCOLHANDLER_CID);
static NS_DEFINE_CID(kAboutBlankModuleCID, NS_ABOUT_BLANK_MODULE_CID);
////////////////////////////////////////////////////////////////////////////////
@ -43,6 +45,9 @@ NSGetFactory(nsISupports* aServMgr,
if (aClass.Equals(kAboutProtocolHandlerCID)) {
rv = NS_NewGenericFactory(&fact, nsAboutProtocolHandler::Create);
}
else if (aClass.Equals(kAboutBlankModuleCID)) {
rv = NS_NewGenericFactory(&fact, nsAboutBlank::Create);
}
else {
rv = NS_ERROR_FAILURE;
}
@ -66,6 +71,12 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kAboutBlankModuleCID,
"about:blank",
NS_ABOUT_MODULE_PROGID_PREFIX "blank",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
return rv;
}
@ -80,6 +91,9 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
rv = compMgr->UnregisterComponent(kAboutProtocolHandlerCID, aPath);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kAboutBlankModuleCID, aPath);
if (NS_FAILED(rv)) return rv;
return rv;
}

View File

@ -134,20 +134,24 @@ nsAboutProtocolHandler::NewChannel(const char* verb, nsIURI* uri,
{
// about:what you ask?
nsresult rv;
char* what;
rv = uri->GetPath(&what);
char* whatStr;
rv = uri->GetPath(&whatStr);
if (NS_FAILED(rv)) return rv;
// look up a handler to deal with "what"
// look up a handler to deal with "whatStr"
nsAutoString progID(NS_ABOUT_MODULE_PROGID_PREFIX);
nsAutoString whatStr(what);
nsCRT::free(what);
nsAutoString what(whatStr);
nsCRT::free(whatStr);
// only take up to a question-mark if there is one:
PRInt32 amt = whatStr.Find("?");
PRInt32 amt = what.Find("?");
progID.Append(what, amt); // if amt == -1, take it all
NS_WITH_SERVICE(nsIAboutModule, aboutMod, progID.GetBuffer(), &rv);
char* progIDStr = progID.ToNewCString();
if (progIDStr == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_WITH_SERVICE(nsIAboutModule, aboutMod, progIDStr, &rv);
nsCRT::free(progIDStr);
if (NS_SUCCEEDED(rv)) {
// The standard return case:
return aboutMod->NewChannel(verb, uri, eventSinkGetter,