Fix for bug#66334 - Viewsource needs to be a protocol handler

r=valeski,sr=rpotts
This commit is contained in:
chak%netscape.com 2001-04-16 20:17:36 +00:00
parent 2c58e0142a
commit b9342d088b
10 changed files with 63 additions and 77 deletions

View File

@ -181,6 +181,8 @@ NS_IMETHODIMP nsDSURIContentListener::CanHandleContent(const char* aContentType,
|| nsCRT::strcasecmp(aContentType, "image/tiff") == 0
|| nsCRT::strcasecmp(aContentType, "application/http-index-format") == 0)
*aCanHandleContent = PR_TRUE;
else if (PL_strcasestr(aContentType, "; x-view-type=view-source") != nsnull)
*aCanHandleContent = PR_TRUE;
}
else
*aCanHandleContent = PR_FALSE;

View File

@ -137,9 +137,6 @@ nsDocShell::nsDocShell() :
mAllowJavascript(PR_TRUE),
mAllowMetaRedirects(PR_TRUE),
mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
mViewMode(viewNormal),
mLastViewMode(viewNormal),
mRestoreViewMode(PR_FALSE),
mBusyFlags(BUSY_FLAGS_NONE),
mEODForCurrentDocument (PR_FALSE),
mURIResultedInDocument(PR_FALSE),
@ -459,7 +456,7 @@ nsDocShell::LoadURI(nsIURI* aURI, nsIDocShellLoadInfo* aLoadInfo, PRUint32 aLoad
}
if (shEntry) {
// Load is from SH. SH does normal load only
mViewMode = viewNormal;
rv = LoadHistoryEntry(shEntry, loadType);
} else {
rv = InternalLoad(aURI, referrer, owner, inheritOwner, stopActiveDoc, (const char*) target, nsnull,
@ -763,33 +760,6 @@ NS_IMETHODIMP nsDocShell::SetAppType(PRUint32 aAppType)
return NS_OK;
}
NS_IMETHODIMP nsDocShell::GetViewMode(PRInt32* aViewMode)
{
NS_ENSURE_ARG_POINTER(aViewMode);
*aViewMode = mViewMode;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::SetViewMode(PRInt32 aViewMode)
{
NS_ENSURE_ARG((viewNormal == aViewMode) || (viewSource == aViewMode));
PRBool reload = PR_FALSE;
if((mViewMode != aViewMode) && mCurrentURI)
reload = PR_TRUE;
mViewMode = aViewMode;
if(reload)
{
Reload(LOAD_FLAGS_NONE);
}
return NS_OK;
}
NS_IMETHODIMP nsDocShell::GetZoom(float* zoom)
{
NS_ENSURE_ARG_POINTER(zoom);
@ -2870,9 +2840,13 @@ nsresult nsDocShell::NewContentViewerObj(const char* aContentType,
//XXX This should probably be some category thing....
char id[256];
PR_snprintf(id, sizeof(id), NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "%s;1?type=%s",
(const char*)((viewSource == mViewMode) ? "view-source" : "view"),
(const char*)"view",
aContentType);
// Note that we're always passing in "view" for the component id above
// and to the docLoaderFactory->CreateInstance() at the end of this method.
// nsLayoutDLF makes the determination if it should be a "view-source"
// Create an instance of the document-loader-factory
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory(do_CreateInstance(id));
if(!docLoaderFactory)
@ -2896,7 +2870,7 @@ nsresult nsDocShell::NewContentViewerObj(const char* aContentType,
// Now create an instance of the content viewer
NS_ENSURE_SUCCESS(docLoaderFactory->CreateInstance(
(viewSource == mViewMode) ? "view-source" : "view",
"view",
aOpenedChannel, aLoadGroup, aContentType,
NS_STATIC_CAST(nsIContentViewerContainer*, this), nsnull,
aContentHandler, aViewer), NS_ERROR_FAILURE);
@ -3173,29 +3147,6 @@ NS_IMETHODIMP nsDocShell::CreateFixupURI(const PRUnichar* aStringURI,
// Eliminate embedded newlines, which single-line text fields now allow:
uriString.StripChars("\r\n");
// XXX nasty hack to check for the view-source: prefix
//
// The long term way and probably CORRECT way to do this is to write a
// protocol handler for the view-source: schema and have that feed back a
// content type that the docshell recognizes to mean to use viewSource mode.
//
const char cViewSource[] = "view-source:";
if (uriString.EqualsWithConversion(cViewSource, PR_TRUE, sizeof(cViewSource) - 1))
{
// Strip the view-source: prefix and set the docshell's view mode
nsAutoString newUri;
uriString.Mid(newUri, sizeof(cViewSource) - 1, -1);
uriString = newUri;
mLastViewMode = mViewMode;
mViewMode = viewSource;
mRestoreViewMode = PR_TRUE;
}
else if (mRestoreViewMode)
{
mRestoreViewMode = PR_FALSE;
mViewMode = mLastViewMode;
}
// Create the fixup object if necessary
if (!mURIFixup)
{
@ -3594,10 +3545,6 @@ NS_IMETHODIMP nsDocShell::DoChannelLoad(nsIChannel *aChannel, nsURILoadCommand a
(void)aChannel->GetLoadFlags(&loadFlags);
loadFlags |= nsIChannel::LOAD_DOCUMENT_URI;
// "View source" always wants the currently cached content.
if ( mViewMode == viewSource ) {
loadFlags |= nsIRequest::LOAD_FROM_CACHE;
} else {
// Load attributes depend on load type...
switch ( mLoadType )
{
@ -3637,7 +3584,6 @@ NS_IMETHODIMP nsDocShell::DoChannelLoad(nsIChannel *aChannel, nsURILoadCommand a
}
break;
}
}
(void) aChannel->SetLoadFlags(loadFlags);

View File

@ -95,6 +95,11 @@ enum LoadType {
LOAD_REFRESH = MAKE_LOAD_TYPE(LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_REFRESH)
};
/* internally used ViewMode types */
enum ViewMode {
viewNormal = 0x0,
viewSource = 0x1
};
//*****************************************************************************
//*** nsRefreshTimer
@ -289,9 +294,6 @@ protected:
PRBool mAllowJavascript;
PRBool mAllowMetaRedirects;
PRUint32 mAppType;
PRInt32 mViewMode;
PRInt32 mLastViewMode;
PRBool mRestoreViewMode;
PRInt32 mChildOffset; // Offset in the parent's child list.
PRUint32 mBusyFlags;
// Reference to the SHEntry for this docshell until the page is destroyed.

View File

@ -162,17 +162,6 @@ interface nsIDocShell : nsISupports
attribute unsigned long appType;
/*
Definitions for the viewModes the docShell can be in.
*/
const long viewNormal=0;
const long viewSource=1;
/*
This is the mode that the docShell is in for viewing when a load occurs.
*/
attribute long viewMode;
/**
* Set/Get the document scale factor. When setting this attribute, a
* NS_ERROR_NOT_IMPLEMENTED error may be returned by implementations

View File

@ -63,12 +63,14 @@ static char* gHTMLTypes[] = {
"text/rtf",
"text/cpp",
"text/css",
"text/html; x-view-type=view-source",
0
};
static char* gXMLTypes[] = {
"text/xml",
"application/xml",
"text/xml; x-view-type=view-source",
0
};
@ -243,8 +245,40 @@ nsLayoutDLF::CreateInstance(const char *aCommand,
}
}
// Check aContentType to see if it's a view-source type
//
// If it's a "view-source:", aContentType will be of the form
//
// <orig_type>; x-view-type=view-source
//
// where <orig_type> can be text/html, text/xml etc.
//
nsCAutoString strContentType; strContentType.Append(aContentType);
PRInt32 idx = strContentType.Find("; x-view-type=view-source", PR_TRUE, 0, -1);
if(idx != -1)
{ // Found "; x-view-type=view-source" param in content type.
// Set aCommand to view-source
aCommand = "view-source";
// Null terminate at the ";" in "text/html; x-view-type=view-source"
// The idea is to end up with the original content type i.e. without
// the x-view-type param was added to it.
strContentType.SetCharAt('\0', idx);
aContentType = strContentType.get(); //This will point to the "original" mime type
}
if(0==PL_strcmp(aCommand,"view-source")) {
#ifdef VIEW_SOURCE_HTML
NS_ENSURE_ARG(aChannel);
// It's a view-source. Reset channel's content type to the original
// type so as not to choke the parser when it asks the channel
// for the content type during the parse phase
aChannel->SetContentType(aContentType);
aContentType=gHTMLTypes[0];
#else
if(0==PL_strcmp(aContentType,gHTMLTypes[1])) {

View File

@ -38,6 +38,7 @@ SHARED_LIBRARY_LIBS = \
$(DIST)/lib/libnkftp_s.$(LIB_SUFFIX) \
$(DIST)/lib/libnkfinger_s.$(LIB_SUFFIX) \
$(DIST)/lib/libnkdatetm_s.$(LIB_SUFFIX) \
$(DIST)/lib/libnkviewsource_s.$(LIB_SUFFIX) \
$(NULL)
LOCAL_INCLUDES = \
@ -45,6 +46,7 @@ LOCAL_INCLUDES = \
-I$(srcdir)/../protocol/ftp/src \
-I$(srcdir)/../protocol/finger/src \
-I$(srcdir)/../protocol/datetime/src \
-I$(srcdir)/../protocol/viewsource/src \
$(NULL)
EXTRA_DSO_LDOPTS = \

View File

@ -38,6 +38,7 @@ LLIBS= \
$(DIST)\lib\nkftp_s.lib \
$(DIST)\lib\nkfinger_s.lib \
$(DIST)\lib\nkdatetm_s.lib \
$(DIST)\lib\nkviewsource_s.lib \
$(LIBNSPR)
INCS = $(INCS) \
@ -46,6 +47,7 @@ INCS = $(INCS) \
-I$(DEPTH)\netwerk\protocol\ftp\src \
-I$(DEPTH)\netwerk\protocol\finger\src \
-I$(DEPTH)\netwerk\protocol\datetime\src \
-I$(DEPTH)\netwerk\protocol\viewsource\src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -26,6 +26,7 @@
#include "nsFtpProtocolHandler.h"
#include "nsFingerHandler.h"
#include "nsDateTimeHandler.h"
#include "nsViewSourceHandler.h"
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFtpProtocolHandler, Init);
@ -59,6 +60,13 @@ static nsModuleComponentInfo gNetModuleInfo[] = {
NS_DATETIMEHANDLER_CID,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "datetime",
nsDateTimeHandler::Create
},
// from netwerk/protocol/viewsource:
{ "The ViewSource Protocol Handler",
NS_VIEWSOURCEHANDLER_CID,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "view-source",
nsViewSourceHandler::Create
}
};

View File

@ -27,7 +27,7 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = about data file ftp http keyword jar res \
datetime finger gopher
datetime finger gopher viewsource
include $(topsrcdir)/config/rules.mk

View File

@ -35,6 +35,7 @@ DIRS= \
res \
finger \
gopher \
viewsource \
$(NULL)
include <$(DEPTH)\config\rules.mak>