Chromium Code Reviews| 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_CORE_H_ |
| 6 #define CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_IMPL_H_ | 6 #define CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_CORE_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" | |
| 16 #include "content/public/renderer/render_thread_observer.h" | 14 #include "content/public/renderer/render_thread_observer.h" |
| 17 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 18 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 19 | 17 |
| 20 class SkBitmap; | |
| 21 | |
| 22 namespace gfx { | |
| 23 class Size; | |
| 24 } | |
| 25 | |
| 26 namespace content { | 18 namespace content { |
| 27 | 19 |
| 28 class MultiResolutionImageResourceFetcher; | 20 class MultiResolutionImageResourceFetcher; |
| 29 class RenderFrame; | 21 class RenderFrame; |
| 30 | 22 |
| 31 class ImageDownloaderImpl : public mojom::ImageDownloader, | 23 class ImageDownloaderCore : public RenderThreadObserver { |
| 32 public RenderFrameObserver, | |
| 33 public RenderThreadObserver { | |
| 34 public: | 24 public: |
| 35 ~ImageDownloaderImpl() override; | 25 // |render_frame| outlives this class. |
| 36 | 26 explicit ImageDownloaderCore(RenderFrame* render_frame); |
| 37 static void CreateMojoService(RenderFrame* render_frame, | 27 ~ImageDownloaderCore() override; |
| 38 mojom::ImageDownloaderRequest request); | |
| 39 | 28 |
| 40 // RenderThreadObserver implementation. | 29 // RenderThreadObserver implementation. |
| 41 void OnRenderProcessShutdown() override; | 30 void OnRenderProcessShutdown() override; |
| 42 | 31 |
| 43 private: | 32 using DownloadCallback = |
| 44 ImageDownloaderImpl(RenderFrame* render_frame, | 33 base::Callback<void(int32_t, const std::vector<SkBitmap>&)>; |
| 45 mojom::ImageDownloaderRequest request); | 34 // Request to aynchronously download an image. When done, |callback| will be |
| 46 | 35 // called. |
| 47 // RenderFrameObserver implementation. | |
| 48 void OnDestruct() override; | |
| 49 | |
| 50 // ImageDownloader methods: | |
| 51 void DownloadImage(const GURL& url, | 36 void DownloadImage(const GURL& url, |
| 52 bool is_favicon, | 37 bool is_favicon, |
| 53 uint32_t max_bitmap_size, | |
| 54 bool bypass_cache, | 38 bool bypass_cache, |
| 55 const DownloadImageCallback& callback) override; | 39 const DownloadCallback& callback); |
| 56 | 40 |
| 41 private: | |
| 57 // Requests to fetch an image. When done, the ImageDownloaderImpl | 42 // Requests to fetch an image. When done, the ImageDownloaderImpl |
|
miu
2016/12/03 01:05:30
s/ImageDownloaderImpl/image downloader/
xjz
2016/12/06 19:50:55
Done.
| |
| 58 // is notified by way of DidFetchImage. Returns true if the | 43 // is notified by way of DidFetchImage. Returns true if the |
| 59 // request was successfully started, false otherwise. | 44 // request was successfully started, false otherwise. |
| 60 // If the image is a favicon, cookies will not be | 45 // If the image is a favicon, cookies will not be |
| 61 // sent nor accepted during download. If the image has multiple frames, all | 46 // 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 | 47 // frames are returned. |
| 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, | 48 bool FetchImage(const GURL& image_url, |
| 67 bool is_favicon, | 49 bool is_favicon, |
| 68 uint32_t max_image_size, | |
| 69 bool bypass_cache, | 50 bool bypass_cache, |
| 70 const DownloadImageCallback& callback); | 51 const DownloadCallback& callback); |
| 71 | 52 |
| 72 // This callback is triggered when FetchImage completes, either | 53 // This callback is triggered when FetchImage completes, either |
| 73 // succesfully or with a failure. See FetchImage for more | 54 // succesfully or with a failure. See FetchImage for more |
| 74 // details. | 55 // details. |
| 75 void DidFetchImage(uint32_t max_image_size, | 56 void DidFetchImage(const DownloadCallback& callback, |
| 76 const DownloadImageCallback& callback, | |
| 77 MultiResolutionImageResourceFetcher* fetcher, | 57 MultiResolutionImageResourceFetcher* fetcher, |
| 78 const std::vector<SkBitmap>& images); | 58 const std::vector<SkBitmap>& images); |
| 79 | 59 |
| 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> | 60 typedef ScopedVector<MultiResolutionImageResourceFetcher> |
| 88 ImageResourceFetcherList; | 61 ImageResourceFetcherList; |
| 89 | 62 |
| 90 // ImageResourceFetchers schedule via FetchImage. | 63 // ImageResourceFetchers schedule via FetchImage. |
| 91 ImageResourceFetcherList image_fetchers_; | 64 ImageResourceFetcherList image_fetchers_; |
| 92 | 65 |
| 93 mojo::Binding<mojom::ImageDownloader> binding_; | 66 RenderFrame* const render_frame_; // Outlives this class. |
| 94 | 67 |
| 95 DISALLOW_COPY_AND_ASSIGN(ImageDownloaderImpl); | 68 DISALLOW_COPY_AND_ASSIGN(ImageDownloaderCore); |
| 96 }; | 69 }; |
| 97 | 70 |
| 98 } // namespace content | 71 } // namespace content |
| 99 | 72 |
| 100 #endif // CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_IMPL_H_ | 73 #endif // CONTENT_RENDERER_IMAGE_DOWNLOADER_IMAGE_DOWNLOADER_CORE_H_ |
| OLD | NEW |