2015-05-03 12:32:37 -07: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-24 17:50:32 -07: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 16:41:15 -07:00
|
|
|
#include "mozilla/dom/Fetch.h"
|
2014-07-24 17:50:32 -07:00
|
|
|
#include "mozilla/dom/ResponseBinding.h"
|
|
|
|
|
2015-04-29 08:59:43 -07:00
|
|
|
#include "InternalHeaders.h"
|
2014-09-26 16:41:15 -07:00
|
|
|
#include "InternalResponse.h"
|
|
|
|
|
2014-07-24 17:50:32 -07:00
|
|
|
namespace mozilla {
|
2015-06-04 21:39:34 -07:00
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace ipc
|
2015-06-04 21:39:34 -07:00
|
|
|
|
2014-07-24 17:50:32 -07:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Headers;
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class Response final : public nsISupports
|
2015-03-27 11:52:19 -07:00
|
|
|
, public FetchBody<Response>
|
|
|
|
, public nsWrapperCache
|
2014-07-24 17:50:32 -07:00
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Response)
|
|
|
|
|
|
|
|
public:
|
2014-09-26 16:41:15 -07:00
|
|
|
Response(nsIGlobalObject* aGlobal, InternalResponse* aInternalResponse);
|
|
|
|
|
2015-01-06 15:35:02 -08:00
|
|
|
Response(const Response& aOther) = delete;
|
2014-07-24 17:50:32 -07:00
|
|
|
|
|
|
|
JSObject*
|
2015-03-21 09:28:04 -07:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2014-07-24 17:50:32 -07: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 07:13:33 -07:00
|
|
|
return ResponseBinding::Wrap(aCx, this, aGivenProto);
|
2014-07-24 17:50:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ResponseType
|
|
|
|
Type() const
|
|
|
|
{
|
2014-09-26 16:41:15 -07:00
|
|
|
return mInternalResponse->Type();
|
2014-07-24 17:50:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetUrl(DOMString& aUrl) const
|
|
|
|
{
|
2014-10-06 11:01:20 -07:00
|
|
|
nsCString url;
|
|
|
|
mInternalResponse->GetUrl(url);
|
|
|
|
aUrl.AsAString() = NS_ConvertUTF8toUTF16(url);
|
2014-07-24 17:50:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
Status() const
|
|
|
|
{
|
2014-09-26 16:41:15 -07:00
|
|
|
return mInternalResponse->GetStatus();
|
2014-07-24 17:50:32 -07:00
|
|
|
}
|
|
|
|
|
2015-01-27 17:34:34 -08:00
|
|
|
bool
|
|
|
|
Ok() const
|
|
|
|
{
|
|
|
|
return mInternalResponse->GetStatus() >= 200 &&
|
|
|
|
mInternalResponse->GetStatus() <= 299;
|
|
|
|
}
|
|
|
|
|
2014-07-24 17:50:32 -07:00
|
|
|
void
|
|
|
|
GetStatusText(nsCString& aStatusText) const
|
|
|
|
{
|
2014-09-26 16:41:15 -07:00
|
|
|
aStatusText = mInternalResponse->GetStatusText();
|
2014-07-24 17:50:32 -07:00
|
|
|
}
|
|
|
|
|
2014-10-02 10:59:20 -07:00
|
|
|
InternalHeaders*
|
|
|
|
GetInternalHeaders() const
|
|
|
|
{
|
|
|
|
return mInternalResponse->Headers();
|
|
|
|
}
|
|
|
|
|
2015-05-25 11:21:05 -07:00
|
|
|
void
|
|
|
|
InitChannelInfo(nsIChannel* aChannel)
|
|
|
|
{
|
|
|
|
mInternalResponse->InitChannelInfo(aChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ChannelInfo&
|
|
|
|
GetChannelInfo() const
|
2015-04-23 15:50:04 -07:00
|
|
|
{
|
2015-05-25 11:21:05 -07:00
|
|
|
return mInternalResponse->GetChannelInfo();
|
2015-04-23 15:50:04 -07:00
|
|
|
}
|
|
|
|
|
2015-06-04 21:39:34 -07:00
|
|
|
const UniquePtr<mozilla::ipc::PrincipalInfo>&
|
|
|
|
GetPrincipalInfo() const
|
|
|
|
{
|
|
|
|
return mInternalResponse->GetPrincipalInfo();
|
|
|
|
}
|
|
|
|
|
2014-10-02 10:59:20 -07:00
|
|
|
Headers* Headers_();
|
2014-09-26 16:41:15 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
GetBody(nsIInputStream** aStream) { return mInternalResponse->GetBody(aStream); }
|
2014-07-24 17:50:32 -07:00
|
|
|
|
|
|
|
static already_AddRefed<Response>
|
|
|
|
Error(const GlobalObject& aGlobal);
|
|
|
|
|
|
|
|
static already_AddRefed<Response>
|
2014-12-26 09:44:09 -08:00
|
|
|
Redirect(const GlobalObject& aGlobal, const nsAString& aUrl, uint16_t aStatus, ErrorResult& aRv);
|
2014-07-24 17:50:32 -07:00
|
|
|
|
|
|
|
static already_AddRefed<Response>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2015-03-17 08:32:04 -07:00
|
|
|
const Optional<ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams>& aBody,
|
2014-07-24 17:50:32 -07:00
|
|
|
const ResponseInit& aInit, ErrorResult& rv);
|
|
|
|
|
2014-09-26 16:41:15 -07:00
|
|
|
nsIGlobalObject* GetParentObject() const
|
2014-07-24 17:50:32 -07:00
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Response>
|
2015-02-19 17:24:24 -08:00
|
|
|
Clone(ErrorResult& aRv) const;
|
2014-07-24 17:50:32 -07:00
|
|
|
|
2014-09-26 16:41:15 -07:00
|
|
|
void
|
|
|
|
SetBody(nsIInputStream* aBody);
|
2015-03-02 05:08:00 -08:00
|
|
|
|
|
|
|
already_AddRefed<InternalResponse>
|
|
|
|
GetInternalResponse() const;
|
|
|
|
|
2014-07-24 17:50:32 -07:00
|
|
|
private:
|
|
|
|
~Response();
|
|
|
|
|
2014-09-26 16:41:15 -07:00
|
|
|
nsCOMPtr<nsIGlobalObject> mOwner;
|
|
|
|
nsRefPtr<InternalResponse> mInternalResponse;
|
2014-10-02 10:59:20 -07:00
|
|
|
// Lazily created
|
|
|
|
nsRefPtr<Headers> mHeaders;
|
2014-07-24 17:50:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Response_h
|