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 #include "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/Body.h" | 6 #include "modules/serviceworkers/Body.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/V8ThrowException.h" | 10 #include "bindings/core/v8/V8ThrowException.h" |
11 #include "core/fileapi/Blob.h" | 11 #include "core/fileapi/Blob.h" |
12 #include "core/fileapi/FileReaderLoader.h" | 12 #include "core/fileapi/FileReaderLoader.h" |
13 #include "core/fileapi/FileReaderLoaderClient.h" | 13 #include "core/fileapi/FileReaderLoaderClient.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 ScriptPromise Body::readAsync(ScriptState* scriptState, ResponseType type) | 17 ScriptPromise Body::readAsync(ScriptState* scriptState, ResponseType type) |
18 { | 18 { |
19 if (m_bodyUsed) | 19 if (m_bodyUsed) |
20 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("Already read", scriptState->isolate())); | 20 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("Already read", scriptState->isolate())); |
21 | 21 |
22 // executionContext may be 0 if V8::TerminateExecution() is called in the | |
23 // main thread. | |
haraken
2014/09/11 16:20:01
Let's elaborate the comment a bit more.
When the
horo
2014/09/11 16:49:55
Done.
| |
24 // FIXME: Handle this case in more better way. | |
25 ExecutionContext* executionContext = scriptState->executionContext(); | |
26 if (executionContext == 0) | |
haraken
2014/09/11 16:20:01
if (!executionContext)
horo
2014/09/11 16:49:55
Done.
| |
27 return ScriptPromise(); | |
28 | |
22 m_bodyUsed = true; | 29 m_bodyUsed = true; |
23 m_responseType = type; | 30 m_responseType = type; |
24 | 31 |
25 ASSERT(!m_resolver); | 32 ASSERT(!m_resolver); |
26 m_resolver = ScriptPromiseResolver::create(scriptState); | 33 m_resolver = ScriptPromiseResolver::create(scriptState); |
27 ScriptPromise promise = m_resolver->promise(); | 34 ScriptPromise promise = m_resolver->promise(); |
28 | 35 |
29 FileReaderLoader::ReadType readType = FileReaderLoader::ReadAsText; | 36 FileReaderLoader::ReadType readType = FileReaderLoader::ReadAsText; |
30 RefPtr<BlobDataHandle> blobHandle = blobDataHandle(); | 37 RefPtr<BlobDataHandle> blobHandle = blobDataHandle(); |
31 if (!blobHandle.get()) { | 38 if (!blobHandle.get()) { |
(...skipping 23 matching lines...) Expand all Loading... | |
55 ASSERT_NOT_REACHED(); | 62 ASSERT_NOT_REACHED(); |
56 break; | 63 break; |
57 case ResponseAsJSON: | 64 case ResponseAsJSON: |
58 case ResponseAsText: | 65 case ResponseAsText: |
59 break; | 66 break; |
60 default: | 67 default: |
61 ASSERT_NOT_REACHED(); | 68 ASSERT_NOT_REACHED(); |
62 } | 69 } |
63 | 70 |
64 m_loader = adoptPtr(new FileReaderLoader(readType, this)); | 71 m_loader = adoptPtr(new FileReaderLoader(readType, this)); |
65 m_loader->start(scriptState->executionContext(), blobHandle); | 72 m_loader->start(executionContext, blobHandle); |
66 | 73 |
67 return promise; | 74 return promise; |
68 } | 75 } |
69 | 76 |
70 ScriptPromise Body::arrayBuffer(ScriptState* scriptState) | 77 ScriptPromise Body::arrayBuffer(ScriptState* scriptState) |
71 { | 78 { |
72 return readAsync(scriptState, ResponseAsArrayBuffer); | 79 return readAsync(scriptState, ResponseAsArrayBuffer); |
73 } | 80 } |
74 | 81 |
75 ScriptPromise Body::blob(ScriptState* scriptState) | 82 ScriptPromise Body::blob(ScriptState* scriptState) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 { | 180 { |
174 ASSERT(m_resolver); | 181 ASSERT(m_resolver); |
175 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) | 182 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) |
176 return; | 183 return; |
177 | 184 |
178 m_resolver->resolve(""); | 185 m_resolver->resolve(""); |
179 m_resolver.clear(); | 186 m_resolver.clear(); |
180 } | 187 } |
181 | 188 |
182 } // namespace blink | 189 } // namespace blink |
OLD | NEW |