| 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 ReadableStream_h | 5 #ifndef ReadableStream_h |
| 6 #define ReadableStream_h | 6 #define ReadableStream_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseProperty.h" | 9 #include "bindings/core/v8/ScriptPromiseProperty.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| 11 #include "bindings/core/v8/ScriptValue.h" | 11 #include "bindings/core/v8/ScriptValue.h" |
| 12 #include "bindings/core/v8/ScriptWrappable.h" | 12 #include "bindings/core/v8/ScriptWrappable.h" |
| 13 #include "bindings/core/v8/V8Binding.h" | 13 #include "bindings/core/v8/V8Binding.h" |
| 14 #include "core/dom/ActiveDOMObject.h" | 14 #include "core/dom/ActiveDOMObject.h" |
| 15 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
| 16 #include "wtf/Forward.h" | 16 #include "wtf/Forward.h" |
| 17 #include "wtf/PassRefPtr.h" | 17 #include "wtf/PassRefPtr.h" |
| 18 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 class DOMException; | 22 class DOMException; |
| 23 class ExceptionState; | 23 class ExceptionState; |
| 24 class ExclusiveStreamReader; | |
| 25 class UnderlyingSource; | 24 class UnderlyingSource; |
| 26 | 25 |
| 27 class ReadableStream : public GarbageCollectedFinalized<ReadableStream>, public
ScriptWrappable, public ActiveDOMObject { | 26 class ReadableStream : public GarbageCollectedFinalized<ReadableStream>, public
ScriptWrappable, public ActiveDOMObject { |
| 28 DEFINE_WRAPPERTYPEINFO(); | 27 DEFINE_WRAPPERTYPEINFO(); |
| 29 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ReadableStream); | 28 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ReadableStream); |
| 30 public: | 29 public: |
| 31 enum State { | 30 enum State { |
| 32 Readable, | 31 Readable, |
| 33 Waiting, | 32 Waiting, |
| 34 Closed, | 33 Closed, |
| 35 Errored, | 34 Errored, |
| 36 }; | 35 }; |
| 37 | 36 |
| 38 // After ReadableStream construction, |didSourceStart| must be called when | 37 // After ReadableStream construction, |didSourceStart| must be called when |
| 39 // |source| initialization succeeds and |error| must be called when | 38 // |source| initialization succeeds and |error| must be called when |
| 40 // |source| initialization fails. | 39 // |source| initialization fails. |
| 41 ReadableStream(ExecutionContext*, UnderlyingSource* /* source */); | 40 ReadableStream(ExecutionContext*, UnderlyingSource* /* source */); |
| 42 virtual ~ReadableStream(); | 41 virtual ~ReadableStream(); |
| 43 | 42 |
| 44 bool isStarted() const { return m_isStarted; } | 43 bool isStarted() const { return m_isStarted; } |
| 45 bool isDraining() const { return m_isDraining; } | 44 bool isDraining() const { return m_isDraining; } |
| 46 bool isPulling() const { return m_isPulling; } | 45 bool isPulling() const { return m_isPulling; } |
| 47 State stateInternal() const { return m_state; } | 46 State state() const { return m_state; } |
| 48 DOMException* storedException() { return m_exception.get(); } | 47 String stateString() const; |
| 49 | 48 |
| 50 // |stateString|, |read| and |ready| are affected by an exclusive lock. Use | 49 virtual ScriptValue read(ScriptState*, ExceptionState&) = 0; |
| 51 // |stateInternal|, |readInternal| and |readyInternal| if you want to avoid | |
| 52 // that. | |
| 53 String stateString() const; | |
| 54 ScriptValue read(ScriptState*, ExceptionState&); | |
| 55 ScriptPromise ready(ScriptState*); | 50 ScriptPromise ready(ScriptState*); |
| 56 ScriptPromise cancel(ScriptState*, ScriptValue reason); | 51 ScriptPromise cancel(ScriptState*, ScriptValue reason); |
| 57 ScriptPromise closed(ScriptState*); | 52 ScriptPromise closed(ScriptState*); |
| 58 | 53 |
| 59 virtual ScriptValue readInternal(ScriptState*, ExceptionState&) = 0; | |
| 60 ScriptPromise readyInternal(ScriptState*); | |
| 61 | |
| 62 void close(); | 54 void close(); |
| 63 void error(PassRefPtrWillBeRawPtr<DOMException>); | 55 void error(PassRefPtrWillBeRawPtr<DOMException>); |
| 64 | 56 |
| 65 void didSourceStart(); | 57 void didSourceStart(); |
| 66 | 58 |
| 67 // This function is not a getter. It creates an ExclusiveStreamReader and | |
| 68 // returns it. | |
| 69 ExclusiveStreamReader* getReader(ExceptionState&); | |
| 70 // Only ExclusiveStreamReader methods should call this function. | |
| 71 void setReader(ExclusiveStreamReader*); | |
| 72 bool isLockedTo(const ExclusiveStreamReader* reader) const { return m_reader
== reader; } | |
| 73 | |
| 74 bool hasPendingActivity() const override; | 59 bool hasPendingActivity() const override; |
| 75 void trace(Visitor*) override; | 60 virtual void trace(Visitor*) override; |
| 76 | |
| 77 // Returns the string representation of the given State. | |
| 78 static String stateToString(State); | |
| 79 | 61 |
| 80 protected: | 62 protected: |
| 81 bool enqueuePreliminaryCheck(); | 63 bool enqueuePreliminaryCheck(); |
| 82 bool enqueuePostAction(); | 64 bool enqueuePostAction(); |
| 83 void readInternalPreliminaryCheck(ExceptionState&); | 65 void readPreliminaryCheck(ExceptionState&); |
| 84 void readInternalPostAction(); | 66 void readPostAction(); |
| 85 | 67 |
| 86 private: | 68 private: |
| 87 using WaitPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Undefi
nedGenerator, RefPtrWillBeMember<DOMException>>; | 69 typedef ScriptPromiseProperty<Member<ReadableStream>, ToV8UndefinedGenerator
, RefPtrWillBeMember<DOMException> > WaitPromise; |
| 88 using ClosedPromise = ScriptPromiseProperty<Member<ReadableStream>, ToV8Unde
finedGenerator, RefPtrWillBeMember<DOMException>>; | 70 typedef ScriptPromiseProperty<Member<ReadableStream>, ToV8UndefinedGenerator
, RefPtrWillBeMember<DOMException> > ClosedPromise; |
| 89 | 71 |
| 90 virtual bool isQueueEmpty() const = 0; | 72 virtual bool isQueueEmpty() const = 0; |
| 91 virtual void clearQueue() = 0; | 73 virtual void clearQueue() = 0; |
| 92 // This function will call ReadableStream::error on error. | 74 // This function will call ReadableStream::error on error. |
| 93 virtual bool shouldApplyBackpressure() = 0; | 75 virtual bool shouldApplyBackpressure() = 0; |
| 94 | 76 |
| 95 void callPullIfNeeded(); | 77 void callPullIfNeeded(); |
| 96 | 78 |
| 97 Member<UnderlyingSource> m_source; | 79 Member<UnderlyingSource> m_source; |
| 98 bool m_isStarted; | 80 bool m_isStarted; |
| 99 bool m_isDraining; | 81 bool m_isDraining; |
| 100 bool m_isPulling; | 82 bool m_isPulling; |
| 101 State m_state; | 83 State m_state; |
| 102 | 84 |
| 103 Member<WaitPromise> m_ready; | 85 Member<WaitPromise> m_ready; |
| 104 Member<ClosedPromise> m_closed; | 86 Member<ClosedPromise> m_closed; |
| 105 | |
| 106 RefPtrWillBeMember<DOMException> m_exception; | 87 RefPtrWillBeMember<DOMException> m_exception; |
| 107 Member<ExclusiveStreamReader> m_reader; | |
| 108 }; | 88 }; |
| 109 | 89 |
| 110 } // namespace blink | 90 } // namespace blink |
| 111 | 91 |
| 112 #endif // ReadableStream_h | 92 #endif // ReadableStream_h |
| OLD | NEW |