Bug 1297300 - Add missing checks to GetSpec() calls in layout/. r=dholbert,heycam.

--HG--
extra : rebase_source : b3a26866746cde4337f5ffeff94f370b2eb7da3e
This commit is contained in:
Nicholas Nethercote 2016-08-31 20:10:10 +10:00
parent 9554ec97fa
commit f4ec41d9b5
16 changed files with 64 additions and 40 deletions

View File

@ -2019,10 +2019,14 @@ nsImageFrame::HandleEvent(nsPresContext* aPresContext,
// mouse is over the border. // mouse is over the border.
if (p.x < 0) p.x = 0; if (p.x < 0) p.x = 0;
if (p.y < 0) p.y = 0; if (p.y < 0) p.y = 0;
nsAutoCString spec; nsAutoCString spec;
uri->GetSpec(spec); nsresult rv = uri->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
spec += nsPrintfCString("?%d,%d", p.x, p.y); spec += nsPrintfCString("?%d,%d", p.x, p.y);
uri->SetSpec(spec); rv = uri->SetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
bool clicked = false; bool clicked = false;
if (aEvent->mMessage == eMouseClick && !aEvent->DefaultPrevented()) { if (aEvent->mMessage == eMouseClick && !aEvent->DefaultPrevented()) {

View File

@ -361,7 +361,8 @@ inCSSValueSearch::SearchStyleValue(const nsAFlatString& aValue, nsIURI* aBaseURL
nsresult rv = NS_NewURI(getter_AddRefs(uri), url, nullptr, aBaseURL); nsresult rv = NS_NewURI(getter_AddRefs(uri), url, nullptr, aBaseURL);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString spec; nsAutoCString spec;
uri->GetSpec(spec); rv = uri->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString *result = new NS_ConvertUTF8toUTF16(spec); nsAutoString *result = new NS_ConvertUTF8toUTF16(spec);
if (mReturnRelativeURLs) if (mReturnRelativeURLs)
EqualizeURL(result); EqualizeURL(result);

View File

@ -121,7 +121,8 @@ nsFontFace::GetURI(nsAString & aURI)
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData"); NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
if (mFontEntry->mUserFontData->mURI) { if (mFontEntry->mUserFontData->mURI) {
nsAutoCString spec; nsAutoCString spec;
mFontEntry->mUserFontData->mURI->GetSpec(spec); nsresult rv = mFontEntry->mUserFontData->mURI->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
AppendUTF8toUTF16(spec, aURI); AppendUTF8toUTF16(spec, aURI);
} }
} }

View File

@ -1218,9 +1218,9 @@ nsPrintEngine::GetDocumentTitleAndURL(nsIDocument* aDoc,
if (!exposableURI) return; if (!exposableURI) return;
nsAutoCString urlCStr; nsAutoCString urlCStr;
exposableURI->GetSpec(urlCStr); nsresult rv = exposableURI->GetSpec(urlCStr);
if (NS_FAILED(rv)) return;
nsresult rv;
nsCOMPtr<nsITextToSubURI> textToSubURI = nsCOMPtr<nsITextToSubURI> textToSubURI =
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv); do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
if (NS_FAILED(rv)) return; if (NS_FAILED(rv)) return;

View File

@ -1760,7 +1760,8 @@ CSSStyleSheet::GetHref(nsAString& aHref)
{ {
if (mInner->mOriginalSheetURI) { if (mInner->mOriginalSheetURI) {
nsAutoCString str; nsAutoCString str;
mInner->mOriginalSheetURI->GetSpec(str); nsresult rv = mInner->mOriginalSheetURI->GetSpec(str);
NS_ENSURE_SUCCESS(rv, rv);
CopyUTF8toUTF16(str, aHref); CopyUTF8toUTF16(str, aHref);
} else { } else {
SetDOMStringToNull(aHref); SetDOMStringToNull(aHref);

View File

@ -35,7 +35,10 @@ public:
mURI = aURI; mURI = aURI;
nsAutoCString cSpec; nsAutoCString cSpec;
mURI->GetSpec(cSpec); nsresult rv = mURI->GetSpec(cSpec);
if (NS_FAILED(rv)) {
cSpec.AssignLiteral("[nsIURI::GetSpec failed]");
}
CopyUTF8toUTF16(cSpec, mSpec); CopyUTF8toUTF16(cSpec, mSpec);
} }
return mSpec; return mSpec;

View File

@ -1263,9 +1263,7 @@ FontFaceSet::LogMessage(gfxUserFontEntry* aUserFontEntry,
CSSStyleSheet* sheet = rule->GetStyleSheet(); CSSStyleSheet* sheet = rule->GetStyleSheet();
// if the style sheet is removed while the font is loading can be null // if the style sheet is removed while the font is loading can be null
if (sheet) { if (sheet) {
nsAutoCString spec; nsCString spec = sheet->GetSheetURI()->GetSpecOrDefault();
rv = sheet->GetSheetURI()->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
CopyUTF8toUTF16(spec, href); CopyUTF8toUTF16(spec, href);
} else { } else {
NS_WARNING("null parent stylesheet for @font-face rule"); NS_WARNING("null parent stylesheet for @font-face rule");

View File

@ -1775,10 +1775,10 @@ Loader::ParseSheet(const nsAString& aInput,
aLoadData->mSheet->Principal(), aLoadData->mSheet->Principal(),
aLoadData->mLineNumber); aLoadData->mLineNumber);
} else { } else {
aLoadData->mSheet->AsServo()->ParseSheet(aInput, sheetURI, baseURI, rv =
aLoadData->mSheet->Principal(), aLoadData->mSheet->AsServo()->ParseSheet(aInput, sheetURI, baseURI,
aLoadData->mLineNumber); aLoadData->mSheet->Principal(),
rv = NS_OK; aLoadData->mLineNumber);
} }
mParsingDatas.RemoveElementAt(mParsingDatas.Length() - 1); mParsingDatas.RemoveElementAt(mParsingDatas.Length() - 1);

View File

@ -68,7 +68,7 @@ ServoStyleSheet::AppendStyleSheet(StyleSheetHandle aSheet)
MOZ_CRASH("stylo: not implemented"); MOZ_CRASH("stylo: not implemented");
} }
void nsresult
ServoStyleSheet::ParseSheet(const nsAString& aInput, ServoStyleSheet::ParseSheet(const nsAString& aInput,
nsIURI* aSheetURI, nsIURI* aSheetURI,
nsIURI* aBaseURI, nsIURI* aBaseURI,
@ -83,7 +83,8 @@ ServoStyleSheet::ParseSheet(const nsAString& aInput,
new ThreadSafePrincipalHolder(aSheetPrincipal); new ThreadSafePrincipalHolder(aSheetPrincipal);
nsCString baseString; nsCString baseString;
aBaseURI->GetSpec(baseString); nsresult rv = aBaseURI->GetSpec(baseString);
NS_ENSURE_SUCCESS(rv, rv);
NS_ConvertUTF16toUTF8 input(aInput); NS_ConvertUTF16toUTF8 input(aInput);
mSheet = Servo_StyleSheet_FromUTF8Bytes( mSheet = Servo_StyleSheet_FromUTF8Bytes(
@ -91,6 +92,8 @@ ServoStyleSheet::ParseSheet(const nsAString& aInput,
mParsingMode, mParsingMode,
reinterpret_cast<const uint8_t*>(baseString.get()), baseString.Length(), reinterpret_cast<const uint8_t*>(baseString.get()), baseString.Length(),
base, referrer, principal).Consume(); base, referrer, principal).Consume();
return NS_OK;
} }
void void

View File

@ -40,11 +40,11 @@ public:
StyleSheetHandle GetParentSheet() const; StyleSheetHandle GetParentSheet() const;
void AppendStyleSheet(StyleSheetHandle aSheet); void AppendStyleSheet(StyleSheetHandle aSheet);
void ParseSheet(const nsAString& aInput, MOZ_MUST_USE nsresult ParseSheet(const nsAString& aInput,
nsIURI* aSheetURI, nsIURI* aSheetURI,
nsIURI* aBaseURI, nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal, nsIPrincipal* aSheetPrincipal,
uint32_t aLineNumber); uint32_t aLineNumber);
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;

View File

@ -1499,10 +1499,8 @@ StyleRule::List(FILE* out, int32_t aIndent) const
if (sheet) { if (sheet) {
nsIURI* uri = sheet->GetSheetURI(); nsIURI* uri = sheet->GetSheetURI();
if (uri) { if (uri) {
nsAutoCString uristr;
str.Append(" /* "); str.Append(" /* ");
uri->GetSpec(uristr); str.Append(uri->GetSpecOrDefault());
str.Append(uristr);
str.Append(':'); str.Append(':');
str.AppendInt(mLineNumber); str.AppendInt(mLineNumber);
str.Append(" */"); str.Append(" */");

View File

@ -975,8 +975,11 @@ DocumentRule::UseForPresentation(nsPresContext* aPresContext)
nsIDocument *doc = aPresContext->Document(); nsIDocument *doc = aPresContext->Document();
nsIURI *docURI = doc->GetDocumentURI(); nsIURI *docURI = doc->GetDocumentURI();
nsAutoCString docURISpec; nsAutoCString docURISpec;
if (docURI) if (docURI) {
docURI->GetSpec(docURISpec); // If GetSpec fails (due to OOM) just skip these URI-specific CSS rules.
nsresult rv = docURI->GetSpec(docURISpec);
NS_ENSURE_SUCCESS(rv, false);
}
for (URL *url = mURLs; url; url = url->next) { for (URL *url = mURLs; url; url = url->next) {
switch (url->func) { switch (url->func) {

View File

@ -547,7 +547,7 @@ AnnotateCrashReport(nsIURI* aURI)
nsAutoCString scheme; nsAutoCString scheme;
nsDependentCSubstring filename; nsDependentCSubstring filename;
if (aURI) { if (aURI) {
aURI->GetSpec(spec); spec = aURI->GetSpecOrDefault();
aURI->GetScheme(scheme); aURI->GetScheme(scheme);
int32_t i = spec.RFindChar('/'); int32_t i = spec.RFindChar('/');
if (i != -1) { if (i != -1) {
@ -603,9 +603,8 @@ AnnotateCrashReport(nsIURI* aURI)
if (!resolvedURI) { if (!resolvedURI) {
annotation.AppendLiteral("(ConvertChromeURL failed)\n"); annotation.AppendLiteral("(ConvertChromeURL failed)\n");
} else { } else {
nsAutoCString resolvedSpec; annotation.Append(
resolvedURI->GetSpec(resolvedSpec); NS_ConvertUTF8toUTF16(resolvedURI->GetSpecOrDefault()));
annotation.Append(NS_ConvertUTF8toUTF16(resolvedSpec));
annotation.Append('\n'); annotation.Append('\n');
} }
} }
@ -949,7 +948,10 @@ nsLayoutStylesheetCache::BuildPreferenceSheet(StyleSheetHandle::RefPtr* aSheet,
if (sheet->IsGecko()) { if (sheet->IsGecko()) {
sheet->AsGecko()->ReparseSheet(sheetText); sheet->AsGecko()->ReparseSheet(sheetText);
} else { } else {
sheet->AsServo()->ParseSheet(sheetText, uri, uri, nullptr, 0); nsresult rv = sheet->AsServo()->ParseSheet(sheetText, uri, uri, nullptr, 0);
// Parsing the about:PreferenceStyleSheet URI can only fail on OOM. If we
// are OOM before we parsed any documents we might as well abort.
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
} }
#undef NS_GET_R_G_B #undef NS_GET_R_G_B

View File

@ -100,7 +100,8 @@ nsROCSSPrimitiveValue::GetCssText(nsAString& aCssText)
{ {
if (mValue.mURI) { if (mValue.mURI) {
nsAutoCString specUTF8; nsAutoCString specUTF8;
mValue.mURI->GetSpec(specUTF8); nsresult rv = mValue.mURI->GetSpec(specUTF8);
NS_ENSURE_SUCCESS(rv, rv);
tmpStr.AssignLiteral("url("); tmpStr.AssignLiteral("url(");
nsStyleUtil::AppendEscapedCSSString(NS_ConvertUTF8toUTF16(specUTF8), nsStyleUtil::AppendEscapedCSSString(NS_ConvertUTF8toUTF16(specUTF8),
@ -461,10 +462,13 @@ nsROCSSPrimitiveValue::GetStringValue(nsAString& aReturn)
break; break;
case CSS_URI: { case CSS_URI: {
nsAutoCString spec; nsAutoCString spec;
if (mValue.mURI) if (mValue.mURI) {
mValue.mURI->GetSpec(spec); nsresult rv = mValue.mURI->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
}
CopyUTF8toUTF16(spec, aReturn); CopyUTF8toUTF16(spec, aReturn);
} break; break;
}
default: default:
aReturn.Truncate(); aReturn.Truncate();
return NS_ERROR_DOM_INVALID_ACCESS_ERR; return NS_ERROR_DOM_INVALID_ACCESS_ERR;

View File

@ -185,7 +185,12 @@ FragmentOrURL::GetSourceString(nsString &aRef) const
mURL->GetRef(cref); mURL->GetRef(cref);
cref.Insert('#', 0); cref.Insert('#', 0);
} else { } else {
mURL->GetSpec(cref); // It's not entirely clear how to best handle failure here. Ensuring the
// string is empty seems safest.
nsresult rv = mURL->GetSpec(cref);
if (NS_FAILED(rv)) {
cref.Truncate();
}
} }
aRef = NS_ConvertUTF8toUTF16(cref); aRef = NS_ConvertUTF8toUTF16(cref);

View File

@ -2119,7 +2119,8 @@ nsTreeBodyFrame::GetImage(int32_t aRowIndex, nsTreeColumn* aCol, bool aUseContex
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
styleRequest->GetURI(getter_AddRefs(uri)); styleRequest->GetURI(getter_AddRefs(uri));
nsAutoCString spec; nsAutoCString spec;
uri->GetSpec(spec); nsresult rv = uri->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
CopyUTF8toUTF16(spec, imageSrc); CopyUTF8toUTF16(spec, imageSrc);
} }