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