Chromium Code Reviews| 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/FetchBodyStream.h" | 6 #include "modules/serviceworkers/FetchBodyStream.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/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/fileapi/Blob.h" | 12 #include "core/fileapi/Blob.h" |
| 13 #include "core/fileapi/FileReaderLoader.h" | 13 #include "core/fileapi/FileReaderLoader.h" |
| 14 #include "core/fileapi/FileReaderLoaderClient.h" | 14 #include "core/fileapi/FileReaderLoaderClient.h" |
| 15 #include "modules/serviceworkers/ResponseInit.h" | 15 #include "modules/serviceworkers/ResponseInit.h" |
| 16 #include "platform/NotImplemented.h" | 16 #include "platform/NotImplemented.h" |
| 17 #include "public/platform/WebServiceWorkerResponse.h" | 17 #include "public/platform/WebServiceWorkerResponse.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 PassRefPtrWillBeRawPtr<FetchBodyStream> FetchBodyStream::create(ExecutionContext * context, PassRefPtr<BlobDataHandle> blobDataHandle) | 21 PassRefPtrWillBeRawPtr<FetchBodyStream> FetchBodyStream::create(ExecutionContext * context, PassRefPtr<BlobDataHandle> blobDataHandle) |
| 22 { | 22 { |
| 23 RefPtrWillBeRawPtr<FetchBodyStream> fetchBodyStream(adoptRefWillBeNoop(new F etchBodyStream(context, blobDataHandle))); | 23 RefPtrWillBeRawPtr<FetchBodyStream> fetchBodyStream(adoptRefWillBeNoop(new F etchBodyStream(context, blobDataHandle))); |
| 24 fetchBodyStream->suspendIfNeeded(); | 24 fetchBodyStream->suspendIfNeeded(); |
| 25 return fetchBodyStream.release(); | 25 return fetchBodyStream.release(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 ScriptPromise FetchBodyStream::readAsync(ScriptState* scriptState, ResponseType type) | 28 ScriptPromise FetchBodyStream::readAsync(ScriptState* scriptState, ResponseType type) |
| 29 { | 29 { |
| 30 if (m_hasRead) | 30 if (m_hasRead) |
|
haraken
2014/09/04 08:13:03
I think you should check m_scriptState->contextIsE
horo
2014/09/04 09:54:28
Done.
| |
| 31 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("Already read", scriptState->isolate())); | 31 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror("Already read", scriptState->isolate())); |
| 32 | 32 |
| 33 m_hasRead = true; | 33 m_hasRead = true; |
| 34 m_responseType = type; | 34 m_responseType = type; |
| 35 | 35 |
| 36 ASSERT(!m_resolver); | 36 ASSERT(!m_resolver); |
| 37 m_resolver = ScriptPromiseResolver::create(scriptState); | 37 m_resolver = ScriptPromiseResolver::create(scriptState); |
| 38 ScriptPromise promise = m_resolver->promise(); | 38 ScriptPromise promise = m_resolver->promise(); |
| 39 | 39 |
| 40 FileReaderLoader::ReadType readType = FileReaderLoader::ReadAsText; | 40 FileReaderLoader::ReadType readType = FileReaderLoader::ReadAsText; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 59 // FIXME: Implement this. | 59 // FIXME: Implement this. |
| 60 ASSERT_NOT_REACHED(); | 60 ASSERT_NOT_REACHED(); |
| 61 break; | 61 break; |
| 62 case ResponseAsJSON: | 62 case ResponseAsJSON: |
| 63 case ResponseAsText: | 63 case ResponseAsText: |
| 64 break; | 64 break; |
| 65 default: | 65 default: |
| 66 ASSERT_NOT_REACHED(); | 66 ASSERT_NOT_REACHED(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 ExecutionContext* executionContext = scriptState->executionContext(); | |
| 70 if (!executionContext) { | |
| 71 m_resolver->reject(V8ThrowException::createTypeError("ExecutionContext t erminated", scriptState->isolate())); | |
| 72 m_resolver.clear(); | |
| 73 return promise; | |
| 74 } | |
| 75 | |
| 69 m_loader = adoptPtr(new FileReaderLoader(readType, this)); | 76 m_loader = adoptPtr(new FileReaderLoader(readType, this)); |
| 70 m_loader->start(scriptState->executionContext(), m_blobDataHandle); | 77 m_loader->start(executionContext, m_blobDataHandle); |
| 71 | 78 |
| 72 return promise; | 79 return promise; |
| 73 } | 80 } |
| 74 | 81 |
| 75 ScriptPromise FetchBodyStream::asArrayBuffer(ScriptState* scriptState) | 82 ScriptPromise FetchBodyStream::asArrayBuffer(ScriptState* scriptState) |
| 76 { | 83 { |
| 77 return readAsync(scriptState, ResponseAsArrayBuffer); | 84 return readAsync(scriptState, ResponseAsArrayBuffer); |
| 78 } | 85 } |
| 79 | 86 |
| 80 ScriptPromise FetchBodyStream::asBlob(ScriptState* scriptState) | 87 ScriptPromise FetchBodyStream::asBlob(ScriptState* scriptState) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 { | 185 { |
| 179 ASSERT(m_resolver); | 186 ASSERT(m_resolver); |
| 180 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) | 187 if (!m_resolver->executionContext() || m_resolver->executionContext()->activ eDOMObjectsAreStopped()) |
| 181 return; | 188 return; |
| 182 | 189 |
| 183 m_resolver->resolve(""); | 190 m_resolver->resolve(""); |
| 184 m_resolver.clear(); | 191 m_resolver.clear(); |
| 185 } | 192 } |
| 186 | 193 |
| 187 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |