OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_IMAGE_DOWNLOADER_IMPL_H_ | |
6 #define CONTENT_IMAGE_DOWNLOADER_IMPL_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/memory/scoped_vector.h" | |
11 #include "content/common/image_downloader/image_downloader.mojom.h" | |
12 #include "content/public/renderer/render_frame_observer.h" | |
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | |
14 #include "url/gurl.h" | |
15 | |
16 class SkBitmap; | |
17 | |
18 namespace gfx { | |
19 class Size; | |
20 } | |
21 | |
22 namespace content { | |
23 | |
24 class MultiResolutionImageResourceFetcher; | |
25 class RenderFrame; | |
26 | |
27 class ImageDownloaderImpl : public image_downloader::ImageDownloader, | |
28 public RenderFrameObserver { | |
29 public: | |
30 static void CreateMojoService( | |
31 RenderFrame* render_frame, | |
32 mojo::InterfaceRequest<image_downloader::ImageDownloader> request); | |
33 | |
34 private: | |
35 typedef mojo::Callback<void(image_downloader::DownloadResultPtr)> | |
Anand Mistry (off Chromium)
2015/04/16 01:07:16
This should already be defined in the generated co
leonhsl(Using Gerrit)
2015/04/17 06:14:34
Done.
| |
36 DownloadResultCallback; | |
37 | |
38 explicit ImageDownloaderImpl( | |
39 RenderFrame* render_frame, | |
40 mojo::InterfaceRequest<image_downloader::ImageDownloader> request); | |
41 ~ImageDownloaderImpl() override; | |
42 | |
43 // ImageDownloader methods: | |
44 void DownloadImage(image_downloader::DownloadReqPtr req, | |
45 const DownloadResultCallback& callback) override; | |
46 | |
47 // Requests to fetch an image. When done, the ImageDownloaderImpl | |
48 // is notified by way of DidFetchImage. Returns true if the | |
49 // request was successfully started, false otherwise. | |
50 // If the image is a favicon, cookies will not be | |
51 // sent nor accepted during download. If the image has multiple frames, all | |
52 // the frames whose size <= |max_image_size| are returned. If all of the | |
53 // frames are larger than |max_image_size|, the smallest frame is resized to | |
54 // |max_image_size| and is the only result. |max_image_size| == 0 is | |
55 // interpreted as no max image size. | |
56 bool FetchImage(const GURL& image_url, | |
57 bool is_favicon, | |
58 uint32_t max_image_size, | |
59 bool bypass_cache, | |
60 const DownloadResultCallback& callback); | |
61 | |
62 // This callback is triggered when FetchImage completes, either | |
63 // succesfully or with a failure. See FetchImage for more | |
64 // details. | |
65 void DidFetchImage(uint32_t max_image_size, | |
66 const DownloadResultCallback& callback, | |
67 MultiResolutionImageResourceFetcher* fetcher, | |
68 const std::vector<SkBitmap>& images); | |
69 | |
70 // Decodes a data: URL image or returns an empty image in case of failure. | |
71 SkBitmap ImageFromDataUrl(const GURL&) const; | |
72 | |
73 // Reply download result | |
74 void ReplyDownloadResult( | |
75 int32_t http_status_code, | |
76 const GURL& image_url, | |
77 const std::vector<SkBitmap>& result_images, | |
78 const std::vector<gfx::Size>& result_original_image_sizes, | |
79 const DownloadResultCallback& callback); | |
80 | |
81 // We use StrongBinding to ensure deletion of "this" when connection closed | |
82 mojo::StrongBinding<ImageDownloader> binding_; | |
83 | |
84 typedef ScopedVector<MultiResolutionImageResourceFetcher> | |
85 ImageResourceFetcherList; | |
86 | |
87 // ImageResourceFetchers schedule via FetchImage. | |
88 ImageResourceFetcherList image_fetchers_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(ImageDownloaderImpl); | |
91 }; | |
92 | |
93 } // namespace content | |
94 | |
95 #endif // CONTENT_IMAGE_DOWNLOADER_IMPL_H_ | |
OLD | NEW |