Bug 1219852 P2 Report non-response values passed to FetchEvent.respondWith(). r=bz

This commit is contained in:
Ben Kelly 2015-10-31 10:34:20 -07:00
Родитель 6eedccec9c
Коммит cd7a409e01
2 изменённых файлов: 57 добавлений и 1 удалений

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

@ -186,3 +186,5 @@ BadOpaqueRedirectInterceptionWithURL=Failed to load '%S'. A ServiceWorker passed
InterceptionCanceledWithURL=Failed to load '%S'. A ServiceWorker canceled the load by calling FetchEvent.preventDefault().
# LOCALIZATION NOTE: Do not translate "ServiceWorker", "promise", or "FetchEvent.respondWith()". %1$S is a URL. %2$S is an error string.
InterceptionRejectedResponseWithURL=Failed to load '%1$S'. A ServiceWorker passed a promise to FetchEvent.respondWith() that rejected with '%2$S'.
# LOCALIZATION NOTE: Do not translate "ServiceWorker", "promise", "FetchEvent.respondWith()", or "Response". %1$S is a URL. %2$S is an error string.
InterceptedNonResponseWithURL=Failed to load '%1$S'. A ServiceWorker passed a promise to FetchEvent.respondWith() that resolved with non-Response value '%2$S'.

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

@ -283,6 +283,13 @@ public:
mRespondWithColumnNumber, aMessageName, aParams);
}
void AsyncLog(const nsACString& aSourceSpec, uint32_t aLine, uint32_t aColumn,
const nsACString& aMessageName, const nsTArray<nsString>& aParams)
{
::AsyncLog(mInterceptedChannel, aSourceSpec, aLine, aColumn, aMessageName,
aParams);
}
private:
~RespondWithHandler()
{
@ -421,12 +428,17 @@ ExtractErrorValues(JSContext* aCx, JS::Handle<JS::Value> aValue,
class MOZ_STACK_CLASS AutoCancel
{
RefPtr<RespondWithHandler> mOwner;
nsCString mSourceSpec;
uint32_t mLine;
uint32_t mColumn;
nsCString mMessageName;
nsTArray<nsString> mParams;
public:
AutoCancel(RespondWithHandler* aOwner, const nsString& aRequestURL)
: mOwner(aOwner)
, mLine(0)
, mColumn(0)
, mMessageName(NS_LITERAL_CSTRING("InterceptionFailedWithURL"))
{
mParams.AppendElement(aRequestURL);
@ -435,7 +447,11 @@ public:
~AutoCancel()
{
if (mOwner) {
mOwner->AsyncLog(mMessageName, mParams);
if (mSourceSpec.IsEmpty()) {
mOwner->AsyncLog(mMessageName, mParams);
} else {
mOwner->AsyncLog(mSourceSpec, mLine, mColumn, mMessageName, mParams);
}
mOwner->CancelRequest(NS_ERROR_INTERCEPTION_FAILED);
}
}
@ -451,6 +467,25 @@ public:
StringArrayAppender::Append(mParams, sizeof...(Params), aParams...);
}
template<typename... Params>
void SetCancelMessageAndLocation(const nsACString& aSourceSpec,
uint32_t aLine, uint32_t aColumn,
const nsACString& aMessageName,
Params... aParams)
{
MOZ_ASSERT(mOwner);
MOZ_ASSERT(mMessageName.EqualsLiteral("InterceptionFailedWithURL"));
MOZ_ASSERT(mParams.Length() == 1);
mSourceSpec = aSourceSpec;
mLine = aLine;
mColumn = aColumn;
mMessageName = aMessageName;
mParams.Clear();
StringArrayAppender::Append(mParams, sizeof...(Params), aParams...);
}
void Reset()
{
mOwner = nullptr;
@ -466,12 +501,31 @@ RespondWithHandler::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValu
if (!aValue.isObject()) {
NS_WARNING("FetchEvent::RespondWith was passed a promise resolved to a non-Object value");
nsCString sourceSpec;
uint32_t line = 0;
uint32_t column = 0;
nsString valueString;
ExtractErrorValues(aCx, aValue, sourceSpec, &line, &column, valueString);
autoCancel.SetCancelMessageAndLocation(sourceSpec, line, column,
NS_LITERAL_CSTRING("InterceptedNonResponseWithURL"),
&mRequestURL, &valueString);
return;
}
RefPtr<Response> response;
nsresult rv = UNWRAP_OBJECT(Response, &aValue.toObject(), response);
if (NS_FAILED(rv)) {
nsCString sourceSpec;
uint32_t line = 0;
uint32_t column = 0;
nsString valueString;
ExtractErrorValues(aCx, aValue, sourceSpec, &line, &column, valueString);
autoCancel.SetCancelMessageAndLocation(sourceSpec, line, column,
NS_LITERAL_CSTRING("InterceptedNonResponseWithURL"),
&mRequestURL, &valueString);
return;
}