Diff
Modified: trunk/Source/WebCore/ChangeLog (197743 => 197744)
--- trunk/Source/WebCore/ChangeLog 2016-03-08 09:08:11 UTC (rev 197743)
+++ trunk/Source/WebCore/ChangeLog 2016-03-08 09:10:09 UTC (rev 197744)
@@ -1,3 +1,35 @@
+2016-03-08 Youenn Fablet <[email protected]>
+
+ [Fetch API] Make FetchRequest and FetchResponse ActiveDOMObject
+ https://bugs.webkit.org/show_bug.cgi?id=154729
+
+ Reviewed by Darin Adler.
+
+ Covered by existing tests.
+
+ Making FetchRequest and FetchResponse ActiveDOMObject.
+ Both objects can always be suspended now.
+ This might be updated when blob conversion is added or when fetching data to fill in FetchResponse.
+
+ * Modules/fetch/FetchRequest.cpp:
+ (WebCore::FetchRequest::create):
+ (WebCore::FetchRequest::clone):
+ (WebCore::FetchRequest::activeDOMObjectName):
+ (WebCore::FetchRequest::canSuspendForDocumentSuspension):
+ * Modules/fetch/FetchRequest.h:
+ (WebCore::FetchRequest::FetchRequest):
+ * Modules/fetch/FetchRequest.idl:
+ * Modules/fetch/FetchResponse.cpp:
+ (WebCore::FetchResponse::error):
+ (WebCore::FetchResponse::redirect):
+ (WebCore::FetchResponse::FetchResponse):
+ (WebCore::FetchResponse::clone):
+ (WebCore::FetchResponse::activeDOMObjectName):
+ (WebCore::FetchResponse::canSuspendForDocumentSuspension):
+ * Modules/fetch/FetchResponse.h:
+ (WebCore::FetchResponse::create):
+ * Modules/fetch/FetchResponse.idl:
+
2016-03-08 Nikos Andronikos <[email protected]>
[SVG2] Implement marker orient='auto-start-reverse'
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (197743 => 197744)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp 2016-03-08 09:08:11 UTC (rev 197743)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp 2016-03-08 09:10:09 UTC (rev 197744)
@@ -266,7 +266,7 @@
return nullptr;
}
- return adoptRef(*new FetchRequest(WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
+ return adoptRef(*new FetchRequest(context, WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
}
RefPtr<FetchRequest> FetchRequest::create(ScriptExecutionContext& context, FetchRequest* input, const Dictionary& init, ExceptionCode& ec)
@@ -297,7 +297,7 @@
return nullptr;
}
- return adoptRef(*new FetchRequest(WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
+ return adoptRef(*new FetchRequest(context, WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
}
String FetchRequest::type() const
@@ -435,7 +435,7 @@
return String();
}
-RefPtr<FetchRequest> FetchRequest::clone(ExceptionCode& ec)
+RefPtr<FetchRequest> FetchRequest::clone(ScriptExecutionContext* context, ExceptionCode& ec)
{
if (isDisturbed()) {
ec = TypeError;
@@ -443,9 +443,19 @@
}
// FIXME: Validate body teeing.
- return adoptRef(*new FetchRequest(FetchBody(m_body), FetchHeaders::create(m_headers.get()), FetchRequest::InternalRequest(m_internalRequest)));
+ return adoptRef(*new FetchRequest(*context, FetchBody(m_body), FetchHeaders::create(m_headers.get()), FetchRequest::InternalRequest(m_internalRequest)));
}
+const char* FetchRequest::activeDOMObjectName() const
+{
+ return "Request";
+}
+
+bool FetchRequest::canSuspendForDocumentSuspension() const
+{
+ return true;
+}
+
} // namespace WebCore
#endif // ENABLE(FETCH_API)
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.h (197743 => 197744)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.h 2016-03-08 09:08:11 UTC (rev 197743)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.h 2016-03-08 09:10:09 UTC (rev 197744)
@@ -31,6 +31,7 @@
#if ENABLE(FETCH_API)
+#include "ActiveDOMObject.h"
#include "FetchBody.h"
#include "FetchHeaders.h"
#include "FetchOptions.h"
@@ -43,7 +44,7 @@
typedef int ExceptionCode;
-class FetchRequest : public RefCounted<FetchRequest> {
+class FetchRequest final : public RefCounted<FetchRequest>, public ActiveDOMObject {
public:
static RefPtr<FetchRequest> create(ScriptExecutionContext&, FetchRequest*, const Dictionary&, ExceptionCode&);
static RefPtr<FetchRequest> create(ScriptExecutionContext&, const String&, const Dictionary&, ExceptionCode&);
@@ -63,7 +64,7 @@
String redirect() const;
const String& integrity() const { return m_internalRequest.integrity; }
- RefPtr<FetchRequest> clone(ExceptionCode&);
+ RefPtr<FetchRequest> clone(ScriptExecutionContext*, ExceptionCode&);
// Body API
bool isDisturbed() const { return m_body.isDisturbed(); }
@@ -83,18 +84,24 @@
FetchBody& body() { return m_body; }
private:
- FetchRequest(FetchBody&&, Ref<FetchHeaders>&&, InternalRequest&&);
+ FetchRequest(ScriptExecutionContext&, FetchBody&&, Ref<FetchHeaders>&&, InternalRequest&&);
+ // ActiveDOMObject API.
+ const char* activeDOMObjectName() const final;
+ bool canSuspendForDocumentSuspension() const final;
+
FetchBody m_body;
Ref<FetchHeaders> m_headers;
InternalRequest m_internalRequest;
};
-inline FetchRequest::FetchRequest(FetchBody&& body, Ref<FetchHeaders>&& headers, InternalRequest&& internalRequest)
- : m_body(WTFMove(body))
+inline FetchRequest::FetchRequest(ScriptExecutionContext& context, FetchBody&& body, Ref<FetchHeaders>&& headers, InternalRequest&& internalRequest)
+ : ActiveDOMObject(&context)
+ , m_body(WTFMove(body))
, m_headers(WTFMove(headers))
, m_internalRequest(WTFMove(internalRequest))
{
+ suspendIfNeeded();
}
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.idl (197743 => 197744)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.idl 2016-03-08 09:08:11 UTC (rev 197743)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.idl 2016-03-08 09:10:09 UTC (rev 197744)
@@ -35,13 +35,13 @@
enum ReferrerPolicy { "", "no-referrer", "no-referrer-when-downgrade", "origin-only", "origin-when-cross-origin", "unsafe-url" };
[
+ ActiveDOMObject,
Conditional=FETCH_API,
ConstructorCallWith=ScriptExecutionContext,
ConstructorRaisesException,
Constructor(FetchRequest input, [Default=Undefined] optional Dictionary init),
Constructor(DOMString input, [Default=Undefined] optional Dictionary init),
GlobalContext=DOMWindow&WorkerGlobalScope,
- ImplementationLacksVTable,
InterfaceName=Request
]
interface FetchRequest {
@@ -59,6 +59,6 @@
readonly attribute RequestRedirect redirect;
readonly attribute DOMString integrity;
- [RaisesException, NewObject] FetchRequest clone();
+ [NewObject, CallWith=ScriptExecutionContext, RaisesException] FetchRequest clone();
};
FetchRequest implements FetchBody;
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (197743 => 197744)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-03-08 09:08:11 UTC (rev 197743)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-03-08 09:10:09 UTC (rev 197744)
@@ -48,9 +48,9 @@
return status == 101 || status == 204 || status == 205 || status == 304;
}
-Ref<FetchResponse> FetchResponse::error()
+Ref<FetchResponse> FetchResponse::error(ScriptExecutionContext* context)
{
- return adoptRef(*new FetchResponse(Type::Error, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
+ return adoptRef(*new FetchResponse(*context, Type::Error, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
}
RefPtr<FetchResponse> FetchResponse::redirect(ScriptExecutionContext* context, const String& url, int status, ExceptionCode& ec)
@@ -65,7 +65,7 @@
ec = TypeError;
return nullptr;
}
- RefPtr<FetchResponse> redirectResponse = adoptRef(*new FetchResponse(Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
+ RefPtr<FetchResponse> redirectResponse = adoptRef(*new FetchResponse(*context, Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
redirectResponse->m_response.setHTTPStatusCode(status);
redirectResponse->m_headers->fastSet(HTTPHeaderName::Location, requestURL.string());
return redirectResponse;
@@ -108,21 +108,23 @@
}
}
-FetchResponse::FetchResponse(Type type, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
- : m_type(type)
+FetchResponse::FetchResponse(ScriptExecutionContext& context, Type type, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
+ : ActiveDOMObject(&context)
+ , m_type(type)
, m_response(WTFMove(response))
, m_body(WTFMove(body))
, m_headers(WTFMove(headers))
{
+ suspendIfNeeded();
}
-RefPtr<FetchResponse> FetchResponse::clone(ExceptionCode& ec)
+RefPtr<FetchResponse> FetchResponse::clone(ScriptExecutionContext* context, ExceptionCode& ec)
{
if (m_body.isDisturbed() || m_isLocked) {
ec = TypeError;
return nullptr;
}
- RefPtr<FetchResponse> cloned = adoptRef(*new FetchResponse(m_type, FetchBody(m_body), FetchHeaders::create(headers()), ResourceResponse(m_response)));
+ RefPtr<FetchResponse> cloned = adoptRef(*new FetchResponse(*context, m_type, FetchBody(m_body), FetchHeaders::create(headers()), ResourceResponse(m_response)));
cloned->m_isRedirected = m_isRedirected;
return cloned;
}
@@ -153,6 +155,16 @@
return JSC::jsNull();
}
+const char* FetchResponse::activeDOMObjectName() const
+{
+ return "Response";
+}
+
+bool FetchResponse::canSuspendForDocumentSuspension() const
+{
+ return true;
+}
+
} // namespace WebCore
#endif // ENABLE(FETCH_API)
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (197743 => 197744)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h 2016-03-08 09:08:11 UTC (rev 197743)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h 2016-03-08 09:10:09 UTC (rev 197744)
@@ -31,6 +31,7 @@
#if ENABLE(FETCH_API)
+#include "ActiveDOMObject.h"
#include "FetchBody.h"
#include "FetchHeaders.h"
#include "ResourceResponse.h"
@@ -45,10 +46,10 @@
typedef int ExceptionCode;
-class FetchResponse : public RefCounted<FetchResponse> {
+class FetchResponse final : public RefCounted<FetchResponse>, public ActiveDOMObject {
public:
- static Ref<FetchResponse> create() { return adoptRef(*new FetchResponse(Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
- static Ref<FetchResponse> error();
+ static Ref<FetchResponse> create(ScriptExecutionContext& context) { return adoptRef(*new FetchResponse(context, Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
+ static Ref<FetchResponse> error(ScriptExecutionContext*);
static RefPtr<FetchResponse> redirect(ScriptExecutionContext*, const String&, int, ExceptionCode&);
// FIXME: Binding generator should not require below method to handle optional status parameter.
static RefPtr<FetchResponse> redirect(ScriptExecutionContext* context, const String& url, ExceptionCode& ec) { return redirect(context, url, 302, ec); }
@@ -63,7 +64,7 @@
const String& statusText() const { return m_response.httpStatusText(); }
FetchHeaders& headers() { return m_headers; }
- RefPtr<FetchResponse> clone(ExceptionCode&);
+ RefPtr<FetchResponse> clone(ScriptExecutionContext*, ExceptionCode&);
// Body API
bool isDisturbed() const { return m_body.isDisturbed(); }
@@ -76,8 +77,12 @@
private:
enum class Type { Basic, Cors, Default, Error, Opaque, OpaqueRedirect };
- FetchResponse(Type, FetchBody&&, Ref<FetchHeaders>&&, ResourceResponse&&);
+ FetchResponse(ScriptExecutionContext&, Type, FetchBody&&, Ref<FetchHeaders>&&, ResourceResponse&&);
+ // ActiveDOMObject API
+ const char* activeDOMObjectName() const final;
+ bool canSuspendForDocumentSuspension() const final;
+
Type m_type;
ResourceResponse m_response;
FetchBody m_body;
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.idl (197743 => 197744)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2016-03-08 09:08:11 UTC (rev 197743)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2016-03-08 09:10:09 UTC (rev 197744)
@@ -28,16 +28,17 @@
enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredirect" };
[
+ ActiveDOMObject,
Conditional=FETCH_API,
+ ConstructorCallWith=ScriptExecutionContext,
GlobalContext=DOMWindow&WorkerGlobalScope,
- ImplementationLacksVTable,
InterfaceName=Response,
JSBuiltinConstructor
]
interface FetchResponse {
// FIXME: NewObject does not seem to be supported for static methods.
- static FetchResponse error();
- [RaisesException, CallWith=ScriptExecutionContext] static FetchResponse redirect(DOMString url, optional unsigned short status = 302);
+ [CallWith=ScriptExecutionContext] static FetchResponse error();
+ [CallWith=ScriptExecutionContext, RaisesException] static FetchResponse redirect(DOMString url, optional unsigned short status = 302);
readonly attribute ResponseType type;
@@ -50,7 +51,7 @@
readonly attribute FetchHeaders headers;
[Custom, RaisesException] readonly attribute ReadableStream? body;
- [NewObject, RaisesException] FetchResponse clone();
+ [NewObject, CallWith=ScriptExecutionContext, RaisesException] FetchResponse clone();
[Private, RaisesException] void initializeWith(Dictionary parameters);
};