From 92aee5da44c1d49c74ba358209b0e132f8dce0e0 Mon Sep 17 00:00:00 2001 From: "chak%netscape.com" Date: Mon, 16 Apr 2001 20:17:36 +0000 Subject: [PATCH] Fix for bug#66334 - Viewsource needs to be a protocol handler r=valeski,sr=rpotts git-svn-id: svn://10.0.0.236/trunk@92417 18797224-902f-48f8-a5cc-f745e15eee43 --- .../docshell/base/nsDSURIContentListener.cpp | 2 + mozilla/docshell/base/nsDocShell.cpp | 70 +++---------------- mozilla/docshell/base/nsDocShell.h | 8 ++- mozilla/docshell/base/nsIDocShell.idl | 11 --- mozilla/layout/build/nsLayoutDLF.cpp | 34 +++++++++ mozilla/netwerk/build2/Makefile.in | 2 + mozilla/netwerk/build2/makefile.win | 2 + mozilla/netwerk/build2/nsNetModule2.cpp | 8 +++ mozilla/netwerk/protocol/Makefile.in | 2 +- mozilla/netwerk/protocol/makefile.win | 1 + 10 files changed, 63 insertions(+), 77 deletions(-) diff --git a/mozilla/docshell/base/nsDSURIContentListener.cpp b/mozilla/docshell/base/nsDSURIContentListener.cpp index e30be640183..e0215b3d638 100644 --- a/mozilla/docshell/base/nsDSURIContentListener.cpp +++ b/mozilla/docshell/base/nsDSURIContentListener.cpp @@ -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; diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 1fb55a77897..9154bf1a880 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -136,10 +136,7 @@ nsDocShell::nsDocShell() : mAllowPlugins(PR_TRUE), mAllowJavascript(PR_TRUE), mAllowMetaRedirects(PR_TRUE), - mAppType(nsIDocShell::APP_TYPE_UNKNOWN), - mViewMode(viewNormal), - mLastViewMode(viewNormal), - mRestoreViewMode(PR_FALSE), + mAppType(nsIDocShell::APP_TYPE_UNKNOWN), 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 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); diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 286a394a913..261d88a7822 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -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. diff --git a/mozilla/docshell/base/nsIDocShell.idl b/mozilla/docshell/base/nsIDocShell.idl index cc760c14e49..40220277283 100644 --- a/mozilla/docshell/base/nsIDocShell.idl +++ b/mozilla/docshell/base/nsIDocShell.idl @@ -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 diff --git a/mozilla/layout/build/nsLayoutDLF.cpp b/mozilla/layout/build/nsLayoutDLF.cpp index 7b5f20137ce..cbb69602aab 100644 --- a/mozilla/layout/build/nsLayoutDLF.cpp +++ b/mozilla/layout/build/nsLayoutDLF.cpp @@ -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 + // + // ; x-view-type=view-source + // + // where 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])) { diff --git a/mozilla/netwerk/build2/Makefile.in b/mozilla/netwerk/build2/Makefile.in index 80ecf9ab8e0..efdf3d91b0a 100644 --- a/mozilla/netwerk/build2/Makefile.in +++ b/mozilla/netwerk/build2/Makefile.in @@ -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 = \ diff --git a/mozilla/netwerk/build2/makefile.win b/mozilla/netwerk/build2/makefile.win index 209cb137ca0..dd7b50c7755 100644 --- a/mozilla/netwerk/build2/makefile.win +++ b/mozilla/netwerk/build2/makefile.win @@ -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> diff --git a/mozilla/netwerk/build2/nsNetModule2.cpp b/mozilla/netwerk/build2/nsNetModule2.cpp index 17e0cf49712..37f704885ef 100644 --- a/mozilla/netwerk/build2/nsNetModule2.cpp +++ b/mozilla/netwerk/build2/nsNetModule2.cpp @@ -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 } }; diff --git a/mozilla/netwerk/protocol/Makefile.in b/mozilla/netwerk/protocol/Makefile.in index ae472cab925..16c1afdcb78 100644 --- a/mozilla/netwerk/protocol/Makefile.in +++ b/mozilla/netwerk/protocol/Makefile.in @@ -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 diff --git a/mozilla/netwerk/protocol/makefile.win b/mozilla/netwerk/protocol/makefile.win index cbbf14da8d4..081f1c96a6a 100644 --- a/mozilla/netwerk/protocol/makefile.win +++ b/mozilla/netwerk/protocol/makefile.win @@ -35,6 +35,7 @@ DIRS= \ res \ finger \ gopher \ + viewsource \ $(NULL) include <$(DEPTH)\config\rules.mak>