Make sure that sheets in a document always know their URL. Bug 218031, r+sr=dbaron

This commit is contained in:
bzbarsky%mit.edu 2003-10-06 13:24:55 +00:00
Родитель d6608ce74f
Коммит ca7587571d
11 изменённых файлов: 69 добавлений и 59 удалений

Просмотреть файл

@ -76,7 +76,12 @@ public:
NS_IMETHOD StyleSheetCount(PRInt32& aCount) const = 0;
NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const = 0;
NS_IMETHOD Init(nsIURI* aURL) = 0;
/**
* SetURL must be called on all sheets before parsing into them.
* SetURL may only be called while the sheet is 1) incomplete and 2)
* has no rules in it
*/
NS_IMETHOD SetURL(nsIURI* aURL) = 0;
NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
NS_IMETHOD AppendMedium(nsIAtom* aMedium) = 0;
NS_IMETHOD ClearMedia(void) = 0;

Просмотреть файл

@ -782,10 +782,14 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
return NS_OK;
}
if (channelURI) {
// Enough to set the URI on mSheet, since any sibling datas we have share
// the same mInner as mSheet and will thus get the same URI.
mSheet->SetURL(channelURI);
}
PRBool completed;
return mLoader->ParseSheet(aDataStream, this,
channelURI ? channelURI : mURI,
completed);
return mLoader->ParseSheet(aDataStream, this, completed);
}
#ifdef MOZ_XUL
@ -1035,8 +1039,15 @@ CSSLoaderImpl::CreateSheet(nsIURI* aURI,
if (!*aSheet) {
aSheetState = eSheetNeedsParser;
rv = NS_NewCSSStyleSheet(aSheet); // Don't init the sheet here, but in
// ParseSheet once we know the final URI
nsCOMPtr<nsIURI> sheetURI = aURI;
if (!sheetURI) {
// Inline style. Use the document's base URL so that @import in
// the inline sheet picks up the right base.
NS_ASSERTION(aLinkingContent, "Inline stylesheet without linking content?");
aLinkingContent->GetBaseURL(getter_AddRefs(sheetURI));
}
rv = NS_NewCSSStyleSheet(aSheet, sheetURI);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -1271,7 +1282,7 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
}
PRBool completed;
rv = ParseSheet(converterStream, aLoadData, aLoadData->mURI, completed);
rv = ParseSheet(converterStream, aLoadData, completed);
NS_ASSERTION(completed, "sync load did not complete");
return rv;
}
@ -1392,25 +1403,17 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
nsresult
CSSLoaderImpl::ParseSheet(nsIUnicharInputStream* aStream,
SheetLoadData* aLoadData,
nsIURI* aSheetURI,
PRBool& aCompleted)
{
LOG(("CSSLoaderImpl::ParseSheet"));
NS_PRECONDITION(aStream, "Must have data to parse");
NS_PRECONDITION(aLoadData, "Must have load data");
NS_PRECONDITION(aSheetURI, "Must have sheet URI");
NS_PRECONDITION(aLoadData->mSheet, "Must have sheet to parse into");
aCompleted = PR_FALSE;
// Init the sheet with the correct URI so that the relative URIs in
// it will be resolved properly.
nsresult rv = aLoadData->mSheet->Init(aSheetURI);
NS_ASSERTION(NS_SUCCEEDED(rv),
"If this is failing, something has gone terribly wrong");
nsCOMPtr<nsICSSParser> parser;
rv = GetParserFor(aLoadData->mSheet, getter_AddRefs(parser));
nsresult rv = GetParserFor(aLoadData->mSheet, getter_AddRefs(parser));
if (NS_FAILED(rv)) {
LOG_ERROR((" Failed to get CSS parser"));
SheetComplete(aLoadData, PR_FALSE);
@ -1422,7 +1425,9 @@ CSSLoaderImpl::ParseSheet(nsIUnicharInputStream* aStream,
nsCOMPtr<nsICSSStyleSheet> dummySheet;
// Push our load data on the stack so any kids can pick it up
mParsingDatas.AppendElement(aLoadData);
rv = parser->Parse(aStream, aSheetURI, *getter_AddRefs(dummySheet));
nsCOMPtr<nsIURI> uri;
aLoadData->mSheet->GetURL(*getter_AddRefs(uri));
rv = parser->Parse(aStream, uri, *getter_AddRefs(dummySheet));
mParsingDatas.RemoveElementAt(mParsingDatas.Count() - 1);
RecycleParser(parser);
@ -1610,12 +1615,9 @@ CSSLoaderImpl::LoadInlineStyle(nsIContent* aElement,
return NS_ERROR_OUT_OF_MEMORY;
}
nsCOMPtr<nsIURI> baseURI;
aElement->GetBaseURL(getter_AddRefs(baseURI));
NS_ADDREF(data);
// Parse completion releases the load data
return ParseSheet(aStream, data, baseURI, aCompleted);
return ParseSheet(aStream, data, aCompleted);
}
NS_IMETHODIMP

Просмотреть файл

@ -286,7 +286,6 @@ protected:
// access to
nsresult ParseSheet(nsIUnicharInputStream* aStream,
SheetLoadData* aLoadData,
nsIURI* aSheetURI,
PRBool& aCompleted);
public:

Просмотреть файл

@ -805,7 +805,7 @@ public:
NS_DECL_ISUPPORTS
// basic style sheet data
NS_IMETHOD Init(nsIURI* aURL);
NS_IMETHOD SetURL(nsIURI* aURL);
NS_IMETHOD GetURL(nsIURI*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD SetTitle(const nsAString& aTitle);
@ -1780,7 +1780,7 @@ CSSStyleSheetImpl::DropRuleProcessorReference(nsICSSStyleRuleProcessor* aProcess
NS_IMETHODIMP
CSSStyleSheetImpl::Init(nsIURI* aURL)
CSSStyleSheetImpl::SetURL(nsIURI* aURL)
{
NS_PRECONDITION(aURL, "null ptr");
if (! aURL)
@ -1790,9 +1790,8 @@ CSSStyleSheetImpl::Init(nsIURI* aURL)
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ASSERTION(! mInner->mURL, "already initialized");
if (mInner->mURL)
return NS_ERROR_ALREADY_INITIALIZED;
NS_ASSERTION(!mInner->mOrderedRules && !mInner->mComplete,
"Can't call SetURL on sheets that are complete or have rules");
mInner->mURL = aURL;
return NS_OK;
@ -3059,7 +3058,7 @@ NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURI* aURL)
if (NS_FAILED(rv = NS_NewCSSStyleSheet(&sheet)))
return rv;
if (NS_FAILED(rv = sheet->Init(aURL))) {
if (NS_FAILED(rv = sheet->SetURL(aURL))) {
NS_RELEASE(sheet);
return rv;
}

Просмотреть файл

@ -2229,7 +2229,7 @@ nsresult PresShell::CreatePreferenceStyleSheet(void)
result = NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nsnull);
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(uri, "null but no error");
result = mPrefStyleSheet->Init(uri);
result = mPrefStyleSheet->SetURL(uri);
if (NS_SUCCEEDED(result)) {
mPrefStyleSheet->SetComplete();
nsCOMPtr<nsIDOMCSSStyleSheet> sheet(do_QueryInterface(mPrefStyleSheet));

Просмотреть файл

@ -2229,7 +2229,7 @@ nsresult PresShell::CreatePreferenceStyleSheet(void)
result = NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nsnull);
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(uri, "null but no error");
result = mPrefStyleSheet->Init(uri);
result = mPrefStyleSheet->SetURL(uri);
if (NS_SUCCEEDED(result)) {
mPrefStyleSheet->SetComplete();
nsCOMPtr<nsIDOMCSSStyleSheet> sheet(do_QueryInterface(mPrefStyleSheet));

Просмотреть файл

@ -534,7 +534,7 @@ GetMathMLAttributeStyleSheet(nsIPresContext* aPresContext,
nsCOMPtr<nsICSSStyleSheet> cssSheet(do_CreateInstance(kCSSStyleSheetCID));
if (!cssSheet)
return;
cssSheet->Init(uri);
cssSheet->SetURL(uri);
nsCOMPtr<nsIDOMCSSStyleSheet> domSheet(do_QueryInterface(cssSheet));
if (domSheet) {
PRUint32 index;

Просмотреть файл

@ -782,10 +782,14 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
return NS_OK;
}
if (channelURI) {
// Enough to set the URI on mSheet, since any sibling datas we have share
// the same mInner as mSheet and will thus get the same URI.
mSheet->SetURL(channelURI);
}
PRBool completed;
return mLoader->ParseSheet(aDataStream, this,
channelURI ? channelURI : mURI,
completed);
return mLoader->ParseSheet(aDataStream, this, completed);
}
#ifdef MOZ_XUL
@ -1035,8 +1039,15 @@ CSSLoaderImpl::CreateSheet(nsIURI* aURI,
if (!*aSheet) {
aSheetState = eSheetNeedsParser;
rv = NS_NewCSSStyleSheet(aSheet); // Don't init the sheet here, but in
// ParseSheet once we know the final URI
nsCOMPtr<nsIURI> sheetURI = aURI;
if (!sheetURI) {
// Inline style. Use the document's base URL so that @import in
// the inline sheet picks up the right base.
NS_ASSERTION(aLinkingContent, "Inline stylesheet without linking content?");
aLinkingContent->GetBaseURL(getter_AddRefs(sheetURI));
}
rv = NS_NewCSSStyleSheet(aSheet, sheetURI);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -1271,7 +1282,7 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
}
PRBool completed;
rv = ParseSheet(converterStream, aLoadData, aLoadData->mURI, completed);
rv = ParseSheet(converterStream, aLoadData, completed);
NS_ASSERTION(completed, "sync load did not complete");
return rv;
}
@ -1392,25 +1403,17 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
nsresult
CSSLoaderImpl::ParseSheet(nsIUnicharInputStream* aStream,
SheetLoadData* aLoadData,
nsIURI* aSheetURI,
PRBool& aCompleted)
{
LOG(("CSSLoaderImpl::ParseSheet"));
NS_PRECONDITION(aStream, "Must have data to parse");
NS_PRECONDITION(aLoadData, "Must have load data");
NS_PRECONDITION(aSheetURI, "Must have sheet URI");
NS_PRECONDITION(aLoadData->mSheet, "Must have sheet to parse into");
aCompleted = PR_FALSE;
// Init the sheet with the correct URI so that the relative URIs in
// it will be resolved properly.
nsresult rv = aLoadData->mSheet->Init(aSheetURI);
NS_ASSERTION(NS_SUCCEEDED(rv),
"If this is failing, something has gone terribly wrong");
nsCOMPtr<nsICSSParser> parser;
rv = GetParserFor(aLoadData->mSheet, getter_AddRefs(parser));
nsresult rv = GetParserFor(aLoadData->mSheet, getter_AddRefs(parser));
if (NS_FAILED(rv)) {
LOG_ERROR((" Failed to get CSS parser"));
SheetComplete(aLoadData, PR_FALSE);
@ -1422,7 +1425,9 @@ CSSLoaderImpl::ParseSheet(nsIUnicharInputStream* aStream,
nsCOMPtr<nsICSSStyleSheet> dummySheet;
// Push our load data on the stack so any kids can pick it up
mParsingDatas.AppendElement(aLoadData);
rv = parser->Parse(aStream, aSheetURI, *getter_AddRefs(dummySheet));
nsCOMPtr<nsIURI> uri;
aLoadData->mSheet->GetURL(*getter_AddRefs(uri));
rv = parser->Parse(aStream, uri, *getter_AddRefs(dummySheet));
mParsingDatas.RemoveElementAt(mParsingDatas.Count() - 1);
RecycleParser(parser);
@ -1610,12 +1615,9 @@ CSSLoaderImpl::LoadInlineStyle(nsIContent* aElement,
return NS_ERROR_OUT_OF_MEMORY;
}
nsCOMPtr<nsIURI> baseURI;
aElement->GetBaseURL(getter_AddRefs(baseURI));
NS_ADDREF(data);
// Parse completion releases the load data
return ParseSheet(aStream, data, baseURI, aCompleted);
return ParseSheet(aStream, data, aCompleted);
}
NS_IMETHODIMP

Просмотреть файл

@ -286,7 +286,6 @@ protected:
// access to
nsresult ParseSheet(nsIUnicharInputStream* aStream,
SheetLoadData* aLoadData,
nsIURI* aSheetURI,
PRBool& aCompleted);
public:

Просмотреть файл

@ -805,7 +805,7 @@ public:
NS_DECL_ISUPPORTS
// basic style sheet data
NS_IMETHOD Init(nsIURI* aURL);
NS_IMETHOD SetURL(nsIURI* aURL);
NS_IMETHOD GetURL(nsIURI*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD SetTitle(const nsAString& aTitle);
@ -1780,7 +1780,7 @@ CSSStyleSheetImpl::DropRuleProcessorReference(nsICSSStyleRuleProcessor* aProcess
NS_IMETHODIMP
CSSStyleSheetImpl::Init(nsIURI* aURL)
CSSStyleSheetImpl::SetURL(nsIURI* aURL)
{
NS_PRECONDITION(aURL, "null ptr");
if (! aURL)
@ -1790,9 +1790,8 @@ CSSStyleSheetImpl::Init(nsIURI* aURL)
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ASSERTION(! mInner->mURL, "already initialized");
if (mInner->mURL)
return NS_ERROR_ALREADY_INITIALIZED;
NS_ASSERTION(!mInner->mOrderedRules && !mInner->mComplete,
"Can't call SetURL on sheets that are complete or have rules");
mInner->mURL = aURL;
return NS_OK;
@ -3059,7 +3058,7 @@ NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURI* aURL)
if (NS_FAILED(rv = NS_NewCSSStyleSheet(&sheet)))
return rv;
if (NS_FAILED(rv = sheet->Init(aURL))) {
if (NS_FAILED(rv = sheet->SetURL(aURL))) {
NS_RELEASE(sheet);
return rv;
}

Просмотреть файл

@ -76,7 +76,12 @@ public:
NS_IMETHOD StyleSheetCount(PRInt32& aCount) const = 0;
NS_IMETHOD GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const = 0;
NS_IMETHOD Init(nsIURI* aURL) = 0;
/**
* SetURL must be called on all sheets before parsing into them.
* SetURL may only be called while the sheet is 1) incomplete and 2)
* has no rules in it
*/
NS_IMETHOD SetURL(nsIURI* aURL) = 0;
NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
NS_IMETHOD AppendMedium(nsIAtom* aMedium) = 0;
NS_IMETHOD ClearMedia(void) = 0;