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
3 // found in the LICENSE file.
5 #ifndef ReadableStream_h
6 #define ReadableStream_h
8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseProperty.h"
10 #include "bindings/core/v8/ScriptState.h"
11 #include "bindings/core/v8/ScriptValue.h"
12 #include "bindings/core/v8/ScriptWrappable.h"
13 #include "bindings/core/v8/V8Binding.h"
14 #include "core/dom/ContextLifecycleObserver.h"
15 #include "platform/heap/Handle.h"
16 #include "wtf/Forward.h"
17 #include "wtf/PassRefPtr.h"
18 #include "wtf/RefPtr.h"
24 class UnderlyingSource;
26 class ReadableStream : public GarbageCollectedFinalized<ReadableStream>, public ScriptWrappable {
27 DEFINE_WRAPPERTYPEINFO();
36 // FIXME: Define Strategy here.
37 // FIXME: Add |strategy| constructor parameter.
38 // After ReadableStream construction, |didSourceStart| must be called when
39 // |source| initialization succeeds and |error| must be called when
40 // |source| initialization fails.
41 ReadableStream(ExecutionContext*, UnderlyingSource* /* source */);
42 virtual ~ReadableStream();
44 bool isStarted() const { return m_isStarted; }
45 bool isDraining() const { return m_isDraining; }
46 bool isPulling() const { return m_isPulling; }
47 State state() const { return m_state; }
48 String stateString() const;
50 virtual ScriptValue read(ScriptState*, ExceptionState&) = 0;
51 ScriptPromise wait(ScriptState*);
52 ScriptPromise cancel(ScriptState*, ScriptValue reason);
53 ScriptPromise closed(ScriptState*);
56 void error(PassRefPtrWillBeRawPtr<DOMException>);
58 void didSourceStart();
60 virtual void trace(Visitor*);
63 bool enqueuePreliminaryCheck(size_t chunkSize);
64 bool enqueuePostAction(size_t totalQueueSize);
65 void readPreliminaryCheck(ExceptionState&);
66 void readPostAction();
69 typedef ScriptPromiseProperty<Member<ReadableStream>, V8UndefinedType, RefPtrWillBeMember<DOMException> > WaitPromise;
70 typedef ScriptPromiseProperty<Member<ReadableStream>, V8UndefinedType, RefPtrWillBeMember<DOMException> > ClosedPromise;
72 virtual bool isQueueEmpty() const = 0;
73 virtual void clearQueue() = 0;
75 void callOrSchedulePull();
77 Member<UnderlyingSource> m_source;
81 bool m_isSchedulingPull;
84 Member<WaitPromise> m_wait;
85 Member<ClosedPromise> m_closed;
86 RefPtrWillBeMember<DOMException> m_exception;
91 #endif // ReadableStream_h