OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_IMPL_H_ |
6 #define CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_IMPL_H_ | 6 #define CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_IMPL_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" | |
13 #include "base/memory/scoped_vector.h" | |
14 #include "content/common/image_downloader/image_downloader.mojom.h" | 12 #include "content/common/image_downloader/image_downloader.mojom.h" |
15 #include "content/public/renderer/render_frame_observer.h" | 13 #include "content/public/renderer/render_frame_observer.h" |
16 #include "content/public/renderer/render_thread_observer.h" | 14 #include "content/renderer/image_downloader/image_downloader_core.h" |
17 #include "mojo/public/cpp/bindings/binding.h" | 15 #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 ImageDownloaderCore; |
29 class RenderFrame; | 22 class RenderFrame; |
30 | 23 |
31 class ImageDownloaderImpl : public mojom::ImageDownloader, | 24 class ImageDownloaderImpl : public mojom::ImageDownloader, |
32 public RenderFrameObserver, | 25 public RenderFrameObserver { |
33 public RenderThreadObserver { | |
34 public: | 26 public: |
35 ~ImageDownloaderImpl() override; | 27 ~ImageDownloaderImpl() override; |
36 | 28 |
37 static void CreateMojoService(RenderFrame* render_frame, | 29 static void CreateMojoService(RenderFrame* render_frame, |
38 mojom::ImageDownloaderRequest request); | 30 mojom::ImageDownloaderRequest request); |
39 | 31 |
40 // RenderThreadObserver implementation. | |
41 void OnRenderProcessShutdown() override; | |
42 | |
43 private: | 32 private: |
44 ImageDownloaderImpl(RenderFrame* render_frame, | 33 ImageDownloaderImpl(RenderFrame* render_frame, |
45 mojom::ImageDownloaderRequest request); | 34 mojom::ImageDownloaderRequest request); |
46 | 35 |
47 // RenderFrameObserver implementation. | 36 // RenderFrameObserver implementation. |
48 void OnDestruct() override; | 37 void OnDestruct() override; |
49 | 38 |
50 // ImageDownloader methods: | 39 // ImageDownloader implementation. |
51 void DownloadImage(const GURL& url, | 40 void DownloadImage(const GURL& url, |
52 bool is_favicon, | 41 bool is_favicon, |
53 uint32_t max_bitmap_size, | 42 uint32_t max_bitmap_size, |
54 bool bypass_cache, | 43 bool bypass_cache, |
55 const DownloadImageCallback& callback) override; | 44 const DownloadImageCallback& callback) override; |
56 | 45 |
57 // Requests to fetch an image. When done, the ImageDownloaderImpl | 46 // Called when downloading finishes. All frames in |images| whose size <= |
58 // is notified by way of DidFetchImage. Returns true if the | 47 // |max_image_size| will be returned through |callback|. If all of the frames |
59 // request was successfully started, false otherwise. | 48 // are larger than |max_image_size|, the smallest frame is resized to |
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 | 49 // |max_image_size| and is the only result. |max_image_size| == 0 is |
65 // interpreted as no max image size. | 50 // interpreted as no max image size. |
66 bool FetchImage(const GURL& image_url, | 51 void DidDownloadImage(uint32_t max_bitmap_size, |
67 bool is_favicon, | 52 const DownloadImageCallback& callback, |
68 uint32_t max_image_size, | 53 int32_t http_status_code, |
69 bool bypass_cache, | 54 const std::vector<SkBitmap>& images); |
70 const DownloadImageCallback& callback); | |
71 | |
72 // This callback is triggered when FetchImage completes, either | |
73 // succesfully or with a failure. See FetchImage for more | |
74 // details. | |
75 void DidFetchImage(uint32_t max_image_size, | |
76 const DownloadImageCallback& callback, | |
77 MultiResolutionImageResourceFetcher* fetcher, | |
78 const std::vector<SkBitmap>& images); | |
79 | |
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> | |
88 ImageResourceFetcherList; | |
89 | |
90 // ImageResourceFetchers schedule via FetchImage. | |
91 ImageResourceFetcherList image_fetchers_; | |
92 | 55 |
93 mojo::Binding<mojom::ImageDownloader> binding_; | 56 mojo::Binding<mojom::ImageDownloader> binding_; |
94 | 57 |
58 ImageDownloaderCore image_downloader_; | |
miu
2016/12/03 01:05:30
If the core installs a RenderFrameObserver (see ot
xjz
2016/12/06 19:50:55
Changed to use inheritance and "delete this" in ba
xjz
2016/12/06 23:58:17
As commented elsewhere, removed "delete this" in b
| |
59 | |
95 DISALLOW_COPY_AND_ASSIGN(ImageDownloaderImpl); | 60 DISALLOW_COPY_AND_ASSIGN(ImageDownloaderImpl); |
96 }; | 61 }; |
97 | 62 |
98 } // namespace content | 63 } // namespace content |
99 | 64 |
100 #endif // CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_IMPL_H_ | 65 #endif // CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_IMPL_H_ |
OLD | NEW |