mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1017613 - Part 2 - Response IDL and stubs. r=baku
--HG-- extra : rebase_source : f2f55775ed2e9fc92af829d3ce6f7ca3553b97db
This commit is contained in:
parent
6e9ecfbbaa
commit
75d95732ee
@ -887,6 +887,10 @@ DOMInterfaces = {
|
||||
'binaryNames': { 'headers': 'headers_' },
|
||||
},
|
||||
|
||||
'Response': {
|
||||
'binaryNames': { 'headers': 'headers_' },
|
||||
},
|
||||
|
||||
'RGBColor': {
|
||||
'nativeType': 'nsDOMCSSRGBColor',
|
||||
},
|
||||
|
134
dom/fetch/Response.cpp
Normal file
134
dom/fetch/Response.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
#include "Response.h"
|
||||
#include "nsDOMString.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
|
||||
#include "mozilla/ErrorResult.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(Response)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(Response)
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Response, mOwner)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Response)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
Response::Response(nsISupports* aOwner)
|
||||
: mOwner(aOwner)
|
||||
, mHeaders(new Headers(aOwner))
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
Response::~Response()
|
||||
{
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<Response>
|
||||
Response::Error(const GlobalObject& aGlobal)
|
||||
{
|
||||
ErrorResult result;
|
||||
ResponseInit init;
|
||||
init.mStatus = 0;
|
||||
Optional<ArrayBufferOrArrayBufferViewOrScalarValueStringOrURLSearchParams> body;
|
||||
nsRefPtr<Response> r = Response::Constructor(aGlobal, body, init, result);
|
||||
return r.forget();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<Response>
|
||||
Response::Redirect(const GlobalObject& aGlobal, const nsAString& aUrl,
|
||||
uint16_t aStatus)
|
||||
{
|
||||
ErrorResult result;
|
||||
ResponseInit init;
|
||||
Optional<ArrayBufferOrArrayBufferViewOrScalarValueStringOrURLSearchParams> body;
|
||||
nsRefPtr<Response> r = Response::Constructor(aGlobal, body, init, result);
|
||||
return r.forget();
|
||||
}
|
||||
|
||||
/*static*/ already_AddRefed<Response>
|
||||
Response::Constructor(const GlobalObject& global,
|
||||
const Optional<ArrayBufferOrArrayBufferViewOrScalarValueStringOrURLSearchParams>& aBody,
|
||||
const ResponseInit& aInit, ErrorResult& rv)
|
||||
{
|
||||
nsRefPtr<Response> response = new Response(global.GetAsSupports());
|
||||
return response.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Response>
|
||||
Response::Clone()
|
||||
{
|
||||
nsRefPtr<Response> response = new Response(mOwner);
|
||||
return response.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Response::ArrayBuffer(ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
|
||||
MOZ_ASSERT(global);
|
||||
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Response::Blob(ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
|
||||
MOZ_ASSERT(global);
|
||||
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Response::Json(ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
|
||||
MOZ_ASSERT(global);
|
||||
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Response::Text(ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
|
||||
MOZ_ASSERT(global);
|
||||
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
promise->MaybeReject(NS_ERROR_NOT_AVAILABLE);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
Response::BodyUsed()
|
||||
{
|
||||
return false;
|
||||
}
|
107
dom/fetch/Response.h
Normal file
107
dom/fetch/Response.h
Normal file
@ -0,0 +1,107 @@
|
||||
/* -*- 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_Response_h
|
||||
#define mozilla_dom_Response_h
|
||||
|
||||
#include "nsWrapperCache.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
|
||||
#include "mozilla/dom/ResponseBinding.h"
|
||||
#include "mozilla/dom/UnionTypes.h"
|
||||
|
||||
class nsPIDOMWindow;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class Headers;
|
||||
|
||||
class Response MOZ_FINAL : public nsISupports
|
||||
, public nsWrapperCache
|
||||
{
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Response)
|
||||
|
||||
public:
|
||||
Response(nsISupports* aOwner);
|
||||
|
||||
JSObject*
|
||||
WrapObject(JSContext* aCx)
|
||||
{
|
||||
return ResponseBinding::Wrap(aCx, this);
|
||||
}
|
||||
|
||||
ResponseType
|
||||
Type() const
|
||||
{
|
||||
return ResponseType::Error;
|
||||
}
|
||||
|
||||
void
|
||||
GetUrl(DOMString& aUrl) const
|
||||
{
|
||||
aUrl.AsAString() = EmptyString();
|
||||
}
|
||||
|
||||
uint16_t
|
||||
Status() const
|
||||
{
|
||||
return 400;
|
||||
}
|
||||
|
||||
void
|
||||
GetStatusText(nsCString& aStatusText) const
|
||||
{
|
||||
aStatusText = EmptyCString();
|
||||
}
|
||||
|
||||
Headers*
|
||||
Headers_() const { return mHeaders; }
|
||||
|
||||
static already_AddRefed<Response>
|
||||
Error(const GlobalObject& aGlobal);
|
||||
|
||||
static already_AddRefed<Response>
|
||||
Redirect(const GlobalObject& aGlobal, const nsAString& aUrl, uint16_t aStatus);
|
||||
|
||||
static already_AddRefed<Response>
|
||||
Constructor(const GlobalObject& aGlobal,
|
||||
const Optional<ArrayBufferOrArrayBufferViewOrScalarValueStringOrURLSearchParams>& aBody,
|
||||
const ResponseInit& aInit, ErrorResult& rv);
|
||||
|
||||
nsISupports* GetParentObject() const
|
||||
{
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
already_AddRefed<Response>
|
||||
Clone();
|
||||
|
||||
already_AddRefed<Promise>
|
||||
ArrayBuffer(ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Blob(ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Json(ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Text(ErrorResult& aRv);
|
||||
|
||||
bool
|
||||
BodyUsed();
|
||||
private:
|
||||
~Response();
|
||||
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
nsRefPtr<Headers> mHeaders;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_Response_h
|
@ -7,11 +7,13 @@
|
||||
EXPORTS.mozilla.dom += [
|
||||
'Headers.h',
|
||||
'Request.h',
|
||||
'Response.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'Headers.cpp',
|
||||
'Request.cpp',
|
||||
'Response.cpp',
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
|
@ -864,6 +864,8 @@ var interfaceNamesInGlobalScope =
|
||||
"Rect",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "Request", pref: "dom.fetch.enabled"},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "Response", pref: "dom.fetch.enabled"},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"RGBColor",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
36
dom/webidl/Response.webidl
Normal file
36
dom/webidl/Response.webidl
Normal file
@ -0,0 +1,36 @@
|
||||
/* -*- Mode: IDL; 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/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* https://fetch.spec.whatwg.org/#response-class
|
||||
*/
|
||||
|
||||
[Constructor(optional BodyInit body, optional ResponseInit init),
|
||||
Exposed=(Window,Worker),
|
||||
Func="mozilla::dom::Headers::PrefEnabled"]
|
||||
interface Response {
|
||||
static Response error();
|
||||
static Response redirect(ScalarValueString url, optional unsigned short status = 302);
|
||||
|
||||
readonly attribute ResponseType type;
|
||||
|
||||
readonly attribute ScalarValueString url;
|
||||
readonly attribute unsigned short status;
|
||||
readonly attribute ByteString statusText;
|
||||
readonly attribute Headers headers;
|
||||
|
||||
Response clone();
|
||||
};
|
||||
|
||||
Response implements Body;
|
||||
|
||||
dictionary ResponseInit {
|
||||
unsigned short status = 200;
|
||||
// WebIDL spec doesn't allow default values for ByteString.
|
||||
ByteString statusText;
|
||||
HeadersInit headers;
|
||||
};
|
||||
|
||||
enum ResponseType { "basic", "cors", "default", "error", "opaque" };
|
@ -330,6 +330,7 @@ WEBIDL_FILES = [
|
||||
'Request.webidl',
|
||||
'ResourceStats.webidl',
|
||||
'ResourceStatsManager.webidl',
|
||||
'Response.webidl',
|
||||
'RGBColor.webidl',
|
||||
'RTCConfiguration.webidl',
|
||||
'RTCIceCandidate.webidl',
|
||||
|
@ -6,5 +6,6 @@ function ok(a, msg) {
|
||||
onmessage = function() {
|
||||
ok(typeof Headers === "function", "Headers should be defined");
|
||||
ok(typeof Request === "function", "Request should be defined");
|
||||
ok(typeof Response === "function", "Response should be defined");
|
||||
postMessage({ type: 'finish' });
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user