Bug 482921 part 1 - Implement HTML syntax highlighting using the new parser. r=Olli.Pettay.

This commit is contained in:
Henri Sivonen
2010-07-30 13:15:38 +03:00
parent 6d5bbec2af
commit a42c6e14db
37 changed files with 4254 additions and 107 deletions

View File

@@ -65,6 +65,9 @@
#include "nsEscape.h"
#include "mozilla/dom/Element.h"
#include "nsHtml5SVGLoadDispatcher.h"
#include "nsIURI.h"
#include "nsIProtocolHandler.h"
#include "nsNetUtil.h"
namespace dom = mozilla::dom;
@@ -125,6 +128,7 @@ nsHtml5TreeOperation::~nsHtml5TreeOperation()
case eTreeOpAppendText:
case eTreeOpAppendComment:
case eTreeOpAppendCommentToDocument:
case eTreeOpAddViewSourceHref:
delete[] mTwo.unicharPtr;
break;
case eTreeOpSetDocumentCharset:
@@ -707,6 +711,69 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
}
return rv;
}
case eTreeOpAddClass: {
nsIContent* node = *(mOne.node);
PRUnichar* str = mTwo.unicharPtr;
nsDependentString depStr(str);
node->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, depStr, true);
return rv;
}
case eTreeOpAddViewSourceHref: {
nsIContent* node = *mOne.node;
PRUnichar* buffer = mTwo.unicharPtr;
PRInt32 length = mInt;
nsDependentString relative(buffer, length);
nsIDocument* doc = aBuilder->GetDocument();
const nsCString& charset = doc->GetDocumentCharacterSet();
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri),
relative,
charset.get(),
aBuilder->GetViewSourceBaseURI());
NS_ENSURE_SUCCESS(rv, rv);
// Reuse the fix for bug 467852
// URLs that execute script (e.g. "javascript:" URLs) should just be
// ignored. There's nothing reasonable we can do with them, and allowing
// them to execute in the context of the view-source window presents a
// security risk. Just return the empty string in this case.
bool openingExecutesScript = false;
rv = NS_URIChainHasFlags(uri,
nsIProtocolHandler::URI_OPENING_EXECUTES_SCRIPT,
&openingExecutesScript);
NS_ENSURE_SUCCESS(rv, NS_OK);
if (openingExecutesScript) {
return NS_OK;
}
nsCAutoString viewSourceUrl;
// URLs that return data (e.g. "http:" URLs) should be prefixed with
// "view-source:". URLs that don't return data should just be returned
// undecorated.
bool doesNotReturnData = false;
rv = NS_URIChainHasFlags(uri,
nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA,
&doesNotReturnData);
NS_ENSURE_SUCCESS(rv, NS_OK);
if (!doesNotReturnData) {
viewSourceUrl.AssignLiteral("view-source:");
}
nsCAutoString spec;
uri->GetSpec(spec);
viewSourceUrl.Append(spec);
nsAutoString utf16;
CopyUTF8toUTF16(viewSourceUrl, utf16);
node->SetAttr(kNameSpaceID_None, nsGkAtoms::href, utf16, true);
return rv;
}
default: {
NS_NOTREACHED("Bogus tree op");
}