OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_BASE_H_ |
6 #define CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_IMPL_H_ | 6 #define CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_BASE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/callback.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "content/common/image_downloader/image_downloader.mojom.h" | |
15 #include "content/public/renderer/render_frame_observer.h" | 14 #include "content/public/renderer/render_frame_observer.h" |
16 #include "content/public/renderer/render_thread_observer.h" | 15 #include "content/public/renderer/render_thread_observer.h" |
17 #include "mojo/public/cpp/bindings/binding.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
19 | 18 |
20 class SkBitmap; | |
21 | |
22 namespace gfx { | |
23 class Size; | |
24 } | |
25 | |
26 namespace content { | 19 namespace content { |
27 | 20 |
28 class MultiResolutionImageResourceFetcher; | 21 class MultiResolutionImageResourceFetcher; |
29 class RenderFrame; | 22 class RenderFrame; |
30 | 23 |
31 class ImageDownloaderImpl : public mojom::ImageDownloader, | 24 class ImageDownloaderBase : public RenderFrameObserver, |
32 public RenderFrameObserver, | |
33 public RenderThreadObserver { | 25 public RenderThreadObserver { |
34 public: | 26 public: |
35 ~ImageDownloaderImpl() override; | 27 explicit ImageDownloaderBase(RenderFrame* render_frame); |
36 | 28 ~ImageDownloaderBase() override; |
37 static void CreateMojoService(RenderFrame* render_frame, | |
38 mojom::ImageDownloaderRequest request); | |
39 | 29 |
40 // RenderThreadObserver implementation. | 30 // RenderThreadObserver implementation. |
41 void OnRenderProcessShutdown() override; | 31 void OnRenderProcessShutdown() override; |
42 | 32 |
43 private: | 33 using DownloadCallback = |
44 ImageDownloaderImpl(RenderFrame* render_frame, | 34 base::Callback<void(int32_t, const std::vector<SkBitmap>&)>; |
45 mojom::ImageDownloaderRequest request); | 35 // Request to aynchronously download an image. When done, |callback| will be |
| 36 // called. |
| 37 void DownloadImage(const GURL& url, |
| 38 bool is_favicon, |
| 39 bool bypass_cache, |
| 40 const DownloadCallback& callback); |
46 | 41 |
| 42 protected: |
47 // RenderFrameObserver implementation. | 43 // RenderFrameObserver implementation. |
48 void OnDestruct() override; | 44 void OnDestruct() override; |
49 | 45 |
50 // ImageDownloader methods: | 46 private: |
51 void DownloadImage(const GURL& url, | 47 // Requests to fetch an image. When done, the image downloader is notified by |
52 bool is_favicon, | 48 // way of DidFetchImage. Returns true if the request was successfully started, |
53 uint32_t max_bitmap_size, | 49 // false otherwise. If the image is a favicon, cookies will not be sent nor |
54 bool bypass_cache, | 50 // accepted during download. If the image has multiple frames, all frames are |
55 const DownloadImageCallback& callback) override; | 51 // returned. |
56 | |
57 // Requests to fetch an image. When done, the ImageDownloaderImpl | |
58 // is notified by way of DidFetchImage. Returns true if the | |
59 // request was successfully started, false otherwise. | |
60 // If the image is a favicon, cookies will not be | |
61 // sent nor accepted during download. If the image has multiple frames, all | |
62 // the frames whose size <= |max_image_size| are returned. If all of the | |
63 // frames are larger than |max_image_size|, the smallest frame is resized to | |
64 // |max_image_size| and is the only result. |max_image_size| == 0 is | |
65 // interpreted as no max image size. | |
66 bool FetchImage(const GURL& image_url, | 52 bool FetchImage(const GURL& image_url, |
67 bool is_favicon, | 53 bool is_favicon, |
68 uint32_t max_image_size, | |
69 bool bypass_cache, | 54 bool bypass_cache, |
70 const DownloadImageCallback& callback); | 55 const DownloadCallback& callback); |
71 | 56 |
72 // This callback is triggered when FetchImage completes, either | 57 // This callback is triggered when FetchImage completes, either |
73 // succesfully or with a failure. See FetchImage for more | 58 // succesfully or with a failure. See FetchImage for more |
74 // details. | 59 // details. |
75 void DidFetchImage(uint32_t max_image_size, | 60 void DidFetchImage(const DownloadCallback& callback, |
76 const DownloadImageCallback& callback, | |
77 MultiResolutionImageResourceFetcher* fetcher, | 61 MultiResolutionImageResourceFetcher* fetcher, |
78 const std::vector<SkBitmap>& images); | 62 const std::vector<SkBitmap>& images); |
79 | 63 |
80 // Reply download result | |
81 void ReplyDownloadResult( | |
82 int32_t http_status_code, | |
83 const std::vector<SkBitmap>& result_images, | |
84 const std::vector<gfx::Size>& result_original_image_sizes, | |
85 const DownloadImageCallback& callback); | |
86 | |
87 typedef ScopedVector<MultiResolutionImageResourceFetcher> | 64 typedef ScopedVector<MultiResolutionImageResourceFetcher> |
88 ImageResourceFetcherList; | 65 ImageResourceFetcherList; |
89 | 66 |
90 // ImageResourceFetchers schedule via FetchImage. | 67 // ImageResourceFetchers schedule via FetchImage. |
91 ImageResourceFetcherList image_fetchers_; | 68 ImageResourceFetcherList image_fetchers_; |
92 | 69 |
93 mojo::Binding<mojom::ImageDownloader> binding_; | 70 DISALLOW_COPY_AND_ASSIGN(ImageDownloaderBase); |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(ImageDownloaderImpl); | |
96 }; | 71 }; |
97 | 72 |
98 } // namespace content | 73 } // namespace content |
99 | 74 |
100 #endif // CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_IMPL_H_ | 75 #endif // CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_BASE_H_ |
OLD | NEW |