From 088b02553bdfbd4f7fc23295008c8ba60e9d5e8e Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Tue, 1 Nov 2011 13:33:11 +0200 Subject: [PATCH] Bug 482921 part 5 - Add entry point for new View Source for XML; Make new View Source easy to disable. r=Olli.Pettay. --- content/html/document/src/nsHTMLDocument.cpp | 23 +++++++++++--------- parser/html/nsHtml5Parser.cpp | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 683172860fa6..f3d1dd8f3a9e 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -161,6 +161,8 @@ const PRInt32 kBackward = 1; //#define DEBUG_charset +#define NS_USE_NEW_VIEW_SOURCE 1 + static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); PRUint32 nsHTMLDocument::gWyciwygSessionCnt = 0; @@ -650,7 +652,10 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, bool aReset, nsIContentSink* aSink) { - bool loadAsHtml5 = nsHtml5Module::sEnabled; + bool viewSource = aCommand && !nsCRT::strcmp(aCommand, "view-source") && + NS_USE_NEW_VIEW_SOURCE; + bool loadAsHtml5 = nsHtml5Module::sEnabled || viewSource; + if (aSink) { loadAsHtml5 = false; } @@ -658,8 +663,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, nsCAutoString contentType; aChannel->GetContentType(contentType); - if (contentType.Equals("application/xhtml+xml") && - (!aCommand || nsCRT::strcmp(aCommand, "view-source") != 0)) { + if (contentType.Equals("application/xhtml+xml") && !viewSource) { // We're parsing XHTML as XML, remember that. mIsRegularHTML = false; @@ -673,16 +677,13 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, } #endif - if (loadAsHtml5 && - !(contentType.EqualsLiteral("text/html") && - aCommand && - (!nsCRT::strcmp(aCommand, "view") || - !nsCRT::strcmp(aCommand, "view-source")))) { + if (loadAsHtml5 && !viewSource && !(contentType.EqualsLiteral("text/html") && + aCommand && !nsCRT::strcmp(aCommand, "view"))) { loadAsHtml5 = false; } // TODO: Proper about:blank treatment is bug 543435 - if (loadAsHtml5) { + if (loadAsHtml5 && !viewSource) { // mDocumentURI hasn't been set, yet, so get the URI from the channel nsCOMPtr uri; aChannel->GetOriginalURI(getter_AddRefs(uri)); @@ -730,7 +731,9 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, if (needsParser) { if (loadAsHtml5) { mParser = nsHtml5Module::NewHtml5Parser(); - mParser->MarkAsNotScriptCreated(aCommand); + mParser->MarkAsNotScriptCreated((viewSource && + !contentType.EqualsLiteral("text/html")) ? + "view-source-xml": aCommand); } else { mParser = do_CreateInstance(kCParserCID, &rv); NS_ENSURE_SUCCESS(rv, rv); diff --git a/parser/html/nsHtml5Parser.cpp b/parser/html/nsHtml5Parser.cpp index 52dbd687944c..fef357977145 100644 --- a/parser/html/nsHtml5Parser.cpp +++ b/parser/html/nsHtml5Parser.cpp @@ -705,7 +705,8 @@ nsHtml5Parser::MarkAsNotScriptCreated(const char* aCommand) eParserMode mode = NORMAL; if (!nsCRT::strcmp(aCommand, "view-source")) { mode = VIEW_SOURCE_HTML; - // XXX XML view source not implemented yet + } else if (!nsCRT::strcmp(aCommand, "view-source-xml")) { + mode = VIEW_SOURCE_XML; } #ifdef DEBUG else {