OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef Body_h | 5 #ifndef Body_h |
6 #define Body_h | 6 #define Body_h |
7 | 7 |
8 #include "bindings/core/v8/ActiveScriptWrappable.h" | 8 #include "bindings/core/v8/ActiveScriptWrappable.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
11 #include "bindings/core/v8/ScriptWrappable.h" | 11 #include "bindings/core/v8/ScriptWrappable.h" |
12 #include "core/dom/ActiveDOMObject.h" | 12 #include "core/dom/ContextLifecycleObserver.h" |
13 #include "modules/ModulesExport.h" | 13 #include "modules/ModulesExport.h" |
14 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
15 #include "wtf/text/WTFString.h" | 15 #include "wtf/text/WTFString.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 class BodyStreamBuffer; | 19 class BodyStreamBuffer; |
20 class ExecutionContext; | 20 class ExecutionContext; |
21 class ReadableByteStream; | 21 class ReadableByteStream; |
22 class ScriptState; | 22 class ScriptState; |
23 | 23 |
24 // This class represents Body mix-in defined in the fetch spec | 24 // This class represents Body mix-in defined in the fetch spec |
25 // https://fetch.spec.whatwg.org/#body-mixin. | 25 // https://fetch.spec.whatwg.org/#body-mixin. |
26 // | 26 // |
27 // Note: This class has body stream and its predicate whereas in the current | 27 // Note: This class has body stream and its predicate whereas in the current |
28 // spec only Response has it and Request has a byte stream defined in the | 28 // spec only Response has it and Request has a byte stream defined in the |
29 // Encoding spec. The spec should be fixed shortly to be aligned with this | 29 // Encoding spec. The spec should be fixed shortly to be aligned with this |
30 // implementation. | 30 // implementation. |
31 class MODULES_EXPORT Body | 31 class MODULES_EXPORT Body |
32 : public GarbageCollectedFinalized<Body> | 32 : public GarbageCollectedFinalized<Body> |
33 , public ScriptWrappable | 33 , public ScriptWrappable |
34 , public ActiveScriptWrappable | 34 , public ActiveScriptWrappable |
35 , public ActiveDOMObject { | 35 , public ContextLifecycleObserver { |
36 WTF_MAKE_NONCOPYABLE(Body); | 36 WTF_MAKE_NONCOPYABLE(Body); |
37 DEFINE_WRAPPERTYPEINFO(); | 37 DEFINE_WRAPPERTYPEINFO(); |
38 USING_GARBAGE_COLLECTED_MIXIN(Body); | 38 USING_GARBAGE_COLLECTED_MIXIN(Body); |
39 public: | 39 public: |
40 explicit Body(ExecutionContext*); | 40 explicit Body(ExecutionContext*); |
41 ~Body() override { } | 41 ~Body() override { } |
42 | 42 |
43 ScriptPromise arrayBuffer(ScriptState*); | 43 ScriptPromise arrayBuffer(ScriptState*); |
44 ScriptPromise blob(ScriptState*); | 44 ScriptPromise blob(ScriptState*); |
45 ScriptPromise formData(ScriptState*); | 45 ScriptPromise formData(ScriptState*); |
46 ScriptPromise json(ScriptState*); | 46 ScriptPromise json(ScriptState*); |
47 ScriptPromise text(ScriptState*); | 47 ScriptPromise text(ScriptState*); |
48 ReadableByteStream* bodyWithUseCounter(); | 48 ScriptValue bodyWithUseCounter(ScriptState*); |
49 virtual BodyStreamBuffer* bodyBuffer() = 0; | 49 virtual BodyStreamBuffer* bodyBuffer() = 0; |
50 virtual const BodyStreamBuffer* bodyBuffer() const = 0; | 50 virtual const BodyStreamBuffer* bodyBuffer() const = 0; |
51 ScriptValue v8ExtraStreamBody(ScriptState*); | |
52 | 51 |
53 virtual bool bodyUsed(); | 52 virtual bool bodyUsed(); |
54 bool isBodyLocked(); | 53 bool isBodyLocked(); |
55 | 54 |
56 // ActiveScriptWrappable override. | 55 // ActiveScriptWrappable override. |
57 bool hasPendingActivity() const override; | 56 bool hasPendingActivity() const override; |
58 | 57 |
59 DEFINE_INLINE_VIRTUAL_TRACE() | 58 DEFINE_INLINE_VIRTUAL_TRACE() |
60 { | 59 { |
61 ActiveDOMObject::trace(visitor); | 60 ContextLifecycleObserver::trace(visitor); |
62 } | 61 } |
63 | 62 |
64 private: | 63 private: |
65 ReadableByteStream* body(); | |
66 virtual String mimeType() const = 0; | 64 virtual String mimeType() const = 0; |
67 | 65 |
68 // Body consumption algorithms will reject with a TypeError in a number of | 66 // Body consumption algorithms will reject with a TypeError in a number of |
69 // error conditions. This method wraps those up into one call which returns | 67 // error conditions. This method wraps those up into one call which returns |
70 // an empty ScriptPromise if the consumption may proceed, and a | 68 // an empty ScriptPromise if the consumption may proceed, and a |
71 // ScriptPromise rejected with a TypeError if it ought to be blocked. | 69 // ScriptPromise rejected with a TypeError if it ought to be blocked. |
72 ScriptPromise rejectInvalidConsumption(ScriptState*); | 70 ScriptPromise rejectInvalidConsumption(ScriptState*); |
73 }; | 71 }; |
74 | 72 |
75 } // namespace blink | 73 } // namespace blink |
76 | 74 |
77 #endif // Body_h | 75 #endif // Body_h |
OLD | NEW |