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.
5 #ifndef PDF_URL_LOADER_WRAPPER_IMPL_H_
6 #define PDF_URL_LOADER_WRAPPER_IMPL_H_
11 #include "base/macros.h"
12 #include "base/timer/timer.h"
13 #include "pdf/url_loader_wrapper.h"
14 #include "ppapi/cpp/url_loader.h"
15 #include "ppapi/utility/completion_callback_factory.h"
16 #include "ui/gfx/range/range.h"
22 namespace chrome_pdf {
24 class URLLoaderWrapperImpl : public URLLoaderWrapper {
26 URLLoaderWrapperImpl(pp::Instance* plugin_instance,
27 const pp::URLLoader& url_loader);
28 ~URLLoaderWrapperImpl() override;
30 // URLLoaderWrapper overrides:
31 int GetContentLength() const override;
32 bool IsAcceptRangesBytes() const override;
33 bool IsContentEncoded() const override;
34 std::string GetContentType() const override;
35 std::string GetContentDisposition() const override;
36 int GetStatusCode() const override;
37 bool IsMultipart() const override;
38 bool GetByteRangeStart(int* start) const override;
39 bool GetDownloadProgress(int64_t* bytes_received,
40 int64_t* total_bytes_to_be_received) const override;
41 void Close() override;
42 void OpenRange(const std::string& url,
43 const std::string& referrer_url,
46 const pp::CompletionCallback& cc) override;
47 void ReadResponseBody(char* buffer,
49 const pp::CompletionCallback& cc) override;
51 void SetResponseHeaders(const std::string& response_headers);
54 void SetHeadersFromLoader();
56 void DidOpen(int32_t result);
57 void DidRead(int32_t result);
59 void ReadResponseBodyImpl();
61 pp::Instance* const plugin_instance_;
62 pp::URLLoader url_loader_;
63 std::string response_headers_;
65 int content_length_ = -1;
66 bool accept_ranges_bytes_ = false;
67 bool content_encoded_ = false;
68 std::string content_type_;
69 std::string content_disposition_;
70 std::string multipart_boundary_;
71 gfx::Range byte_range_ = gfx::Range::InvalidRange();
72 bool is_multipart_ = false;
73 char* buffer_ = nullptr;
74 uint32_t buffer_size_ = 0;
75 bool multi_part_processed_ = false;
77 pp::CompletionCallback did_open_callback_;
78 pp::CompletionCallback did_read_callback_;
79 pp::CompletionCallbackFactory<URLLoaderWrapperImpl> callback_factory_;
81 base::OneShotTimer read_starter_;
83 DISALLOW_COPY_AND_ASSIGN(URLLoaderWrapperImpl);
86 } // namespace chrome_pdf
88 #endif // PDF_URL_LOADER_WRAPPER_IMPL_H_