Bug 606498 - Make sure the new nsIScriptError2 is used in all possible places- part 3; r=bzbarsky,dbaron,mrbkap sr=jst a=blocking2.0

This commit is contained in:
Mihai Sucan 2010-12-20 12:21:59 -04:00
Родитель e351deb22c
Коммит 5676e1f24c
9 изменённых файлов: 125 добавлений и 22 удалений

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

@ -868,7 +868,12 @@ nsCanvasRenderingContext2D::SetStyleFromStringOrInterface(const nsAString& aStr,
nscolor color;
if (!aStr.IsVoid()) {
nsCSSParser parser;
nsIDocument* document = mCanvasElement ?
HTMLCanvasElement()->GetOwnerDoc() : nsnull;
// Pass the CSS Loader object to the parser, to allow parser error
// reports to include the outer window ID.
nsCSSParser parser(document ? document->CSSLoader() : nsnull);
rv = parser.ParseColorString(aStr, nsnull, 0, &color);
if (NS_FAILED(rv)) {
// Error reporting happens inside the CSS parser
@ -1724,7 +1729,12 @@ nsCanvasRenderingContext2D::GetShadowBlur(float *blur)
NS_IMETHODIMP
nsCanvasRenderingContext2D::SetShadowColor(const nsAString& colorstr)
{
nsCSSParser parser;
nsIDocument* document = mCanvasElement ?
HTMLCanvasElement()->GetOwnerDoc() : nsnull;
// Pass the CSS Loader object to the parser, to allow parser error reports
// to include the outer window ID.
nsCSSParser parser(document ? document->CSSLoader() : nsnull);
nscolor color;
nsresult rv = parser.ParseColorString(colorstr, nsnull, 0, &color);
if (NS_FAILED(rv)) {
@ -2170,9 +2180,6 @@ CreateFontStyleRule(const nsAString& aFont,
nsINode* aNode,
nsICSSStyleRule** aResult)
{
nsCSSParser parser;
NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsICSSStyleRule> rule;
PRBool changed;
@ -2182,6 +2189,11 @@ CreateFontStyleRule(const nsAString& aFont,
nsIURI* docURL = document->GetDocumentURI();
nsIURI* baseURL = document->GetDocBaseURI();
// Pass the CSS Loader object to the parser, to allow parser error reports
// to include the outer window ID.
nsCSSParser parser(document->CSSLoader());
NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = parser.ParseStyleAttribute(EmptyString(), docURL, baseURL,
principal, getter_AddRefs(rule));
if (NS_FAILED(rv))
@ -3607,7 +3619,13 @@ nsCanvasRenderingContext2D::DrawWindow(nsIDOMWindow* aWindow, float aX, float aY
return NS_ERROR_FAILURE;
nscolor bgColor;
nsCSSParser parser;
nsIDocument* elementDoc = mCanvasElement ?
HTMLCanvasElement()->GetOwnerDoc() : nsnull;
// Pass the CSS Loader object to the parser, to allow parser error reports
// to include the outer window ID.
nsCSSParser parser(elementDoc ? elementDoc->CSSLoader() : nsnull);
NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = parser.ParseColorString(PromiseFlatString(aBGColor),
nsnull, 0, &bgColor);

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

@ -1046,7 +1046,10 @@ nsHTMLParanoidFragmentSink::AddAttributes(const nsIParserNode& aNode,
if (!baseURI) {
baseURI = aContent->GetBaseURI();
}
nsCSSParser parser;
// Pass the CSS Loader object to the parser, to allow parser error reports
// to include the outer window ID.
nsCSSParser parser(mTargetDocument->CSSLoader());
nsCOMPtr<nsICSSStyleRule> rule;
rv = parser.ParseStyleAttribute(aNode.GetValueAt(i),
mTargetDocument->GetDocumentURI(),

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

@ -946,7 +946,7 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
errorMessage,
strings, NS_ARRAY_LENGTH(strings),
referrer, EmptyString(), 0, 0, errorFlag,
"CSS Loader");
"CSS Loader", mLoader->mDocument);
if (errorFlag == nsIScriptError::errorFlag) {
LOG_WARN((" Ignoring sheet with improper MIME type %s",

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

@ -329,6 +329,11 @@ public:
PRBool GetEnabled() { return mEnabled; }
void SetEnabled(PRBool aEnabled) { mEnabled = aEnabled; }
/**
* Get the document we live for. May return null.
*/
nsIDocument* GetDocument() const { return mDocument; }
/**
* Return true if this loader has pending loads (ones that would send
* notifications to an nsICSSLoaderObserver attached to this loader).

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

@ -807,7 +807,8 @@ CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aSheetURI,
{
NS_ASSERTION(! mScannerInited, "already have scanner");
mScanner.Init(aInput, nsnull, 0, aSheetURI, aLineNumber);
mScanner.Init(aInput, nsnull, 0, aSheetURI, aLineNumber, mSheet,
mChildLoader);
#ifdef DEBUG
mScannerInited = PR_TRUE;
#endif
@ -827,7 +828,8 @@ CSSParserImpl::InitScanner(const nsSubstring& aString, nsIURI* aSheetURI,
// the stream until we're done parsing.
NS_ASSERTION(! mScannerInited, "already have scanner");
mScanner.Init(nsnull, aString.BeginReading(), aString.Length(), aSheetURI, aLineNumber);
mScanner.Init(nsnull, aString.BeginReading(), aString.Length(), aSheetURI,
aLineNumber, mSheet, mChildLoader);
#ifdef DEBUG
mScannerInited = PR_TRUE;

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

@ -58,6 +58,8 @@
#include "nsIStringBundle.h"
#include "nsContentUtils.h"
#include "mozilla/Services.h"
#include "mozilla/css/Loader.h"
#include "nsCSSStyleSheet.h"
#ifdef CSS_REPORT_PARSE_ERRORS
static PRBool gReportErrors = PR_TRUE;
@ -266,6 +268,10 @@ nsCSSScanner::nsCSSScanner()
, mSVGMode(PR_FALSE)
#ifdef CSS_REPORT_PARSE_ERRORS
, mError(mErrorBuf, NS_ARRAY_LENGTH(mErrorBuf), 0)
, mWindowID(0)
, mWindowIDCached(PR_FALSE)
, mSheet(nsnull)
, mLoader(nsnull)
#endif
{
MOZ_COUNT_CTOR(nsCSSScanner);
@ -345,7 +351,8 @@ nsCSSScanner::ReleaseGlobals()
void
nsCSSScanner::Init(nsIUnicharInputStream* aInput,
const PRUnichar * aBuffer, PRUint32 aCount,
nsIURI* aURI, PRUint32 aLineNumber)
nsIURI* aURI, PRUint32 aLineNumber,
nsCSSStyleSheet* aSheet, mozilla::css::Loader* aLoader)
{
NS_PRECONDITION(!mInputStream, "Should not have an existing input stream!");
NS_PRECONDITION(!mReadPointer, "Should not have an existing input buffer!");
@ -386,6 +393,8 @@ nsCSSScanner::Init(nsIUnicharInputStream* aInput,
#ifdef CSS_REPORT_PARSE_ERRORS
mColNumber = 0;
mSheet = aSheet;
mLoader = aLoader;
#endif
}
@ -421,19 +430,35 @@ nsCSSScanner::OutputError()
// Log it to the Error console
if (InitGlobals() && gReportErrors) {
if (!mWindowIDCached) {
if (mSheet) {
mWindowID = mSheet->FindOwningWindowID();
}
if (mWindowID == 0 && mLoader) {
nsIDocument* doc = mLoader->GetDocument();
if (doc) {
mWindowID = doc->OuterWindowID();
}
}
mWindowIDCached = PR_TRUE;
}
nsresult rv;
nsCOMPtr<nsIScriptError> errorObject =
nsCOMPtr<nsIScriptError2> errorObject =
do_CreateInstance(gScriptErrorFactory, &rv);
if (NS_SUCCEEDED(rv)) {
rv = errorObject->Init(mError.get(),
NS_ConvertUTF8toUTF16(mFileName).get(),
EmptyString().get(),
mErrorLineNumber,
mErrorColNumber,
nsIScriptError::warningFlag,
"CSS Parser");
if (NS_SUCCEEDED(rv))
gConsoleService->LogMessage(errorObject);
rv = errorObject->InitWithWindowID(mError.get(),
NS_ConvertUTF8toUTF16(mFileName).get(),
EmptyString().get(),
mErrorLineNumber,
mErrorColNumber,
nsIScriptError::warningFlag,
"CSS Parser", mWindowID);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIScriptError> logError = do_QueryInterface(errorObject);
gConsoleService->LogMessage(logError);
}
}
}
ClearError();
@ -580,6 +605,10 @@ nsCSSScanner::Close()
mFileName.Truncate();
mURI = nsnull;
mError.Truncate();
mWindowID = 0;
mWindowIDCached = PR_FALSE;
mSheet = nsnull;
mLoader = nsnull;
#endif
if (mPushback != mLocalPushback) {
delete [] mPushback;

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

@ -44,6 +44,9 @@
#include "nsString.h"
#include "nsCOMPtr.h"
#include "mozilla/css/Loader.h"
#include "nsCSSStyleSheet.h"
class nsIUnicharInputStream;
// XXX turn this off for minimo builds
@ -142,7 +145,8 @@ class nsCSSScanner {
// Either aInput or (aBuffer and aCount) must be set.
void Init(nsIUnicharInputStream* aInput,
const PRUnichar *aBuffer, PRUint32 aCount,
nsIURI* aURI, PRUint32 aLineNumber);
nsIURI* aURI, PRUint32 aLineNumber,
nsCSSStyleSheet* aSheet, mozilla::css::Loader* aLoader);
void Close();
static PRBool InitGlobals();
@ -244,6 +248,10 @@ protected:
PRUint32 mErrorLineNumber, mColNumber, mErrorColNumber;
nsFixedString mError;
PRUnichar mErrorBuf[200];
PRUint64 mWindowID;
PRBool mWindowIDCached;
nsCSSStyleSheet* mSheet;
mozilla::css::Loader* mLoader;
#endif
};

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

@ -1247,6 +1247,41 @@ nsCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
}
}
/* virtual */ PRUint64
nsCSSStyleSheet::FindOwningWindowID() const
{
PRUint64 windowID = 0;
if (mDocument) {
windowID = mDocument->OuterWindowID();
}
if (windowID == 0 && mOwningNode) {
nsCOMPtr<nsIContent> node = do_QueryInterface(mOwningNode);
if (node) {
nsIDocument* doc = node->GetOwnerDoc();
if (doc) {
windowID = doc->OuterWindowID();
}
}
}
if (windowID == 0 && mOwnerRule) {
nsCOMPtr<nsIStyleSheet> sheet = mOwnerRule->GetStyleSheet();
if (sheet) {
nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(sheet);
if (cssSheet) {
windowID = cssSheet->FindOwningWindowID();
}
}
}
if (windowID == 0 && mParent) {
windowID = mParent->FindOwningWindowID();
}
return windowID;
}
void
nsCSSStyleSheet::AppendStyleSheet(nsCSSStyleSheet* aSheet)
{

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

@ -149,6 +149,9 @@ public:
virtual nsIStyleSheet* GetParentSheet() const; // may be null
virtual nsIDocument* GetOwningDocument() const; // may be null
virtual void SetOwningDocument(nsIDocument* aDocument);
// Find the ID of the owner outer window.
virtual PRUint64 FindOwningWindowID() const;
#ifdef DEBUG
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
#endif