Bug 1301249 - nsIDocument::GetDocumentURI() should be fallible, r=smaug

This commit is contained in:
Andrea Marchesini 2016-09-20 14:03:05 +02:00
Родитель 3d45a22bac
Коммит 72d886f7a3
6 изменённых файлов: 39 добавлений и 20 удалений

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

@ -7071,22 +7071,25 @@ NS_IMETHODIMP
nsDocument::GetDocumentURI(nsAString& aDocumentURI)
{
nsString temp;
nsIDocument::GetDocumentURI(temp);
nsresult rv = nsIDocument::GetDocumentURI(temp);
aDocumentURI = temp;
return NS_OK;
return rv;
}
void
nsresult
nsIDocument::GetDocumentURI(nsString& aDocumentURI) const
{
if (mDocumentURI) {
nsAutoCString uri;
// XXX: should handle GetSpec() failure properly. See bug 1301249.
Unused << mDocumentURI->GetSpec(uri);
nsresult rv = mDocumentURI->GetSpec(uri);
NS_ENSURE_SUCCESS(rv, rv);
CopyUTF8toUTF16(uri, aDocumentURI);
} else {
aDocumentURI.Truncate();
}
return NS_OK;
}
// Alias of above
@ -7096,7 +7099,7 @@ nsDocument::GetURL(nsAString& aURL)
return GetDocumentURI(aURL);
}
void
nsresult
nsIDocument::GetURL(nsString& aURL) const
{
return GetDocumentURI(aURL);
@ -7106,7 +7109,8 @@ void
nsIDocument::GetDocumentURIFromJS(nsString& aDocumentURI, ErrorResult& aRv) const
{
if (!mChromeXHRDocURI || !nsContentUtils::IsCallerChrome()) {
return GetDocumentURI(aDocumentURI);
aRv = GetDocumentURI(aDocumentURI);
return;
}
nsAutoCString uri;

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

@ -8509,7 +8509,9 @@ nsGlobalWindow::CloseOuter(bool aTrustedCaller)
// Don't allow scripts from content to close non-app or non-neterror
// windows that were not opened by script.
nsAutoString url;
mDoc->GetURL(url);
nsresult rv = mDoc->GetURL(url);
NS_ENSURE_SUCCESS_VOID(rv);
if (!mDocShell->GetIsApp() &&
!StringBeginsWith(url, NS_LITERAL_STRING("about:neterror")) &&
!mHadOriginalOpener && !aTrustedCaller) {
@ -10481,7 +10483,10 @@ nsGlobalWindow::GetSessionStorage(ErrorResult& aError)
if (!mSessionStorage) {
nsString documentURI;
if (mDoc) {
mDoc->GetDocumentURI(documentURI);
aError = mDoc->GetDocumentURI(documentURI);
if (NS_WARN_IF(aError.Failed())) {
return nullptr;
}
}
// If the document has the sandboxed origin flag set
@ -10561,7 +10566,10 @@ nsGlobalWindow::GetLocalStorage(ErrorResult& aError)
nsString documentURI;
if (mDoc) {
mDoc->GetDocumentURI(documentURI);
aError = mDoc->GetDocumentURI(documentURI);
if (NS_WARN_IF(aError.Failed())) {
return nullptr;
}
}
nsCOMPtr<nsIDOMStorage> storage;

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

@ -2466,8 +2466,8 @@ public:
mozilla::ErrorResult& rv);
virtual mozilla::dom::DOMImplementation*
GetImplementation(mozilla::ErrorResult& rv) = 0;
void GetURL(nsString& retval) const;
void GetDocumentURI(nsString& retval) const;
MOZ_MUST_USE nsresult GetURL(nsString& retval) const;
MOZ_MUST_USE nsresult GetDocumentURI(nsString& retval) const;
// Return the URI for the document.
// The returned value may differ if the document is loaded via XHR, and
// when accessed from chrome privileged script and

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

@ -29,7 +29,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(DOMEventTargetHelper)
char name[512];
nsAutoString uri;
if (tmp->mOwnerWindow && tmp->mOwnerWindow->GetExtantDoc()) {
tmp->mOwnerWindow->GetExtantDoc()->GetDocumentURI(uri);
Unused << tmp->mOwnerWindow->GetExtantDoc()->GetDocumentURI(uri);
}
nsXPCOMCycleCollectionParticipant* participant = nullptr;

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

@ -27,9 +27,12 @@ static nsCString
GetDocumentURI(nsIDocument* aDocument)
{
nsCString result;
nsString url;
aDocument->GetDocumentURI(url);
result.Append(NS_ConvertUTF16toUTF8(url).get());
nsAutoString url;
nsresult rv = aDocument->GetDocumentURI(url);
if (NS_SUCCEEDED(rv)) {
result.Append(NS_ConvertUTF16toUTF8(url).get());
}
return result;
}

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

@ -251,8 +251,10 @@ nsStyleContext::AssertStructsNotUsedElsewhere(
(mCachedInheritedData.mStyleStructs[eStyleStruct_##name_] == data)) { \
printf_stderr("style struct %p found on style context %p\n", data, this);\
nsString url; \
PresContext()->Document()->GetURL(url); \
printf_stderr(" in %s\n", NS_ConvertUTF16toUTF8(url).get()); \
nsresult rv = PresContext()->Document()->GetURL(url); \
if (NS_SUCCEEDED(rv)) { \
printf_stderr(" in %s\n", NS_ConvertUTF16toUTF8(url).get()); \
} \
MOZ_ASSERT(false, "destroying " #name_ " style struct still present " \
"in style context tree"); \
}
@ -276,8 +278,10 @@ nsStyleContext::AssertStructsNotUsedElsewhere(
printf_stderr("style struct %p found on style context %p\n", data, \
this); \
nsString url; \
PresContext()->Document()->GetURL(url); \
printf_stderr(" in %s\n", NS_ConvertUTF16toUTF8(url).get()); \
nsresult rv = PresContext()->Document()->GetURL(url); \
if (NS_SUCCEEDED(rv)) { \
printf_stderr(" in %s\n", NS_ConvertUTF16toUTF8(url).get()); \
} \
MOZ_ASSERT(false, "destroying " #name_ " style struct still present "\
"in style context tree"); \
}