| 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 // When the main thread sends a V8::TerminateExecution() signal to a worker |
| 23 // thread, any V8 API on the worker thread starts returning an empty |
| 24 // handle. This can happen in Body::readAsync. To avoid the situation, we |
| 25 // first check the ExecutionContext and return immediately if it's already |
| 26 // gone (which means that the V8::TerminateExecution() signal has been sent |
| 27 // to this worker thread). |
| 28 ExecutionContext* executionContext = scriptState->executionContext(); |
| 29 if (!executionContext) |
| 30 return ScriptPromise(); |
| 31 |
| 22 m_bodyUsed = true; | 32 m_bodyUsed = true; |
| 23 m_responseType = type; | 33 m_responseType = type; |
| 24 | 34 |
| 25 ASSERT(!m_resolver); | 35 ASSERT(!m_resolver); |
| 26 m_resolver = ScriptPromiseResolver::create(scriptState); | 36 m_resolver = ScriptPromiseResolver::create(scriptState); |
| 27 ScriptPromise promise = m_resolver->promise(); | 37 ScriptPromise promise = m_resolver->promise(); |
| 28 | 38 |
| 29 FileReaderLoader::ReadType readType = FileReaderLoader::ReadAsText; | 39 FileReaderLoader::ReadType readType = FileReaderLoader::ReadAsText; |
| 30 RefPtr<BlobDataHandle> blobHandle = blobDataHandle(); | 40 RefPtr<BlobDataHandle> blobHandle = blobDataHandle(); |
| 31 if (!blobHandle.get()) { | 41 if (!blobHandle.get()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 55 ASSERT_NOT_REACHED(); | 65 ASSERT_NOT_REACHED(); |
| 56 break; | 66 break; |
| 57 case ResponseAsJSON: | 67 case ResponseAsJSON: |
| 58 case ResponseAsText: | 68 case ResponseAsText: |
| 59 break; | 69 break; |
| 60 default: | 70 default: |
| 61 ASSERT_NOT_REACHED(); | 71 ASSERT_NOT_REACHED(); |
| 62 } | 72 } |
| 63 | 73 |
| 64 m_loader = adoptPtr(new FileReaderLoader(readType, this)); | 74 m_loader = adoptPtr(new FileReaderLoader(readType, this)); |
| 65 m_loader->start(scriptState->executionContext(), blobHandle); | 75 m_loader->start(executionContext, blobHandle); |
| 66 | 76 |
| 67 return promise; | 77 return promise; |
| 68 } | 78 } |
| 69 | 79 |
| 70 ScriptPromise Body::arrayBuffer(ScriptState* scriptState) | 80 ScriptPromise Body::arrayBuffer(ScriptState* scriptState) |
| 71 { | 81 { |
| 72 return readAsync(scriptState, ResponseAsArrayBuffer); | 82 return readAsync(scriptState, ResponseAsArrayBuffer); |
| 73 } | 83 } |
| 74 | 84 |
| 75 ScriptPromise Body::blob(ScriptState* scriptState) | 85 ScriptPromise Body::blob(ScriptState* scriptState) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 { | 183 { |
| 174 ASSERT(m_resolver); | 184 ASSERT(m_resolver); |
| 175 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) | 185 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ
eDOMObjectsAreStopped()) |
| 176 return; | 186 return; |
| 177 | 187 |
| 178 m_resolver->resolve(""); | 188 m_resolver->resolve(""); |
| 179 m_resolver.clear(); | 189 m_resolver.clear(); |
| 180 } | 190 } |
| 181 | 191 |
| 182 } // namespace blink | 192 } // namespace blink |
| OLD | NEW |