Bugs 67887, 67893, 67882, 68185, 73160, 77923. Added support for XHTML base href and target attributes, meta http-equiv and link href. Fixed the blank page bug when xml-stylesheet PI did not contain href attribute. Fixed getElementById() to not match XHTML name attribute. This fix also includes some minor cleanup. r=nisheeth, sr=vidur.

git-svn-id: svn://10.0.0.236/trunk@93488 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
heikki%netscape.com 2001-04-30 23:35:09 +00:00
parent 12007da904
commit 7788ebd4ed
18 changed files with 317 additions and 90 deletions

View File

@ -124,6 +124,13 @@ public:
* Return the base URL for realtive URLs in the document. May return null (or the document URL).
*/
NS_IMETHOD GetBaseURL(nsIURI*& aURL) const = 0;
NS_IMETHOD SetBaseURL(nsIURI* aURL) = 0;
/**
* Get/Set the base target of a link in a document.
*/
NS_IMETHOD GetBaseTarget(nsAWritableString &aBaseTarget)=0;
NS_IMETHOD SetBaseTarget(const nsAReadableString &aBaseTarget)=0;
/**
* Return the content (mime) type of this document.

View File

@ -710,6 +710,8 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
owner->QueryInterface(NS_GET_IID(nsIPrincipal), (void**)&mPrincipal);
}
mDocumentBaseURL = mDocumentURL;
if (aLoadGroup) {
mDocumentLoadGroup = getter_AddRefs(NS_GetWeakReference(aLoadGroup));
// there was an assertion here that aLoadGroup was not null. This is no longer valid
@ -824,11 +826,40 @@ nsDocument::GetDocumentLoadGroup(nsILoadGroup **aGroup) const
NS_IMETHODIMP
nsDocument::GetBaseURL(nsIURI*& aURL) const
{
aURL = mDocumentURL;
aURL = mDocumentBaseURL.get();
NS_IF_ADDREF(aURL);
return NS_OK;
}
NS_IMETHODIMP
nsDocument::SetBaseURL(nsIURI* aURL)
{
nsresult rv;
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = securityManager->CheckLoadURI(mDocumentURL, aURL, nsIScriptSecurityManager::STANDARD);
if (NS_SUCCEEDED(rv)) {
mDocumentBaseURL = aURL;
}
}
return rv;
}
NS_IMETHODIMP
nsDocument::GetBaseTarget(nsAWritableString &aBaseTarget)
{
aBaseTarget.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsDocument::SetBaseTarget(const nsAReadableString &aBaseTarget)
{
return NS_OK;
}
NS_IMETHODIMP nsDocument::GetDocumentCharacterSet(nsAWritableString& oCharSetID)
{
oCharSetID = mCharacterSet;
@ -2741,9 +2772,9 @@ NS_IMETHODIMP
nsDocument::GetBaseURI(nsAWritableString &aURI)
{
aURI.Truncate();
if (mDocumentURL) {
if (mDocumentBaseURL) {
nsXPIDLCString spec;
mDocumentURL->GetSpec(getter_Copies(spec));
mDocumentBaseURL->GetSpec(getter_Copies(spec));
if (spec) {
CopyASCIItoUCS2(nsLiteralCString(spec), aURI);
}

View File

@ -49,6 +49,7 @@
#include "nsHashtable.h"
#include "nsIWordBreakerFactory.h"
#include "nsILineBreakerFactory.h"
#include "nsIURI.h"
class nsIEventListenerManager;
class nsDOMStyleSheetList;
@ -259,6 +260,13 @@ public:
* Return the base URL for realtive URLs in the document. May return null (or the document URL).
*/
NS_IMETHOD GetBaseURL(nsIURI*& aURL) const;
NS_IMETHOD SetBaseURL(nsIURI* aURL);
/**
* Get/Set the base target of a link in a document.
*/
NS_IMETHOD GetBaseTarget(nsAWritableString &aBaseTarget);
NS_IMETHOD SetBaseTarget(const nsAReadableString &aBaseTarget);
/**
* Return a standard name for the document's character set. This will
@ -557,6 +565,7 @@ protected:
nsIArena* mArena;
nsString* mDocumentTitle;
nsIURI* mDocumentURL;
nsCOMPtr<nsIURI> mDocumentBaseURL;
nsIPrincipal* mPrincipal;
nsWeakPtr mDocumentLoadGroup;
nsString mCharacterSet;

View File

@ -329,6 +329,10 @@ static Components gComponents[] = {
{ "XML document encoder", NS_TEXT_ENCODER_CID,
NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", },
{ "XML document encoder", NS_TEXT_ENCODER_CID,
NS_DOC_ENCODER_CONTRACTID_BASE "application/xml", },
{ "XML document encoder", NS_TEXT_ENCODER_CID,
NS_DOC_ENCODER_CONTRACTID_BASE "application/xhtml+xml", },
{ "HTML document encoder", NS_TEXT_ENCODER_CID,
NS_DOC_ENCODER_CONTRACTID_BASE "text/html", },
{ "Plaintext document encoder", NS_TEXT_ENCODER_CID,
@ -337,6 +341,10 @@ static Components gComponents[] = {
NS_HTMLCOPY_ENCODER_CONTRACTID, },
{ "XML content serializer", NS_XMLCONTENTSERIALIZER_CID,
NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/xml", },
{ "XML content serializer", NS_XMLCONTENTSERIALIZER_CID,
NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/xml", },
{ "XML content serializer", NS_XMLCONTENTSERIALIZER_CID,
NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/xhtml+xml", },
{ "HTML content serializer", NS_HTMLCONTENTSERIALIZER_CID,
NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/html", },
{ "XUL content serializer", NS_XMLCONTENTSERIALIZER_CID,

View File

@ -1918,12 +1918,7 @@ nsGenericHTMLElement::GetBaseTarget(nsAWritableString& aBaseTarget) const
}
}
if (nsnull != mDocument) {
nsIHTMLDocument* htmlDoc;
result = mDocument->QueryInterface(NS_GET_IID(nsIHTMLDocument), (void**)&htmlDoc);
if (NS_SUCCEEDED(result)) {
result = htmlDoc->GetBaseTarget(aBaseTarget);
NS_RELEASE(htmlDoc);
}
result = mDocument->GetBaseTarget(aBaseTarget);
}
else {
aBaseTarget.Truncate();

View File

@ -37,7 +37,6 @@
#include "nsIPresContext.h"
#include "nsIEventStateManager.h"
#include "nsIURL.h"
#include "nsIEventStateManager.h"
#include "nsIDOMEvent.h"
#include "nsNetUtil.h"
@ -398,12 +397,9 @@ nsHTMLAnchorElement::GetTarget(nsAWritableString& aValue)
rv = NS_STATIC_CAST(nsIContent *, this)->GetAttribute(kNameSpaceID_HTML,
nsHTMLAtoms::target,
aValue);
if (rv == NS_CONTENT_ATTR_NOT_THERE) {
nsCOMPtr<nsIHTMLDocument>doc(do_QueryInterface(mDocument));
if (doc) {
rv = doc->GetBaseTarget(aValue);
NS_ENSURE_SUCCESS(rv, rv);
}
if (rv == NS_CONTENT_ATTR_NOT_THERE && mDocument) {
rv = mDocument->GetBaseTarget(aValue);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}

View File

@ -64,6 +64,7 @@ HTML_ATOM(archive, "archive")
HTML_ATOM(area, "area")
HTML_ATOM(axis, "axis")
HTML_ATOM(background, "background")
HTML_ATOM(base, "base")
HTML_ATOM(below, "below")
#ifdef IBMBIDI
HTML_ATOM(bdo, "bdo")

View File

@ -366,14 +366,14 @@ public:
void AddBaseTagInfo(nsIHTMLContent* aContent);
nsresult ProcessLink(nsIHTMLContent* aElement, const nsString& aLinkData);
nsresult ProcessLink(nsIHTMLContent* aElement, const nsAReadableString& aLinkData);
nsresult ProcessStyleLink(nsIHTMLContent* aElement,
const nsString& aHref, const nsString& aRel,
const nsString& aTitle, const nsString& aType,
const nsString& aMedia);
void ProcessBaseHref(const nsString& aBaseHref);
void ProcessBaseTarget(const nsString& aBaseTarget);
void ProcessBaseHref(const nsAReadableString& aBaseHref);
void ProcessBaseTarget(const nsAReadableString& aBaseTarget);
nsresult RefreshIfEnabled(nsIViewManager* vm);
@ -387,7 +387,7 @@ public:
nsresult ProcessSCRIPTTag(const nsIParserNode& aNode);
nsresult ProcessSTYLETag(const nsIParserNode& aNode);
nsresult ProcessHeaderData(nsIAtom* aHeader,nsString& aValue,nsIHTMLContent* aContent=nsnull);
nsresult ProcessHeaderData(nsIAtom* aHeader,const nsAReadableString& aValue,nsIHTMLContent* aContent=nsnull);
nsresult ProcessHTTPHeaders(nsIChannel* aChannel);
// Script processing related routines
@ -3752,25 +3752,29 @@ HTMLContentSink::ProcessAREATag(const nsIParserNode& aNode)
}
void
HTMLContentSink::ProcessBaseHref(const nsString& aBaseHref)
HTMLContentSink::ProcessBaseHref(const nsAReadableString& aBaseHref)
{
//-- Make sure this page is allowed to load this URL
nsresult rv;
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return;
nsCOMPtr<nsIURI> baseHrefURI;
rv = NS_NewURI(getter_AddRefs(baseHrefURI), aBaseHref, nsnull);
if (NS_FAILED(rv)) return;
rv = securityManager->CheckLoadURI(mDocumentBaseURL, baseHrefURI, nsIScriptSecurityManager::STANDARD);
if (NS_FAILED(rv)) return;
if (nsnull == mBody) { // still in real HEAD
mHTMLDocument->SetBaseURL(aBaseHref);
NS_RELEASE(mDocumentBaseURL);
mDocument->GetBaseURL(mDocumentBaseURL);
rv = mDocument->SetBaseURL(baseHrefURI); // The document checks if it is legal to set this base
if (NS_SUCCEEDED(rv)) {
NS_RELEASE(mDocumentBaseURL);
mDocument->GetBaseURL(mDocumentBaseURL);
}
}
else { // NAV compatibility quirk
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return;
rv = securityManager->CheckLoadURI(mDocumentBaseURL, baseHrefURI, nsIScriptSecurityManager::STANDARD);
if (NS_FAILED(rv)) return;
mBaseHREF = aBaseHref;
}
}
@ -3795,10 +3799,10 @@ HTMLContentSink::RefreshIfEnabled(nsIViewManager* vm)
}
void
HTMLContentSink::ProcessBaseTarget(const nsString& aBaseTarget)
HTMLContentSink::ProcessBaseTarget(const nsAReadableString& aBaseTarget)
{
if (nsnull == mBody) { // still in real HEAD
mHTMLDocument->SetBaseTarget(aBaseTarget);
mDocument->SetBaseTarget(aBaseTarget);
}
else { // NAV compatibility quirk
mBaseTarget = aBaseTarget;
@ -3859,7 +3863,7 @@ const PRUnichar kLessThanCh = PRUnichar('<');
const PRUnichar kGreaterThanCh = PRUnichar('>');
nsresult
HTMLContentSink::ProcessLink(nsIHTMLContent* aElement, const nsString& aLinkData)
HTMLContentSink::ProcessLink(nsIHTMLContent* aElement, const nsAReadableString& aLinkData)
{
nsresult result = NS_OK;
@ -4371,7 +4375,7 @@ HTMLContentSink::ProcessHTTPHeaders(nsIChannel* aChannel) {
}
nsresult
HTMLContentSink::ProcessHeaderData(nsIAtom* aHeader,nsString& aValue,nsIHTMLContent* aContent)
HTMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAReadableString& aValue,nsIHTMLContent* aContent)
{
nsresult rv=NS_OK;
// XXX necko isn't going to process headers coming in from the parser
@ -4404,7 +4408,7 @@ HTMLContentSink::ProcessHeaderData(nsIAtom* aHeader,nsString& aValue,nsIHTMLCont
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);
rv = webNav->GetCurrentURI(getter_AddRefs(baseURI));
if (NS_FAILED(rv)) return rv;
char *cookie = aValue.ToNewCString();
char *cookie = ToNewUTF8String(aValue);
nsCOMPtr<nsIScriptGlobalObject> globalObj;
nsCOMPtr<nsIPrompt> prompt;
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));

View File

@ -1075,13 +1075,12 @@ nsHTMLDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex
mStyleSheets.InsertElementAt(aSheet, aIndex + 1); // offset one for the attr style sheet
}
NS_IMETHODIMP
nsHTMLDocument::GetBaseURL(nsIURI*& aURL) const
{
if (nsnull != mBaseURL) {
NS_ADDREF(mBaseURL);
aURL = mBaseURL;
if (mDocumentBaseURL) {
aURL = mDocumentBaseURL.get();
NS_ADDREF(aURL);
}
else {
aURL = GetDocumentURL();
@ -1089,20 +1088,6 @@ nsHTMLDocument::GetBaseURL(nsIURI*& aURL) const
return NS_OK;
}
NS_IMETHODIMP
nsHTMLDocument::SetBaseURL(const nsAReadableString& aURLSpec)
{
nsresult result = NS_OK;
NS_IF_RELEASE(mBaseURL);
if (0 < aURLSpec.Length()) {
{
result = NS_NewURI(&mBaseURL, aURLSpec, mDocumentURL);
}
}
return result;
}
NS_IMETHODIMP
nsHTMLDocument::GetBaseTarget(nsAWritableString& aTarget) const
{

View File

@ -91,7 +91,6 @@ public:
NS_IMETHOD GetCSSLoader(nsICSSLoader*& aLoader);
NS_IMETHOD GetBaseURL(nsIURI*& aURL) const;
NS_IMETHOD SetBaseURL(const nsAReadableString& aURLSpec);
NS_IMETHOD GetBaseTarget(nsAWritableString& aTarget) const;
NS_IMETHOD SetBaseTarget(const nsAReadableString& aTarget);

View File

@ -58,11 +58,6 @@ public:
NS_IMETHOD GetForms(nsIDOMHTMLCollection** aForms) = 0;
NS_IMETHOD SetBaseURL(const nsAReadableString& aURLSpec) = 0;
NS_IMETHOD GetBaseTarget(nsAWritableString& aTarget) const = 0;
NS_IMETHOD SetBaseTarget(const nsAReadableString& aTarget) = 0;
NS_IMETHOD SetLastModified(const nsAReadableString& aLastModified) = 0;
NS_IMETHOD SetReferrer(const nsAReadableString& aReferrer) = 0;

View File

@ -64,6 +64,7 @@ HTML_ATOM(archive, "archive")
HTML_ATOM(area, "area")
HTML_ATOM(axis, "axis")
HTML_ATOM(background, "background")
HTML_ATOM(base, "base")
HTML_ATOM(below, "below")
#ifdef IBMBIDI
HTML_ATOM(bdo, "bdo")

View File

@ -34,7 +34,7 @@
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIURL.h"
#include "nsIURL.h"
#include "nsIRefreshURI.h"
#include "nsNetUtil.h"
#include "nsIWebShell.h"
#include "nsIDocShell.h"
@ -74,6 +74,7 @@
#include "nsParserUtils.h"
#include "nsIDocumentViewer.h"
#include "nsIScrollable.h"
#include "nsIWebNavigation.h"
// XXX misnamed header file, but oh well
#include "nsHTMLTokens.h"
@ -90,13 +91,10 @@ nsINameSpaceManager* nsXMLContentSink::gNameSpaceManager = nsnull;
PRUint32 nsXMLContentSink::gRefCnt = 0;
// XXX Open Issues:
// 1) html:base - Should we allow a base tag? If so, the content
// sink needs to maintain the base when resolving URLs for
// loaded scripts and style sheets. Should it be allowed anywhere?
// 2) what's not allowed - We need to figure out which HTML tags
// 1) what's not allowed - We need to figure out which HTML tags
// (prefixed with a HTML namespace qualifier) are explicitly not
// allowed (if any).
// 3) factoring code with nsHTMLContentSink - There's some amount of
// 2) factoring code with nsHTMLContentSink - There's some amount of
// common code between this and the HTML content sink. This will
// increase as we support more and more HTML elements. How can code
// from the code be factored?
@ -615,6 +613,18 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode)
mTextAreaElement = do_QueryInterface(htmlContent);
} else if (tagAtom.get() == nsHTMLAtoms::style) {
mStyleElement = htmlContent;
} else if (tagAtom.get() == nsHTMLAtoms::base) {
if (!mBaseElement) {
mBaseElement = htmlContent; // The first base wins
}
} else if (tagAtom.get() == nsHTMLAtoms::meta) {
if (!mMetaElement) {
mMetaElement = htmlContent;
}
} else if (tagAtom.get() == nsHTMLAtoms::link) {
if (!mLinkElement) {
mLinkElement = htmlContent;
}
}
}
else {
@ -726,6 +736,20 @@ nsXMLContentSink::CloseContainer(const nsIParserNode& aNode)
mStyleElement=nsnull;
mStyleText.Truncate();
}
} else if (tagAtom.get() == nsHTMLAtoms::base) {
if (mBaseElement) {
result = ProcessBASETag();
}
} else if (tagAtom.get() == nsHTMLAtoms::meta) {
if (mMetaElement) {
result = ProcessMETATag();
mMetaElement = nsnull; // HTML can have more than one meta so clear this now
}
} else if (tagAtom.get() == nsHTMLAtoms::link) {
if (mLinkElement) {
result = ProcessLINKTag();
mLinkElement = nsnull; // HTML can have more than one link so clear this now
}
}
}
@ -978,7 +1002,7 @@ nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl, const nsString& aType)
// Hook up the content sink to the parser's output and ask the parser
// to start parsing the URL specified by aURL.
parser->SetContentSink(sink);
nsAutoString utf8(NS_ConvertASCIItoUCS2("UTF-8"));
nsAutoString utf8(NS_LITERAL_STRING("UTF-8"));
styleDoc->SetDocumentCharacterSet(utf8);
parser->SetDocumentCharset(utf8, kCharsetFromDocTypeDefault);
parser->Parse(aUrl);
@ -1205,6 +1229,113 @@ nsXMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
return rv;
}
nsresult
nsXMLContentSink::ProcessBASETag()
{
nsresult rv = NS_OK;
if (mDocument) {
nsAutoString value;
if (NS_CONTENT_ATTR_HAS_VALUE == mBaseElement->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::target, value)) {
mDocument->SetBaseTarget(value);
}
if (NS_CONTENT_ATTR_HAS_VALUE == mBaseElement->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::href, value)) {
nsCOMPtr<nsIURI> baseURI;
rv = NS_NewURI(getter_AddRefs(baseURI), value, nsnull);
if (NS_SUCCEEDED(rv)) {
rv = mDocument->SetBaseURL(baseURI); // The document checks if it is legal to set this base
if (NS_SUCCEEDED(rv)) {
NS_IF_RELEASE(mDocumentBaseURL);
mDocument->GetBaseURL(mDocumentBaseURL);
}
}
}
}
return rv;
}
nsresult
nsXMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAReadableString& aValue,nsIHTMLContent* aContent)
{
nsresult rv=NS_OK;
// XXX necko isn't going to process headers coming in from the parser
//NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)");
// see if we have a refresh "header".
if (aHeader == nsHTMLAtoms::refresh) {
// first get our baseURI
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(mWebShell, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURI> baseURI;
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);
rv = webNav->GetCurrentURI(getter_AddRefs(baseURI));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRefreshURI> reefer = do_QueryInterface(mWebShell);
if (reefer) {
rv = reefer->RefreshURIFromHeader(baseURI, aValue);
if (NS_FAILED(rv)) return rv;
}
} // END refresh
return rv;
}
nsresult
nsXMLContentSink::ProcessMETATag()
{
nsresult rv = NS_OK;
// set any HTTP-EQUIV data into document's header data as well as url
nsAutoString header;
mMetaElement->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::httpEquiv, header);
if (header.Length() > 0) {
nsAutoString result;
mMetaElement->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::content, result);
if (result.Length() > 0) {
header.ToLowerCase();
nsCOMPtr<nsIAtom> fieldAtom(dont_AddRef(NS_NewAtom(header)));
rv=ProcessHeaderData(fieldAtom,result,mMetaElement);
}//if (result.Length() > 0)
}//if (header.Length() > 0)
return rv;
}
nsresult
nsXMLContentSink::ProcessLINKTag()
{
nsresult result = NS_OK;
nsAutoString href;
nsAutoString rel;
nsAutoString title;
nsAutoString type;
nsAutoString media;
mLinkElement->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::href, href);
mLinkElement->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::rel, rel);
mLinkElement->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::title, title);
mLinkElement->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, type);
mLinkElement->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::media, media);
href.CompressWhitespace();
rel.CompressWhitespace();
title.CompressWhitespace();
type.CompressWhitespace();
media.CompressWhitespace();
media.ToLowerCase(); // HTML4.0 spec is inconsistent, make it case INSENSITIVE
if (!href.IsEmpty()) {
result = ProcessStyleLink(mLinkElement, href, rel.Find("alternate") == 0, title, type, media);
}
return result;
}
NS_IMETHODIMP
nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
@ -1231,8 +1362,8 @@ nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
result = nsParserUtils::GetQuotedAttributeValue(text, NS_ConvertASCIItoUCS2("href"), href);
// If there was an error or there's no href, we can't do
// anything with this PI
if ((NS_OK != result) || (0 == href.Length())) {
return result;
if ((NS_OK != result) || href.IsEmpty()) {
return NS_OK;
}
result = nsParserUtils::GetQuotedAttributeValue(text, NS_ConvertASCIItoUCS2("type"), type);
if (NS_FAILED(result)) {
@ -1247,7 +1378,7 @@ nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
media.ToLowerCase();
}
result = nsParserUtils::GetQuotedAttributeValue(text, NS_ConvertASCIItoUCS2("alternate"), alternate);
result = ProcessStyleLink(node, href, alternate.EqualsWithConversion("yes"),
result = ProcessStyleLink(node, href, alternate.Equals(NS_LITERAL_STRING("yes")),
title, type, media);
}
}

View File

@ -136,6 +136,11 @@ protected:
nsresult ProcessStartSCRIPTTag(const nsIParserNode& aNode);
nsresult ProcessSTYLETag(const nsIParserNode& aNode);
nsresult ProcessBASETag();
nsresult ProcessMETATag();
nsresult ProcessLINKTag();
nsresult ProcessHeaderData(nsIAtom* aHeader,const nsAReadableString& aValue,nsIHTMLContent* aContent);
nsresult RefreshIfEnabled(nsIViewManager* vm);
nsresult ProcessCSSStyleLink(nsIContent* aElement,
@ -182,8 +187,6 @@ protected:
PRInt32 mTextSize;
PRPackedBool mConstrainSize;
// XXX Special processing for HTML SCRIPT tags. We may need
// something similar for STYLE.
PRPackedBool mInScript;
PRPackedBool mInTitle;
nsString mScriptText;
@ -201,6 +204,9 @@ protected:
nsString mTextareaText;
nsCOMPtr<nsIDOMHTMLTextAreaElement> mTextAreaElement;
nsCOMPtr<nsIHTMLContent> mStyleElement;
nsCOMPtr<nsIHTMLContent> mBaseElement;
nsCOMPtr<nsIHTMLContent> mMetaElement;
nsCOMPtr<nsIHTMLContent> mLinkElement;
};
#endif // nsXMLContentSink_h__

View File

@ -54,8 +54,8 @@
#include "nsINameSpaceManager.h"
#include "nsICSSLoader.h"
#include "nsCOMPtr.h"
#include "nsIURI.h"
#include "nsXPIDLString.h"
#include "nsIURI.h"
#include "nsIHTTPChannel.h"
#include "nsIServiceManager.h"
#include "nsICharsetAlias.h"
@ -143,6 +143,7 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
NS_ENSURE_SUCCESS(rv, rv);
doc->SetDocumentURL(aBaseURI);
doc->SetBaseURL(aBaseURI);
if (aDoctype) {
nsCOMPtr<nsIDOMNode> tmpNode;
@ -178,12 +179,10 @@ NS_NewXMLDocument(nsIDocument** aInstancePtrResult)
return doc->QueryInterface(NS_GET_IID(nsIDocument), (void**) aInstancePtrResult);
}
nsXMLDocument::nsXMLDocument()
nsXMLDocument::nsXMLDocument()
: mAttrStyleSheet(nsnull), mInlineStyleSheet(nsnull),
mParser(nsnull), mCSSLoader(nsnull)
{
mParser = nsnull;
mAttrStyleSheet = nsnull;
mInlineStyleSheet = nsnull;
mCSSLoader = nsnull;
}
nsXMLDocument::~nsXMLDocument()
@ -262,6 +261,8 @@ nsXMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
result = SetDefaultStylesheets(url);
mBaseTarget.Truncate();
return result;
}
@ -343,8 +344,10 @@ nsXMLDocument::Load(const nsAReadableString& aUrl)
if (NS_FAILED(secMan->CheckLoadURIFromScript(nsnull, uri)))
return NS_ERROR_FAILURE;
// Reset the document URL to the new URL
// Partial Reset
SetDocumentURL(uri);
SetBaseURL(uri);
mBaseTarget.Truncate();
// Create a channel
rv = NS_OpenURI(getter_AddRefs(channel), uri, nsnull, nsnull, this);
@ -991,7 +994,7 @@ nsXMLDocument::CreateElementNS(const nsAReadableString& aNamespaceURI,
}
static nsIContent *
MatchName(nsIContent *aContent, const nsAReadableString& aName)
MatchId(nsIContent *aContent, const nsAReadableString& aName)
{
nsAutoString value;
nsIContent *result = nsnull;
@ -1003,10 +1006,6 @@ MatchName(nsIContent *aContent, const nsAReadableString& aName)
aName.Equals(value)) {
return aContent;
}
else if ((NS_CONTENT_ATTR_HAS_VALUE == aContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::name, value)) &&
aName.Equals(value)) {
return aContent;
}
}
else {
nsCOMPtr<nsIXMLContent> xmlContent = do_QueryInterface(aContent);
@ -1025,7 +1024,7 @@ MatchName(nsIContent *aContent, const nsAReadableString& aName)
for (i = 0; i < count && result == nsnull; i++) {
nsIContent *child;
aContent->ChildAt(i, child);
result = MatchName(child, aName);
result = MatchId(child, aName);
NS_RELEASE(child);
}
@ -1051,7 +1050,7 @@ nsXMLDocument::GetElementById(const nsAReadableString& aElementId,
// XXX For now, we do a brute force search of the content tree.
// We should come up with a more efficient solution.
nsCOMPtr<nsIContent> content(do_QueryInterface(MatchName(mRootContent,aElementId)));
nsCOMPtr<nsIContent> content(do_QueryInterface(MatchId(mRootContent,aElementId)));
nsresult rv = NS_OK;
if (content) {
@ -1111,6 +1110,20 @@ nsXMLDocument::SetTitle(const PRUnichar *aTitle)
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocument::SetBaseTarget(const nsAReadableString &aBaseTarget)
{
mBaseTarget.Assign(aBaseTarget);
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocument::GetBaseTarget(nsAWritableString &aBaseTarget)
{
aBaseTarget.Assign(mBaseTarget);
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
{

View File

@ -32,7 +32,7 @@
class nsIParser;
class nsIDOMNode;
class nsICSSLoader;
class nsIURI;
class nsXMLDocument : public nsMarkupDocument,
public nsIXMLDocument,
@ -62,6 +62,9 @@ public:
NS_IMETHOD EndLoad();
NS_IMETHOD GetBaseTarget(nsAWritableString &aBaseTarget);
NS_IMETHOD SetBaseTarget(const nsAReadableString &aBaseTarget);
// nsIDOMNode interface
NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn);
@ -105,8 +108,10 @@ protected:
virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex);
// For HTML elements in our content model
// XXX This is not clean, but is there a better way?
nsIHTMLStyleSheet* mAttrStyleSheet;
nsIHTMLCSSStyleSheet* mInlineStyleSheet;
nsString mBaseTarget;
nsIParser *mParser;
nsICSSLoader* mCSSLoader;

View File

@ -807,9 +807,43 @@ nsXULDocument::GetDocumentLoadGroup(nsILoadGroup **aGroup) const
NS_IMETHODIMP
nsXULDocument::GetBaseURL(nsIURI*& aURL) const
{
aURL = mDocumentURL;
NS_IF_ADDREF(aURL);
return NS_OK;
if (mDocumentBaseURL) {
aURL = mDocumentBaseURL.get();
NS_ADDREF(aURL);
}
else {
aURL = GetDocumentURL();
}
return NS_OK;
}
NS_IMETHODIMP
nsXULDocument::SetBaseURL(nsIURI* aURL)
{
nsresult rv;
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = securityManager->CheckLoadURI(mDocumentURL, aURL, nsIScriptSecurityManager::STANDARD);
if (NS_SUCCEEDED(rv)) {
mDocumentBaseURL = aURL;
}
}
return rv;
}
NS_IMETHODIMP
nsXULDocument::GetBaseTarget(nsAWritableString &aBaseTarget)
{
aBaseTarget.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsXULDocument::SetBaseTarget(const nsAReadableString &aBaseTarget)
{
return NS_OK;
}
NS_IMETHODIMP
@ -3560,9 +3594,9 @@ NS_IMETHODIMP
nsXULDocument::GetBaseURI(nsAWritableString &aURI)
{
aURI.Truncate();
if (mDocumentURL) {
if (mDocumentBaseURL) {
nsXPIDLCString spec;
mDocumentURL->GetSpec(getter_Copies(spec)); // XUL documents do not have base URL?
mDocumentBaseURL->GetSpec(getter_Copies(spec));
if (spec) {
CopyASCIItoUCS2(nsLiteralCString(spec), aURI);
}

View File

@ -142,6 +142,12 @@ public:
NS_IMETHOD GetBaseURL(nsIURI*& aURL) const;
NS_IMETHOD SetBaseURL(nsIURI *aURI);
NS_IMETHOD GetBaseTarget(nsAWritableString &aBaseTarget);
NS_IMETHOD SetBaseTarget(const nsAReadableString &aBaseTarget);
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets);
NS_IMETHOD GetDocumentCharacterSet(nsAWritableString& oCharSetID);
@ -492,6 +498,7 @@ protected:
nsVoidArray mObservers;
nsAutoString mDocumentTitle;
nsCOMPtr<nsIURI> mDocumentURL; // [OWNER] ??? compare with loader
nsCOMPtr<nsIURI> mDocumentBaseURL;
nsWeakPtr mDocumentLoadGroup; // [WEAK] leads to loader
nsCOMPtr<nsIPrincipal> mDocumentPrincipal; // [OWNER]
nsCOMPtr<nsIContent> mRootContent; // [OWNER]