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/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
10 #include "core/dom/ActiveDOMObject.h" | 10 #include "core/dom/ActiveDOMObject.h" |
11 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" |
12 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
13 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 class BodyStreamBuffer; | 17 class BodyStreamBuffer; |
18 class ExecutionContext; | 18 class ExecutionContext; |
19 class ReadableByteStream; | 19 class ReadableByteStream; |
20 class ScriptState; | 20 class ScriptState; |
21 | 21 |
| 22 // This class represents Body mix-in defined in the fetch spec |
| 23 // https://fetch.spec.whatwg.org/#body-mixin. |
| 24 // |
| 25 // Note: This class has body stream and its predicate whereas in the current |
| 26 // spec only Response has it and Request has a byte stream defined in the |
| 27 // Encoding spec. The spec should be fixed shortly to be aligned with this |
| 28 // implementation. |
22 class MODULES_EXPORT Body | 29 class MODULES_EXPORT Body |
23 : public GarbageCollectedFinalized<Body> | 30 : public GarbageCollectedFinalized<Body> |
24 , public ScriptWrappable | 31 , public ScriptWrappable |
25 , public ActiveDOMObject { | 32 , public ActiveDOMObject { |
26 WTF_MAKE_NONCOPYABLE(Body); | 33 WTF_MAKE_NONCOPYABLE(Body); |
27 DEFINE_WRAPPERTYPEINFO(); | 34 DEFINE_WRAPPERTYPEINFO(); |
28 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Body); | 35 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Body); |
29 public: | 36 public: |
30 explicit Body(ExecutionContext*); | 37 explicit Body(ExecutionContext*); |
31 ~Body() override { } | 38 ~Body() override { } |
32 | 39 |
33 ScriptPromise arrayBuffer(ScriptState*); | 40 ScriptPromise arrayBuffer(ScriptState*); |
34 ScriptPromise blob(ScriptState*); | 41 ScriptPromise blob(ScriptState*); |
35 ScriptPromise formData(ScriptState*); | 42 ScriptPromise formData(ScriptState*); |
36 ScriptPromise json(ScriptState*); | 43 ScriptPromise json(ScriptState*); |
37 ScriptPromise text(ScriptState*); | 44 ScriptPromise text(ScriptState*); |
38 ReadableByteStream* body(); | 45 ReadableByteStream* bodyWithUseCounter(); |
39 virtual BodyStreamBuffer* bodyBuffer() = 0; | 46 virtual BodyStreamBuffer* bodyBuffer() = 0; |
40 virtual const BodyStreamBuffer* bodyBuffer() const = 0; | 47 virtual const BodyStreamBuffer* bodyBuffer() const = 0; |
41 | 48 |
42 bool bodyUsed(); | 49 virtual bool bodyUsed(); |
43 void setBodyPassed() { m_bodyPassed = true; } | 50 bool isBodyLocked(); |
44 | 51 |
45 // ActiveDOMObject override. | 52 // ActiveDOMObject override. |
46 bool hasPendingActivity() const override; | 53 bool hasPendingActivity() const override; |
47 | 54 |
48 DEFINE_INLINE_VIRTUAL_TRACE() | 55 DEFINE_INLINE_VIRTUAL_TRACE() |
49 { | 56 { |
50 ActiveDOMObject::trace(visitor); | 57 ActiveDOMObject::trace(visitor); |
51 } | 58 } |
52 | 59 |
53 // https://w3c.github.io/webappsec-credential-management/#monkey-patching-fe
tch-2 | 60 // https://w3c.github.io/webappsec-credential-management/#monkey-patching-fe
tch-2 |
54 void setOpaque() { m_opaque = true; } | 61 void setOpaque() { m_opaque = true; } |
55 bool opaque() const { return m_opaque; } | 62 bool opaque() const { return m_opaque; } |
56 | 63 |
57 private: | 64 private: |
| 65 ReadableByteStream* body(); |
58 virtual String mimeType() const = 0; | 66 virtual String mimeType() const = 0; |
59 | 67 |
60 // Body consumption algorithms will reject with a TypeError in a number of e
rror | 68 // Body consumption algorithms will reject with a TypeError in a number of |
61 // conditions. This method wraps those up into one call which returns an emp
ty | 69 // error conditions. This method wraps those up into one call which returns |
62 // ScriptPromise if the consumption may proceed, and a ScriptPromise rejecte
d with | 70 // an empty ScriptPromise if the consumption may proceed, and a |
63 // a TypeError if it ought to be blocked. | 71 // ScriptPromise rejected with a TypeError if it ought to be blocked. |
64 ScriptPromise rejectInvalidConsumption(ScriptState*); | 72 ScriptPromise rejectInvalidConsumption(ScriptState*); |
65 | 73 |
66 bool m_bodyPassed; | |
67 bool m_opaque; | 74 bool m_opaque; |
68 }; | 75 }; |
69 | 76 |
70 } // namespace blink | 77 } // namespace blink |
71 | 78 |
72 #endif // Body_h | 79 #endif // Body_h |
OLD | NEW |