Changeset 197744 in webkit


Ignore:
Timestamp:
Mar 8, 2016 1:10:09 AM (8 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

[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:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r197738 r197744  
     12016-03-08  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Fetch API] Make FetchRequest and FetchResponse ActiveDOMObject
     4        https://bugs.webkit.org/show_bug.cgi?id=154729
     5
     6        Reviewed by Darin Adler.
     7
     8        Covered by existing tests.
     9
     10        Making FetchRequest and FetchResponse ActiveDOMObject.
     11        Both objects can always be suspended now.
     12        This might be updated when blob conversion is added or when fetching data to fill in FetchResponse.
     13
     14        * Modules/fetch/FetchRequest.cpp:
     15        (WebCore::FetchRequest::create):
     16        (WebCore::FetchRequest::clone):
     17        (WebCore::FetchRequest::activeDOMObjectName):
     18        (WebCore::FetchRequest::canSuspendForDocumentSuspension):
     19        * Modules/fetch/FetchRequest.h:
     20        (WebCore::FetchRequest::FetchRequest):
     21        * Modules/fetch/FetchRequest.idl:
     22        * Modules/fetch/FetchResponse.cpp:
     23        (WebCore::FetchResponse::error):
     24        (WebCore::FetchResponse::redirect):
     25        (WebCore::FetchResponse::FetchResponse):
     26        (WebCore::FetchResponse::clone):
     27        (WebCore::FetchResponse::activeDOMObjectName):
     28        (WebCore::FetchResponse::canSuspendForDocumentSuspension):
     29        * Modules/fetch/FetchResponse.h:
     30        (WebCore::FetchResponse::create):
     31        * Modules/fetch/FetchResponse.idl:
     32
    1332016-03-08  Nikos Andronikos  <nikos.andronikos-webkit@cisra.canon.com.au>
    234
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp

    r197347 r197744  
    267267    }
    268268
    269     return adoptRef(*new FetchRequest(WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
     269    return adoptRef(*new FetchRequest(context, WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
    270270}
    271271
     
    298298    }
    299299
    300     return adoptRef(*new FetchRequest(WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
     300    return adoptRef(*new FetchRequest(context, WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
    301301}
    302302
     
    436436}
    437437
    438 RefPtr<FetchRequest> FetchRequest::clone(ExceptionCode& ec)
     438RefPtr<FetchRequest> FetchRequest::clone(ScriptExecutionContext* context, ExceptionCode& ec)
    439439{
    440440    if (isDisturbed()) {
     
    444444
    445445    // FIXME: Validate body teeing.
    446     return adoptRef(*new FetchRequest(FetchBody(m_body), FetchHeaders::create(m_headers.get()), FetchRequest::InternalRequest(m_internalRequest)));
     446    return adoptRef(*new FetchRequest(*context, FetchBody(m_body), FetchHeaders::create(m_headers.get()), FetchRequest::InternalRequest(m_internalRequest)));
     447}
     448
     449const char* FetchRequest::activeDOMObjectName() const
     450{
     451    return "Request";
     452}
     453
     454bool FetchRequest::canSuspendForDocumentSuspension() const
     455{
     456    return true;
    447457}
    448458
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.h

    r195954 r197744  
    3232#if ENABLE(FETCH_API)
    3333
     34#include "ActiveDOMObject.h"
    3435#include "FetchBody.h"
    3536#include "FetchHeaders.h"
     
    4445typedef int ExceptionCode;
    4546
    46 class FetchRequest : public RefCounted<FetchRequest> {
     47class FetchRequest final : public RefCounted<FetchRequest>, public ActiveDOMObject {
    4748public:
    4849    static RefPtr<FetchRequest> create(ScriptExecutionContext&, FetchRequest*, const Dictionary&, ExceptionCode&);
     
    6465    const String& integrity() const { return m_internalRequest.integrity; }
    6566
    66     RefPtr<FetchRequest> clone(ExceptionCode&);
     67    RefPtr<FetchRequest> clone(ScriptExecutionContext*, ExceptionCode&);
    6768
    6869    // Body API
     
    8485
    8586private:
    86     FetchRequest(FetchBody&&, Ref<FetchHeaders>&&, InternalRequest&&);
     87    FetchRequest(ScriptExecutionContext&, FetchBody&&, Ref<FetchHeaders>&&, InternalRequest&&);
     88
     89    // ActiveDOMObject API.
     90    const char* activeDOMObjectName() const final;
     91    bool canSuspendForDocumentSuspension() const final;
    8792
    8893    FetchBody m_body;
     
    9196};
    9297
    93 inline FetchRequest::FetchRequest(FetchBody&& body, Ref<FetchHeaders>&& headers, InternalRequest&& internalRequest)
    94     : m_body(WTFMove(body))
     98inline FetchRequest::FetchRequest(ScriptExecutionContext& context, FetchBody&& body, Ref<FetchHeaders>&& headers, InternalRequest&& internalRequest)
     99    : ActiveDOMObject(&context)
     100    , m_body(WTFMove(body))
    95101    , m_headers(WTFMove(headers))
    96102    , m_internalRequest(WTFMove(internalRequest))
    97103{
     104    suspendIfNeeded();
    98105}
    99106
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.idl

    r195954 r197744  
    3636
    3737[
     38    ActiveDOMObject,
    3839    Conditional=FETCH_API,
    3940    ConstructorCallWith=ScriptExecutionContext,
     
    4243    Constructor(DOMString input, [Default=Undefined]  optional Dictionary init),
    4344    GlobalContext=DOMWindow&WorkerGlobalScope,
    44     ImplementationLacksVTable,
    4545    InterfaceName=Request
    4646]
     
    6060    readonly attribute DOMString integrity;
    6161
    62     [RaisesException, NewObject] FetchRequest clone();
     62    [NewObject, CallWith=ScriptExecutionContext, RaisesException] FetchRequest clone();
    6363};
    6464FetchRequest implements FetchBody;
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r197347 r197744  
    4949}
    5050
    51 Ref<FetchResponse> FetchResponse::error()
     51Ref<FetchResponse> FetchResponse::error(ScriptExecutionContext* context)
    5252{
    53     return adoptRef(*new FetchResponse(Type::Error, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
     53    return adoptRef(*new FetchResponse(*context, Type::Error, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
    5454}
    5555
     
    6666        return nullptr;
    6767    }
    68     RefPtr<FetchResponse> redirectResponse = adoptRef(*new FetchResponse(Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
     68    RefPtr<FetchResponse> redirectResponse = adoptRef(*new FetchResponse(*context, Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
    6969    redirectResponse->m_response.setHTTPStatusCode(status);
    7070    redirectResponse->m_headers->fastSet(HTTPHeaderName::Location, requestURL.string());
     
    109109}
    110110
    111 FetchResponse::FetchResponse(Type type, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
    112     : m_type(type)
     111FetchResponse::FetchResponse(ScriptExecutionContext& context, Type type, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
     112    : ActiveDOMObject(&context)
     113    , m_type(type)
    113114    , m_response(WTFMove(response))
    114115    , m_body(WTFMove(body))
    115116    , m_headers(WTFMove(headers))
    116117{
     118    suspendIfNeeded();
    117119}
    118120
    119 RefPtr<FetchResponse> FetchResponse::clone(ExceptionCode& ec)
     121RefPtr<FetchResponse> FetchResponse::clone(ScriptExecutionContext* context, ExceptionCode& ec)
    120122{
    121123    if (m_body.isDisturbed() || m_isLocked) {
     
    123125        return nullptr;
    124126    }
    125     RefPtr<FetchResponse> cloned = adoptRef(*new FetchResponse(m_type, FetchBody(m_body), FetchHeaders::create(headers()), ResourceResponse(m_response)));
     127    RefPtr<FetchResponse> cloned = adoptRef(*new FetchResponse(*context, m_type, FetchBody(m_body), FetchHeaders::create(headers()), ResourceResponse(m_response)));
    126128    cloned->m_isRedirected = m_isRedirected;
    127129    return cloned;
     
    154156}
    155157
     158const char* FetchResponse::activeDOMObjectName() const
     159{
     160    return "Response";
     161}
     162
     163bool FetchResponse::canSuspendForDocumentSuspension() const
     164{
     165    return true;
     166}
     167
    156168} // namespace WebCore
    157169
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.h

    r197347 r197744  
    3232#if ENABLE(FETCH_API)
    3333
     34#include "ActiveDOMObject.h"
    3435#include "FetchBody.h"
    3536#include "FetchHeaders.h"
     
    4647typedef int ExceptionCode;
    4748
    48 class FetchResponse : public RefCounted<FetchResponse> {
     49class FetchResponse final : public RefCounted<FetchResponse>, public ActiveDOMObject {
    4950public:
    50     static Ref<FetchResponse> create() { return adoptRef(*new FetchResponse(Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
    51     static Ref<FetchResponse> error();
     51    static Ref<FetchResponse> create(ScriptExecutionContext& context) { return adoptRef(*new FetchResponse(context, Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
     52    static Ref<FetchResponse> error(ScriptExecutionContext*);
    5253    static RefPtr<FetchResponse> redirect(ScriptExecutionContext*, const String&, int, ExceptionCode&);
    5354    // FIXME: Binding generator should not require below method to handle optional status parameter.
     
    6465
    6566    FetchHeaders& headers() { return m_headers; }
    66     RefPtr<FetchResponse> clone(ExceptionCode&);
     67    RefPtr<FetchResponse> clone(ScriptExecutionContext*, ExceptionCode&);
    6768
    6869    // Body API
     
    7778    enum class Type { Basic, Cors, Default, Error, Opaque, OpaqueRedirect };
    7879
    79     FetchResponse(Type, FetchBody&&, Ref<FetchHeaders>&&, ResourceResponse&&);
     80    FetchResponse(ScriptExecutionContext&, Type, FetchBody&&, Ref<FetchHeaders>&&, ResourceResponse&&);
     81
     82    // ActiveDOMObject API
     83    const char* activeDOMObjectName() const final;
     84    bool canSuspendForDocumentSuspension() const final;
    8085
    8186    Type m_type;
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.idl

    r197049 r197744  
    2929
    3030[
     31    ActiveDOMObject,
    3132    Conditional=FETCH_API,
     33    ConstructorCallWith=ScriptExecutionContext,
    3234    GlobalContext=DOMWindow&WorkerGlobalScope,
    33     ImplementationLacksVTable,
    3435    InterfaceName=Response,
    3536    JSBuiltinConstructor
     
    3738interface FetchResponse {
    3839    // FIXME: NewObject does not seem to be supported for static methods.
    39     static FetchResponse error();
    40     [RaisesException, CallWith=ScriptExecutionContext] static FetchResponse redirect(DOMString url, optional unsigned short status = 302);
     40    [CallWith=ScriptExecutionContext] static FetchResponse error();
     41    [CallWith=ScriptExecutionContext, RaisesException] static FetchResponse redirect(DOMString url, optional unsigned short status = 302);
    4142
    4243    readonly attribute ResponseType type;
     
    5152    [Custom, RaisesException] readonly attribute ReadableStream? body;
    5253
    53     [NewObject, RaisesException] FetchResponse clone();
     54    [NewObject, CallWith=ScriptExecutionContext, RaisesException] FetchResponse clone();
    5455
    5556    [Private, RaisesException] void initializeWith(Dictionary parameters);
Note: See TracChangeset for help on using the changeset viewer.