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 ReadableStreamImpl_h | 5 #ifndef ReadableStreamImpl_h |
6 #define ReadableStreamImpl_h | 6 #define ReadableStreamImpl_h |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
| 12 #include "core/dom/DOMArrayBuffer.h" |
12 #include "core/streams/ReadableStream.h" | 13 #include "core/streams/ReadableStream.h" |
13 #include "wtf/ArrayBuffer.h" | |
14 #include "wtf/Deque.h" | 14 #include "wtf/Deque.h" |
15 #include "wtf/Forward.h" | |
16 #include "wtf/OwnPtr.h" | |
17 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
18 #include "wtf/text/WTFString.h" | 16 #include "wtf/text/WTFString.h" |
19 | 17 |
20 namespace blink { | 18 namespace blink { |
21 | 19 |
22 // We define the default ChunkTypeTraits for frequently used types. | 20 // We define the default ChunkTypeTraits for frequently used types. |
23 template<typename ChunkType> | 21 template<typename ChunkType> |
24 class ReadableStreamChunkTypeTraits { }; | 22 class ReadableStreamChunkTypeTraits { }; |
25 | 23 |
26 template<> | 24 template<> |
27 class ReadableStreamChunkTypeTraits<String> { | 25 class ReadableStreamChunkTypeTraits<String> { |
28 public: | 26 public: |
29 typedef String HoldType; | 27 typedef String HoldType; |
30 typedef const String& PassType; | 28 typedef const String& PassType; |
31 | 29 |
32 static size_t size(const String& value) { return value.length(); } | 30 static size_t size(const String& value) { return value.length(); } |
33 static ScriptValue toScriptValue(ScriptState* scriptState, const HoldType& v
alue) | 31 static ScriptValue toScriptValue(ScriptState* scriptState, const HoldType& v
alue) |
34 { | 32 { |
35 return ScriptValue(scriptState, v8String(scriptState->isolate(), value))
; | 33 return ScriptValue(scriptState, v8String(scriptState->isolate(), value))
; |
36 } | 34 } |
37 }; | 35 }; |
38 | 36 |
39 template<> | 37 template<> |
40 class ReadableStreamChunkTypeTraits<ArrayBuffer> { | 38 class ReadableStreamChunkTypeTraits<DOMArrayBuffer> { |
41 public: | 39 public: |
42 typedef RefPtr<ArrayBuffer> HoldType; | 40 typedef RefPtr<DOMArrayBuffer> HoldType; |
43 typedef PassRefPtr<ArrayBuffer> PassType; | 41 typedef PassRefPtr<DOMArrayBuffer> PassType; |
44 | 42 |
45 static size_t size(const PassType& value) { return value->byteLength(); } | 43 static size_t size(const PassType& value) { return value->byteLength(); } |
46 static size_t size(const HoldType& value) { return value->byteLength(); } | 44 static size_t size(const HoldType& value) { return value->byteLength(); } |
47 static ScriptValue toScriptValue(ScriptState* scriptState, const HoldType& v
alue) | 45 static ScriptValue toScriptValue(ScriptState* scriptState, const HoldType& v
alue) |
48 { | 46 { |
49 return ScriptValue(scriptState, toV8NoInline(value.get(), scriptState->c
ontext()->Global(), scriptState->isolate())); | 47 return ScriptValue(scriptState, toV8NoInline(value.get(), scriptState->c
ontext()->Global(), scriptState->isolate())); |
50 } | 48 } |
51 }; | 49 }; |
52 | 50 |
53 // ReadableStreamImpl<ChunkTypeTraits> is a ReadableStream subtype. It has a | 51 // ReadableStreamImpl<ChunkTypeTraits> is a ReadableStream subtype. It has a |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 ASSERT(!m_queue.isEmpty()); | 103 ASSERT(!m_queue.isEmpty()); |
106 typename ChunkTypeTraits::HoldType chunk = m_queue.takeFirst(); | 104 typename ChunkTypeTraits::HoldType chunk = m_queue.takeFirst(); |
107 m_totalQueueSize -= ChunkTypeTraits::size(chunk); | 105 m_totalQueueSize -= ChunkTypeTraits::size(chunk); |
108 readPostAction(); | 106 readPostAction(); |
109 return ChunkTypeTraits::toScriptValue(scriptState, chunk); | 107 return ChunkTypeTraits::toScriptValue(scriptState, chunk); |
110 } | 108 } |
111 | 109 |
112 } // namespace blink | 110 } // namespace blink |
113 | 111 |
114 #endif // ReadableStreamImpl_h | 112 #endif // ReadableStreamImpl_h |
115 | |
OLD | NEW |