Use nsContentUtils for error-reporting for <area> parsing. Bug 269697,

r+sr=jst
This commit is contained in:
bzbarsky%mit.edu 2004-11-23 17:45:37 +00:00
parent 523d72e483
commit 095f0fe791
8 changed files with 57 additions and 117 deletions

View File

@ -454,6 +454,8 @@ public:
* @param aParams Parameters to be substituted into localized message.
* @param aParamsLength Length of aParams.
* @param aURI URI of resource containing error (may be null).
* @param aSourceLine The text of the line that contains the error (may be
empty).
* @param aLineNumber Line number within resource containing error.
* @param aColumnNumber Column number within resource containing error.
* @param aErrorFlags See nsIScriptError.
@ -463,6 +465,7 @@ public:
eCSS_PROPERTIES,
eXBL_PROPERTIES,
eXUL_PROPERTIES,
eLAYOUT_PROPERTIES,
PropertiesFile_COUNT
};
static nsresult ReportToConsole(PropertiesFile aFile,
@ -470,6 +473,7 @@ public:
const PRUnichar **aParams,
PRUint32 aParamsLength,
nsIURI* aURI,
const nsAFlatString& aSourceLine,
PRUint32 aLineNumber,
PRUint32 aColumnNumber,
PRUint32 aErrorFlags,

View File

@ -2085,11 +2085,12 @@ nsCxPusher::Pop()
mScriptIsRunning = PR_FALSE;
}
static const char gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT][38] = {
static const char gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT][48] = {
// Must line up with the enum values in |PropertiesFile| enum.
"chrome://global/locale/css.properties",
"chrome://global/locale/xbl.properties",
"chrome://global/locale/xul.properties"
"chrome://global/locale/xul.properties",
"chrome://global/locale/layout_errors.properties"
};
/* static */ nsresult
@ -2098,6 +2099,7 @@ nsContentUtils::ReportToConsole(PropertiesFile aFile,
const PRUnichar **aParams,
PRUint32 aParamsLength,
nsIURI* aURI,
const nsAFlatString& aSourceLine,
PRUint32 aLineNumber,
PRUint32 aColumnNumber,
PRUint32 aErrorFlags,
@ -2134,7 +2136,7 @@ nsContentUtils::ReportToConsole(PropertiesFile aFile,
NS_ENSURE_SUCCESS(rv, rv);
rv = errorObject->Init(errorText.get(),
NS_ConvertUTF8toUTF16(spec).get(), // file name
EmptyString().get(), // source line
aSourceLine.get(),
aLineNumber, aColumnNumber,
aErrorFlags, aCategory);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -779,7 +779,7 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
nsContentUtils::ReportToConsole(nsContentUtils::eCSS_PROPERTIES,
errorMessage,
strings, NS_ARRAY_LENGTH(strings),
referrer, 0, 0, errorFlag,
referrer, EmptyString(), 0, 0, errorFlag,
"CSS Loader");
}
}

View File

@ -250,6 +250,7 @@ nsXBLContentSink::ReportUnexpectedElement(nsIAtom* aElementName,
"UnexpectedElement",
params, NS_ARRAY_LENGTH(params),
mDocumentURI,
EmptyString() /* source line */,
aLineNumber, 0 /* column number */,
nsIScriptError::errorFlag,
"XBL Content Sink");

View File

@ -3018,6 +3018,7 @@ nsXULDocument::ReportMissingOverlay(nsIURI* aURI)
"MissingOverlay",
params, NS_ARRAY_LENGTH(params),
mDocumentURI,
EmptyString(), /* source line */
0, /* line number */
0, /* column number */
nsIScriptError::warningFlag,

View File

@ -141,59 +141,25 @@ is_space(char c)
static void logMessage(nsIContent* aContent,
const nsAString& aCoordsSpec,
PRInt32 aFlags,
const PRUnichar* aMessageName) {
nsresult rv;
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIScriptError> errorObject =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIStringBundleService> stringBundleService =
do_GetService(kCStringBundleServiceCID, &rv);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIStringBundle> bundle;
rv = stringBundleService->CreateBundle(
"chrome://global/locale/layout_errors.properties",
getter_AddRefs(bundle));
if (NS_FAILED(rv))
return;
nsXPIDLString errorText;
rv =
bundle->FormatStringFromName(aMessageName,
nsnull, 0,
getter_Copies(errorText));
if (NS_FAILED(rv))
return;
// XXX GetOwnerDocument
nsINodeInfo *nodeInfo = aContent->GetNodeInfo();
NS_ASSERTION(nodeInfo, "Element with no nodeinfo");
nsIDocument* doc = nsContentUtils::GetDocument(nodeInfo);
nsCAutoString urlSpec;
const char* aMessageName) {
nsIURL* documentURI = nsnull;
nsIDocument* doc = aContent->GetOwnerDoc();
if (doc) {
nsIURI *uri = doc->GetDocumentURI();
if (uri) {
uri->GetSpec(urlSpec);
}
documentURI = doc->GetDocumentURI();
}
rv = errorObject->Init(errorText.get(),
NS_ConvertUTF8toUCS2(urlSpec).get(), /* file name */
PromiseFlatString(NS_LITERAL_STRING("coords=\"") +
aCoordsSpec +
NS_LITERAL_STRING("\"")).get(), /* source line */
0, /* line number */
0, /* column number */
aFlags,
"ImageMap");
if (NS_FAILED(rv))
return;
consoleService->LogMessage(errorObject);
nsContentUtils::ReportToConsole(
nsContentUtils::eLAYOUT_PROPERTIES,
aMessageName,
nsnull, /* params */
0, /* params length */
documentURI,
PromiseFlatString(NS_LITERAL_STRING("coords=\"") +
aCoordsSpec +
NS_LITERAL_STRING("\"")), /* source line */
0, /* line number */
0, /* column number */
aFlags,
"ImageMap");
}
// XXX straight copy from laymap.c
@ -445,7 +411,7 @@ void RectArea::ParseCoords(const nsAString& aSpec)
}
if (!saneRect) {
logMessage(mArea, aSpec, flag, NS_LITERAL_STRING("ImageMapRectBoundsError").get());
logMessage(mArea, aSpec, flag, "ImageMapRectBoundsError");
}
}
@ -528,13 +494,13 @@ void PolyArea::ParseCoords(const nsAString& aSpec)
logMessage(mArea,
aSpec,
nsIScriptError::warningFlag,
NS_LITERAL_STRING("ImageMapPolyOddNumberOfCoords").get());
"ImageMapPolyOddNumberOfCoords");
}
} else {
logMessage(mArea,
aSpec,
nsIScriptError::errorFlag,
NS_LITERAL_STRING("ImageMapPolyWrongNumberOfCoords").get());
"ImageMapPolyWrongNumberOfCoords");
}
}
@ -673,7 +639,7 @@ void CircleArea::ParseCoords(const nsAString& aSpec)
logMessage(mArea,
aSpec,
nsIScriptError::errorFlag,
NS_LITERAL_STRING("ImageMapCircleNegativeRadius").get());
"ImageMapCircleNegativeRadius");
}
if (mNumCoords > 3) {
@ -688,7 +654,7 @@ void CircleArea::ParseCoords(const nsAString& aSpec)
logMessage(mArea,
aSpec,
flag,
NS_LITERAL_STRING("ImageMapCircleWrongNumberOfCoords").get());
"ImageMapCircleWrongNumberOfCoords");
}
}

View File

@ -141,59 +141,25 @@ is_space(char c)
static void logMessage(nsIContent* aContent,
const nsAString& aCoordsSpec,
PRInt32 aFlags,
const PRUnichar* aMessageName) {
nsresult rv;
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIScriptError> errorObject =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIStringBundleService> stringBundleService =
do_GetService(kCStringBundleServiceCID, &rv);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIStringBundle> bundle;
rv = stringBundleService->CreateBundle(
"chrome://global/locale/layout_errors.properties",
getter_AddRefs(bundle));
if (NS_FAILED(rv))
return;
nsXPIDLString errorText;
rv =
bundle->FormatStringFromName(aMessageName,
nsnull, 0,
getter_Copies(errorText));
if (NS_FAILED(rv))
return;
// XXX GetOwnerDocument
nsINodeInfo *nodeInfo = aContent->GetNodeInfo();
NS_ASSERTION(nodeInfo, "Element with no nodeinfo");
nsIDocument* doc = nsContentUtils::GetDocument(nodeInfo);
nsCAutoString urlSpec;
const char* aMessageName) {
nsIURL* documentURI = nsnull;
nsIDocument* doc = aContent->GetOwnerDoc();
if (doc) {
nsIURI *uri = doc->GetDocumentURI();
if (uri) {
uri->GetSpec(urlSpec);
}
documentURI = doc->GetDocumentURI();
}
rv = errorObject->Init(errorText.get(),
NS_ConvertUTF8toUCS2(urlSpec).get(), /* file name */
PromiseFlatString(NS_LITERAL_STRING("coords=\"") +
aCoordsSpec +
NS_LITERAL_STRING("\"")).get(), /* source line */
0, /* line number */
0, /* column number */
aFlags,
"ImageMap");
if (NS_FAILED(rv))
return;
consoleService->LogMessage(errorObject);
nsContentUtils::ReportToConsole(
nsContentUtils::eLAYOUT_PROPERTIES,
aMessageName,
nsnull, /* params */
0, /* params length */
documentURI,
PromiseFlatString(NS_LITERAL_STRING("coords=\"") +
aCoordsSpec +
NS_LITERAL_STRING("\"")), /* source line */
0, /* line number */
0, /* column number */
aFlags,
"ImageMap");
}
// XXX straight copy from laymap.c
@ -445,7 +411,7 @@ void RectArea::ParseCoords(const nsAString& aSpec)
}
if (!saneRect) {
logMessage(mArea, aSpec, flag, NS_LITERAL_STRING("ImageMapRectBoundsError").get());
logMessage(mArea, aSpec, flag, "ImageMapRectBoundsError");
}
}
@ -528,13 +494,13 @@ void PolyArea::ParseCoords(const nsAString& aSpec)
logMessage(mArea,
aSpec,
nsIScriptError::warningFlag,
NS_LITERAL_STRING("ImageMapPolyOddNumberOfCoords").get());
"ImageMapPolyOddNumberOfCoords");
}
} else {
logMessage(mArea,
aSpec,
nsIScriptError::errorFlag,
NS_LITERAL_STRING("ImageMapPolyWrongNumberOfCoords").get());
"ImageMapPolyWrongNumberOfCoords");
}
}
@ -673,7 +639,7 @@ void CircleArea::ParseCoords(const nsAString& aSpec)
logMessage(mArea,
aSpec,
nsIScriptError::errorFlag,
NS_LITERAL_STRING("ImageMapCircleNegativeRadius").get());
"ImageMapCircleNegativeRadius");
}
if (mNumCoords > 3) {
@ -688,7 +654,7 @@ void CircleArea::ParseCoords(const nsAString& aSpec)
logMessage(mArea,
aSpec,
flag,
NS_LITERAL_STRING("ImageMapCircleWrongNumberOfCoords").get());
"ImageMapCircleWrongNumberOfCoords");
}
}

View File

@ -779,7 +779,7 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
nsContentUtils::ReportToConsole(nsContentUtils::eCSS_PROPERTIES,
errorMessage,
strings, NS_ARRAY_LENGTH(strings),
referrer, 0, 0, errorFlag,
referrer, EmptyString(), 0, 0, errorFlag,
"CSS Loader");
}
}