2014-09-24 09:03:20 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_Fetch_h
|
|
|
|
#define mozilla_dom_Fetch_h
|
|
|
|
|
2014-10-01 22:43:26 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-10-06 22:01:20 +04:00
|
|
|
#include "mozilla/dom/RequestBinding.h"
|
2014-09-24 09:03:20 +04:00
|
|
|
|
|
|
|
class nsIInputStream;
|
2014-10-06 22:01:20 +04:00
|
|
|
class nsIGlobalObject;
|
2014-09-24 09:03:20 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-11-20 14:58:00 +03:00
|
|
|
class ArrayBufferOrArrayBufferViewOrBlobOrUSVStringOrURLSearchParams;
|
2014-10-06 22:01:20 +04:00
|
|
|
class InternalRequest;
|
2014-11-20 14:58:00 +03:00
|
|
|
class OwningArrayBufferOrArrayBufferViewOrBlobOrUSVStringOrURLSearchParams;
|
2014-09-27 03:41:15 +04:00
|
|
|
class Promise;
|
2014-11-20 14:58:00 +03:00
|
|
|
class RequestOrUSVString;
|
2014-10-06 22:01:20 +04:00
|
|
|
|
|
|
|
namespace workers {
|
|
|
|
class WorkerPrivate;
|
|
|
|
} // namespace workers
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-11-20 14:58:00 +03:00
|
|
|
FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
|
2014-10-06 22:01:20 +04:00
|
|
|
const RequestInit& aInit, ErrorResult& aRv);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetRequestReferrer(nsIGlobalObject* aGlobal, const InternalRequest* aRequest, nsCString& aReferrer);
|
2014-09-27 03:41:15 +04:00
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
/*
|
|
|
|
* Creates an nsIInputStream based on the fetch specifications 'extract a byte
|
|
|
|
* stream algorithm' - http://fetch.spec.whatwg.org/#concept-bodyinit-extract.
|
|
|
|
* Stores content type in out param aContentType.
|
|
|
|
*/
|
|
|
|
nsresult
|
2014-11-20 14:58:00 +03:00
|
|
|
ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrUSVStringOrURLSearchParams& aBodyInit,
|
2014-09-24 09:03:20 +04:00
|
|
|
nsIInputStream** aStream,
|
|
|
|
nsCString& aContentType);
|
|
|
|
|
2014-09-27 03:41:15 +04:00
|
|
|
/*
|
|
|
|
* Non-owning version.
|
|
|
|
*/
|
|
|
|
nsresult
|
2014-11-20 14:58:00 +03:00
|
|
|
ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrUSVStringOrURLSearchParams& aBodyInit,
|
2014-09-27 03:41:15 +04:00
|
|
|
nsIInputStream** aStream,
|
|
|
|
nsCString& aContentType);
|
|
|
|
|
|
|
|
template <class Derived>
|
|
|
|
class FetchBody {
|
|
|
|
public:
|
|
|
|
bool
|
|
|
|
BodyUsed() { return mBodyUsed; }
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
ArrayBuffer(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
return ConsumeBody(CONSUME_ARRAYBUFFER, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
Blob(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
return ConsumeBody(CONSUME_BLOB, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
Json(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
return ConsumeBody(CONSUME_JSON, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
Text(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
return ConsumeBody(CONSUME_TEXT, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
FetchBody()
|
|
|
|
: mBodyUsed(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetBodyUsed()
|
|
|
|
{
|
|
|
|
mBodyUsed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetMimeType(ErrorResult& aRv);
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum ConsumeType
|
|
|
|
{
|
|
|
|
CONSUME_ARRAYBUFFER,
|
|
|
|
CONSUME_BLOB,
|
|
|
|
// FormData not supported right now,
|
|
|
|
CONSUME_JSON,
|
|
|
|
CONSUME_TEXT,
|
|
|
|
};
|
|
|
|
|
|
|
|
Derived*
|
|
|
|
DerivedClass() const
|
|
|
|
{
|
|
|
|
return static_cast<Derived*>(const_cast<FetchBody*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
ConsumeBody(ConsumeType aType, ErrorResult& aRv);
|
|
|
|
|
|
|
|
bool mBodyUsed;
|
|
|
|
nsCString mMimeType;
|
|
|
|
};
|
2014-10-06 22:01:20 +04:00
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Fetch_h
|