Upload upstream chromium 76.0.3809.146
[platform/framework/web/chromium-efl.git] / pdf / url_loader_wrapper_impl.h
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 "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"
17
18 namespace pp {
19 class Instance;
20 }
21
22 namespace chrome_pdf {
23
24 class URLLoaderWrapperImpl : public URLLoaderWrapper {
25  public:
26   URLLoaderWrapperImpl(pp::Instance* plugin_instance,
27                        const pp::URLLoader& url_loader);
28   ~URLLoaderWrapperImpl() override;
29
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,
44                  uint32_t position,
45                  uint32_t size,
46                  const pp::CompletionCallback& cc) override;
47   void ReadResponseBody(char* buffer,
48                         int buffer_size,
49                         const pp::CompletionCallback& cc) override;
50
51   void SetResponseHeaders(const std::string& response_headers);
52
53  private:
54   void SetHeadersFromLoader();
55   void ParseHeaders();
56   void DidOpen(int32_t result);
57   void DidRead(int32_t result);
58
59   void ReadResponseBodyImpl();
60
61   pp::Instance* const plugin_instance_;
62   pp::URLLoader url_loader_;
63   std::string response_headers_;
64
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;
76
77   pp::CompletionCallback did_open_callback_;
78   pp::CompletionCallback did_read_callback_;
79   pp::CompletionCallbackFactory<URLLoaderWrapperImpl> callback_factory_;
80
81   base::OneShotTimer read_starter_;
82
83   DISALLOW_COPY_AND_ASSIGN(URLLoaderWrapperImpl);
84 };
85
86 }  // namespace chrome_pdf
87
88 #endif  // PDF_URL_LOADER_WRAPPER_IMPL_H_