2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-07-25 00:50:32 +00:00
|
|
|
/* 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_Response_h
|
|
|
|
#define mozilla_dom_Response_h
|
|
|
|
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
|
2014-09-26 23:41:15 +00:00
|
|
|
#include "mozilla/dom/Fetch.h"
|
2014-07-25 00:50:32 +00:00
|
|
|
#include "mozilla/dom/ResponseBinding.h"
|
|
|
|
|
2015-04-29 15:59:43 +00:00
|
|
|
#include "InternalHeaders.h"
|
2014-09-26 23:41:15 +00:00
|
|
|
#include "InternalResponse.h"
|
|
|
|
|
2014-07-25 00:50:32 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Headers;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class Response final : public nsISupports
|
2015-03-27 18:52:19 +00:00
|
|
|
, public FetchBody<Response>
|
|
|
|
, public nsWrapperCache
|
2014-07-25 00:50:32 +00:00
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Response)
|
|
|
|
|
|
|
|
public:
|
2014-09-26 23:41:15 +00:00
|
|
|
Response(nsIGlobalObject* aGlobal, InternalResponse* aInternalResponse);
|
|
|
|
|
2015-01-06 23:35:02 +00:00
|
|
|
Response(const Response& aOther) = delete;
|
2014-07-25 00:50:32 +00:00
|
|
|
|
|
|
|
JSObject*
|
2015-03-21 16:28:04 +00:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2014-07-25 00:50:32 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return ResponseBinding::Wrap(aCx, this, aGivenProto);
|
2014-07-25 00:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResponseType
|
|
|
|
Type() const
|
|
|
|
{
|
2014-09-26 23:41:15 +00:00
|
|
|
return mInternalResponse->Type();
|
2014-07-25 00:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetUrl(DOMString& aUrl) const
|
|
|
|
{
|
2014-10-06 18:01:20 +00:00
|
|
|
nsCString url;
|
|
|
|
mInternalResponse->GetUrl(url);
|
|
|
|
aUrl.AsAString() = NS_ConvertUTF8toUTF16(url);
|
2014-07-25 00:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
Status() const
|
|
|
|
{
|
2014-09-26 23:41:15 +00:00
|
|
|
return mInternalResponse->GetStatus();
|
2014-07-25 00:50:32 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 01:34:34 +00:00
|
|
|
bool
|
|
|
|
Ok() const
|
|
|
|
{
|
|
|
|
return mInternalResponse->GetStatus() >= 200 &&
|
|
|
|
mInternalResponse->GetStatus() <= 299;
|
|
|
|
}
|
|
|
|
|
2014-07-25 00:50:32 +00:00
|
|
|
void
|
|
|
|
GetStatusText(nsCString& aStatusText) const
|
|
|
|
{
|
2014-09-26 23:41:15 +00:00
|
|
|
aStatusText = mInternalResponse->GetStatusText();
|
2014-07-25 00:50:32 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 17:59:20 +00:00
|
|
|
InternalHeaders*
|
|
|
|
GetInternalHeaders() const
|
|
|
|
{
|
|
|
|
return mInternalResponse->Headers();
|
|
|
|
}
|
|
|
|
|
2015-04-23 22:50:04 +00:00
|
|
|
const nsCString&
|
|
|
|
GetSecurityInfo() const
|
|
|
|
{
|
|
|
|
return mInternalResponse->GetSecurityInfo();
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:59:20 +00:00
|
|
|
Headers* Headers_();
|
2014-09-26 23:41:15 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
GetBody(nsIInputStream** aStream) { return mInternalResponse->GetBody(aStream); }
|
2014-07-25 00:50:32 +00:00
|
|
|
|
|
|
|
static already_AddRefed<Response>
|
|
|
|
Error(const GlobalObject& aGlobal);
|
|
|
|
|
|
|
|
static already_AddRefed<Response>
|
2014-12-26 17:44:09 +00:00
|
|
|
Redirect(const GlobalObject& aGlobal, const nsAString& aUrl, uint16_t aStatus, ErrorResult& aRv);
|
2014-07-25 00:50:32 +00:00
|
|
|
|
|
|
|
static already_AddRefed<Response>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2015-03-17 15:32:04 +00:00
|
|
|
const Optional<ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams>& aBody,
|
2014-07-25 00:50:32 +00:00
|
|
|
const ResponseInit& aInit, ErrorResult& rv);
|
|
|
|
|
2014-09-26 23:41:15 +00:00
|
|
|
nsIGlobalObject* GetParentObject() const
|
2014-07-25 00:50:32 +00:00
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Response>
|
2015-02-20 01:24:24 +00:00
|
|
|
Clone(ErrorResult& aRv) const;
|
2014-07-25 00:50:32 +00:00
|
|
|
|
2014-09-26 23:41:15 +00:00
|
|
|
void
|
|
|
|
SetBody(nsIInputStream* aBody);
|
2015-03-02 13:08:00 +00:00
|
|
|
|
|
|
|
already_AddRefed<InternalResponse>
|
|
|
|
GetInternalResponse() const;
|
|
|
|
|
2014-07-25 00:50:32 +00:00
|
|
|
private:
|
|
|
|
~Response();
|
|
|
|
|
2014-09-26 23:41:15 +00:00
|
|
|
nsCOMPtr<nsIGlobalObject> mOwner;
|
|
|
|
nsRefPtr<InternalResponse> mInternalResponse;
|
2014-10-02 17:59:20 +00:00
|
|
|
// Lazily created
|
|
|
|
nsRefPtr<Headers> mHeaders;
|
2014-07-25 00:50:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Response_h
|