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

This commit is contained in:
Mihai Sucan 2010-12-20 12:21:58 -04:00
parent 2478390f1c
commit 116aa5fbdc
18 changed files with 128 additions and 64 deletions

View File

@ -807,6 +807,8 @@ public:
* @param aColumnNumber Column number within resource containing error.
* @param aErrorFlags See nsIScriptError.
* @param aCategory Name of module reporting error.
* @param [aWindowId=0] (Optional) The window ID of the outer window the
* message originates from.
*/
enum PropertiesFile {
eCSS_PROPERTIES,
@ -832,7 +834,36 @@ public:
PRUint32 aLineNumber,
PRUint32 aColumnNumber,
PRUint32 aErrorFlags,
const char *aCategory);
const char *aCategory,
PRUint64 aWindowId = 0);
/**
* Report a localized error message to the error console.
* @param aFile Properties file containing localized message.
* @param aMessageName Name of localized message.
* @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.
* @param aCategory Name of module reporting error.
* @param aDocument Reference to the document which triggered the message.
If aURI is null, then aDocument->GetDocumentURI() is used.
*/
static nsresult ReportToConsole(PropertiesFile aFile,
const char *aMessageName,
const PRUnichar **aParams,
PRUint32 aParamsLength,
nsIURI* aURI,
const nsAFlatString& aSourceLine,
PRUint32 aLineNumber,
PRUint32 aColumnNumber,
PRUint32 aErrorFlags,
const char *aCategory,
nsIDocument* aDocument);
/**
* Get the localized string named |aKey| in properties file |aFile|.

View File

@ -3115,7 +3115,8 @@ nsContentUtils::ReportToConsole(PropertiesFile aFile,
PRUint32 aLineNumber,
PRUint32 aColumnNumber,
PRUint32 aErrorFlags,
const char *aCategory)
const char *aCategory,
PRUint64 aWindowId)
{
NS_ASSERTION((aParams && aParamsLength) || (!aParams && !aParamsLength),
"Supply either both parameters and their number or no"
@ -3141,17 +3142,46 @@ nsContentUtils::ReportToConsole(PropertiesFile aFile,
if (aURI)
aURI->GetSpec(spec);
nsCOMPtr<nsIScriptError> errorObject =
nsCOMPtr<nsIScriptError2> errorObject =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = errorObject->Init(errorText.get(),
NS_ConvertUTF8toUTF16(spec).get(), // file name
aSourceLine.get(),
aLineNumber, aColumnNumber,
aErrorFlags, aCategory);
rv = errorObject->InitWithWindowID(errorText.get(),
NS_ConvertUTF8toUTF16(spec).get(), // file name
aSourceLine.get(),
aLineNumber, aColumnNumber,
aErrorFlags, aCategory, aWindowId);
NS_ENSURE_SUCCESS(rv, rv);
return sConsoleService->LogMessage(errorObject);
nsCOMPtr<nsIScriptError> logError = do_QueryInterface(errorObject);
return sConsoleService->LogMessage(logError);
}
/* static */ nsresult
nsContentUtils::ReportToConsole(PropertiesFile aFile,
const char *aMessageName,
const PRUnichar **aParams,
PRUint32 aParamsLength,
nsIURI* aURI,
const nsAFlatString& aSourceLine,
PRUint32 aLineNumber,
PRUint32 aColumnNumber,
PRUint32 aErrorFlags,
const char *aCategory,
nsIDocument* aDocument)
{
nsIURI* uri = aURI;
PRUint64 windowID = 0;
if (aDocument) {
if (!uri) {
uri = aDocument->GetDocumentURI();
}
windowID = aDocument->OuterWindowID();
}
return ReportToConsole(aFile, aMessageName, aParams, aParamsLength, uri,
aSourceLine, aLineNumber, aColumnNumber, aErrorFlags,
aCategory, windowID);
}
PRBool

View File

@ -3990,7 +3990,6 @@ nsDocument::BeginLoad()
NS_DOCUMENT_NOTIFY_OBSERVERS(BeginLoad, (this));
}
// static
void
nsDocument::ReportEmptyGetElementByIdArg()
{
@ -4000,7 +3999,7 @@ nsDocument::ReportEmptyGetElementByIdArg()
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM");
"DOM", this);
}
Element*
@ -5296,11 +5295,10 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
"UseOfGetBoxObjectForWarning",
nsnull, 0,
static_cast<nsIDocument*>(this)->
GetDocumentURI(),
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"BoxObjects");
"BoxObjects", this);
}
*aResult = nsnull;

View File

@ -992,7 +992,7 @@ protected:
* service if it is.
* @returns PR_TRUE if aId looks correct, PR_FALSE otherwise.
*/
static inline PRBool CheckGetElementByIdArg(const nsAString& aId)
inline PRBool CheckGetElementByIdArg(const nsAString& aId)
{
if (aId.IsEmpty()) {
ReportEmptyGetElementByIdArg();
@ -1001,7 +1001,7 @@ protected:
return PR_TRUE;
}
static void ReportEmptyGetElementByIdArg();
void ReportEmptyGetElementByIdArg();
void DispatchContentLoadedEvents();

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 et tw=78: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -903,7 +904,8 @@ nsCanvasRenderingContext2D::SetStyleFromStringOrInterface(const nsAString& aStr,
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"Canvas");
"Canvas",
mCanvasElement ? HTMLCanvasElement()->GetOwnerDoc() : nsnull);
return NS_OK;
}

View File

@ -440,10 +440,10 @@ ReportUseOfDeprecatedMethod(nsEvent* aEvent, nsIDOMEvent* aDOMEvent,
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
aWarning,
strings, NS_ARRAY_LENGTH(strings),
doc ? doc->GetDocumentURI() : nsnull,
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM Events");
"DOM Events", doc);
}
NS_IMETHODIMP

View File

@ -78,11 +78,10 @@ SendJSWarning(nsIDocument* aDocument,
nsContentUtils::ReportToConsole(nsContentUtils::eFORMS_PROPERTIES,
aWarningName,
aWarningArgs, aWarningArgsLen,
aDocument ? aDocument->GetDocumentURI() :
nsnull,
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"HTML");
"HTML", aDocument);
}
// --------------------------------------------------------------------------

View File

@ -213,11 +213,10 @@ ReportUseOfDeprecatedMethod(nsHTMLDocument* aDoc, const char* aWarning)
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
aWarning,
nsnull, 0,
static_cast<nsIDocument*>(aDoc)->
GetDocumentURI(),
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM Events");
"DOM Events", aDoc);
}
static nsresult
@ -2151,7 +2150,7 @@ nsHTMLDocument::WriteCommon(const nsAString& aText,
mDocumentURI,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM Events");
"DOM Events", this);
return NS_OK;
}
mWriteState = eDocumentClosed;
@ -2168,7 +2167,7 @@ nsHTMLDocument::WriteCommon(const nsAString& aText,
mDocumentURI,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM Events");
"DOM Events", this);
return NS_OK;
}
rv = Open();

View File

@ -247,11 +247,12 @@ nsXBLContentSink::ReportUnexpectedElement(nsIAtom* aElementName,
return nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
"UnexpectedElement",
params, NS_ARRAY_LENGTH(params),
mDocumentURI,
nsnull,
EmptyString() /* source line */,
aLineNumber, 0 /* column number */,
nsIScriptError::errorFlag,
"XBL Content Sink");
"XBL Content Sink",
mDocument);
}
void
@ -664,11 +665,12 @@ nsXBLContentSink::ConstructHandler(const PRUnichar **aAtts, PRUint32 aLineNumber
mState = eXBL_Error;
nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
"CommandNotInChrome", nsnull, 0,
mDocumentURI,
nsnull,
EmptyString() /* source line */,
aLineNumber, 0 /* column number */,
nsIScriptError::errorFlag,
"XBL Content Sink");
"XBL Content Sink",
mDocument);
return; // Don't even make this handler.
}

View File

@ -973,16 +973,23 @@ nsXBLPrototypeHandler::ConstructPrototype(nsIContent* aKeyElement,
void
nsXBLPrototypeHandler::ReportKeyConflict(const PRUnichar* aKey, const PRUnichar* aModifiers, nsIContent* aKeyElement, const char *aMessageName)
{
nsIURI* uri = mPrototypeBinding ? mPrototypeBinding->DocURI() :
aKeyElement ? aKeyElement->GetOwnerDoc()->GetDocumentURI() :
nsnull;
nsCOMPtr<nsIDocument> doc;
if (mPrototypeBinding) {
nsXBLDocumentInfo* docInfo = mPrototypeBinding->XBLDocumentInfo();
if (docInfo) {
doc = docInfo->GetDocument();
}
} else if (aKeyElement) {
doc = aKeyElement->GetOwnerDoc();
}
const PRUnichar* params[] = { aKey, aModifiers };
nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
aMessageName,
params, NS_ARRAY_LENGTH(params),
uri, EmptyString(), mLineNumber, 0,
nsnull, EmptyString(), mLineNumber, 0,
nsIScriptError::warningFlag,
"XBL Prototype Handler");
"XBL Prototype Handler", doc);
}
PRBool

View File

@ -134,10 +134,10 @@ IsAncestorBinding(nsIDocument* aDocument,
nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
"TooDeepBindingRecursion",
params, NS_ARRAY_LENGTH(params),
aDocument->GetDocumentURI(),
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"XBL");
"XBL", aDocument);
return PR_TRUE;
}
}
@ -978,10 +978,10 @@ nsXBLService::GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
"InvalidExtendsBinding",
params, NS_ARRAY_LENGTH(params),
doc->GetDocumentURI(),
nsnull,
EmptyString(), 0, 0,
nsIScriptError::errorFlag,
"XBL");
"XBL", doc);
NS_ASSERTION(!IsChromeOrResourceURI(aURI),
"Invalid extends value");
return NS_ERROR_ILLEGAL_VALUE;
@ -1014,10 +1014,10 @@ nsXBLService::GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES,
"CircularExtendsBinding",
params, NS_ARRAY_LENGTH(params),
boundDocument->GetDocumentURI(),
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"XBL");
"XBL", boundDocument);
return NS_ERROR_ILLEGAL_VALUE;
}
}

View File

@ -325,10 +325,10 @@ ReportUseOfDeprecatedMethod(nsIDocument *aDoc, const char* aWarning)
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
aWarning,
nsnull, 0,
aDoc->GetDocumentURI(),
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM3 Load");
"DOM3 Load", aDoc);
}
NS_IMETHODIMP

View File

@ -3330,16 +3330,15 @@ nsXULDocument::ReportMissingOverlay(nsIURI* aURI)
NS_ConvertUTF8toUTF16 utfSpec(spec);
const PRUnichar* params[] = { utfSpec.get() };
nsContentUtils::ReportToConsole(nsContentUtils::eXUL_PROPERTIES,
"MissingOverlay",
params, NS_ARRAY_LENGTH(params),
mDocumentURI,
nsnull,
EmptyString(), /* source line */
0, /* line number */
0, /* column number */
nsIScriptError::warningFlag,
"XUL Document");
"XUL Document", this);
}
nsresult

View File

@ -5350,10 +5350,10 @@ ReportUseOfDeprecatedMethod(nsGlobalWindow* aWindow, const char* aWarning)
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
aWarning,
nsnull, 0,
doc ? doc->GetDocumentURI() : nsnull,
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"DOM Events");
"DOM Events", doc);
}
NS_IMETHODIMP
@ -6048,11 +6048,10 @@ nsGlobalWindow::Close()
nsContentUtils::eDOM_PROPERTIES,
"WindowCloseBlockedWarning",
nsnull, 0, // No params
nsnull, // No URI. Not clear which URI we should be using
// here anyway
nsnull,
EmptyString(), 0, 0, // No source, or column/line number
nsIScriptError::warningFlag,
"DOM Window"); // Better name for the category?
"DOM Window", mDoc); // Better name for the category?
return NS_OK;
}

View File

@ -9667,10 +9667,10 @@ nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState& aState,
nsContentUtils::ReportToConsole(nsContentUtils::eXUL_PROPERTIES,
message,
params, NS_ARRAY_LENGTH(params),
mDocument->GetDocumentURI(),
nsnull,
EmptyString(), 0, 0, // not useful
nsIScriptError::warningFlag,
"FrameConstructor");
"FrameConstructor", mDocument);
nsRefPtr<nsStyleContext> blockSC = mPresShell->StyleSet()->
ResolveAnonymousBoxStyle(nsCSSAnonBoxes::mozXULAnonymousBlock,

View File

@ -124,24 +124,21 @@ static void logMessage(nsIContent* aContent,
const nsAString& aCoordsSpec,
PRInt32 aFlags,
const char* aMessageName) {
nsIURI* documentURI = nsnull;
nsIDocument* doc = aContent->GetOwnerDoc();
if (doc) {
documentURI = doc->GetDocumentURI();
}
nsContentUtils::ReportToConsole(
nsContentUtils::eLAYOUT_PROPERTIES,
aMessageName,
nsnull, /* params */
0, /* params length */
documentURI,
nsnull,
PromiseFlatString(NS_LITERAL_STRING("coords=\"") +
aCoordsSpec +
NS_LITERAL_STRING("\"")), /* source line */
0, /* line number */
0, /* column number */
aFlags,
"ImageMap");
"ImageMap", doc);
}
void Area::ParseCoords(const nsAString& aSpec)

View File

@ -406,10 +406,10 @@ nsSVGUtils::ReportToConsole(nsIDocument* doc,
return nsContentUtils::ReportToConsole(nsContentUtils::eSVG_PROPERTIES,
aWarning,
aParams, aParamsLength,
doc ? doc->GetDocumentURI() : nsnull,
nsnull,
EmptyString(), 0, 0,
nsIScriptError::warningFlag,
"SVG");
"SVG", doc);
}
float

View File

@ -1009,12 +1009,13 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES,
"SpeculationFailed",
nsnull, 0,
mExecutor->GetDocument()->GetDocumentURI(),
nsnull,
EmptyString(),
speculation->GetStartLineNumber(),
0,
nsIScriptError::warningFlag,
"DOM Events");
"DOM Events",
mExecutor->GetDocument());
nsHtml5UTF16Buffer* buffer = mFirstBuffer->next;
while (buffer) {