OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #ifndef PDF_URL_LOADER_WRAPPER_IMPL_H_ |
| 6 #define PDF_URL_LOADER_WRAPPER_IMPL_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "pdf/url_loader_wrapper.h" |
| 13 #include "ppapi/cpp/url_loader.h" |
| 14 #include "ppapi/utility/completion_callback_factory.h" |
| 15 #include "ui/gfx/range/range.h" |
| 16 |
| 17 namespace pp { |
| 18 class Instance; |
| 19 }; |
| 20 |
| 21 namespace chrome_pdf { |
| 22 |
| 23 class URLLoaderWrapperImpl : public URLLoaderWrapper { |
| 24 public: |
| 25 URLLoaderWrapperImpl(pp::Instance* plugin_instance, |
| 26 const pp::URLLoader& url_loader); |
| 27 ~URLLoaderWrapperImpl() override; |
| 28 |
| 29 // URLLoaderWrapper overrides: |
| 30 int GetContentLength() const override; |
| 31 bool IsAcceptRangesBytes() const override; |
| 32 bool IsContentEncoded() const override; |
| 33 std::string GetContentType() const override; |
| 34 std::string GetContentDisposition() const override; |
| 35 int GetStatusCode() const override; |
| 36 bool IsMultipart() const override; |
| 37 bool GetByteRange(int* start, int* end) const override; |
| 38 bool GetDownloadProgress(int64_t* bytes_received, |
| 39 int64_t* total_bytes_to_be_received) const override; |
| 40 void Close() override; |
| 41 void OpenRange(const std::string& url, |
| 42 const std::string& referrer_url, |
| 43 uint32_t position, |
| 44 uint32_t size, |
| 45 const pp::CompletionCallback& cc) override; |
| 46 void ReadResponseBody(char* buffer, |
| 47 int buffer_size, |
| 48 const pp::CompletionCallback& cc) override; |
| 49 |
| 50 void SetResponseHeaders(const std::string& response_headers); |
| 51 |
| 52 private: |
| 53 class ReadStarter; |
| 54 |
| 55 void SetHeadersFromLoader(); |
| 56 void ParseHeaders(); |
| 57 void DidOpen(int32_t result); |
| 58 void DidRead(int32_t result); |
| 59 |
| 60 void ReadResponseBodyImpl(); |
| 61 |
| 62 pp::Instance* const plugin_instance_; |
| 63 pp::URLLoader url_loader_; |
| 64 std::string response_headers_; |
| 65 |
| 66 int content_length_ = -1; |
| 67 bool accept_ranges_bytes_ = false; |
| 68 bool content_encoded_ = false; |
| 69 std::string content_type_; |
| 70 std::string content_disposition_; |
| 71 std::string multipart_boundary_; |
| 72 gfx::Range byte_range_ = gfx::Range::InvalidRange(); |
| 73 bool is_multipart_ = false; |
| 74 char* buffer_ = nullptr; |
| 75 uint32_t buffer_size_ = 0; |
| 76 bool multi_part_processed_ = false; |
| 77 |
| 78 pp::CompletionCallback did_open_callback_; |
| 79 pp::CompletionCallback did_read_callback_; |
| 80 pp::CompletionCallbackFactory<URLLoaderWrapperImpl> callback_factory_; |
| 81 |
| 82 std::unique_ptr<ReadStarter> read_starter_; |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(URLLoaderWrapperImpl); |
| 85 }; |
| 86 |
| 87 } // namespace chrome_pdf |
| 88 |
| 89 #endif // PDF_URL_LOADER_WRAPPER_IMPL_H_ |
OLD | NEW |