OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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_RENDERER_IMAGE_LOADING_HELPER_H_ | |
6 #define CONTENT_RENDERER_IMAGE_LOADING_HELPER_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/scoped_vector.h" | |
12 #include "content/public/renderer/render_frame_observer.h" | |
13 #include "url/gurl.h" | |
14 | |
15 class SkBitmap; | |
16 | |
17 namespace content { | |
18 | |
19 class MultiResolutionImageResourceFetcher; | |
20 | |
21 // This class deals with image downloading. | |
22 // One instance of ImageLoadingHelper is owned by RenderFrame. | |
23 class ImageLoadingHelper : public RenderFrameObserver { | |
24 public: | |
25 explicit ImageLoadingHelper(RenderFrame* render_frame); | |
26 | |
27 private: | |
28 ~ImageLoadingHelper() override; | |
29 | |
30 // Message handler. | |
31 void OnDownloadImage(int id, | |
32 const GURL& image_url, | |
33 bool is_favicon, | |
34 uint32_t max_image_size, | |
35 bool bypass_cache); | |
36 | |
37 // Requests to download an image. When done, the ImageLoadingHelper | |
38 // is notified by way of DidDownloadImage. Returns true if the | |
39 // request was successfully started, false otherwise. id is used to | |
40 // uniquely identify the request and passed back to the | |
41 // DidDownloadImage method. If the image is a favicon, cookies will not be | |
42 // sent nor accepted during download. If the image has multiple frames, all | |
43 // the frames whose size <= |max_image_size| are returned. If all of the | |
44 // frames are larger than |max_image_size|, the smallest frame is resized to | |
45 // |max_image_size| and is the only result. |max_image_size| == 0 is | |
46 // interpreted as no max image size. | |
47 bool DownloadImage(int id, | |
48 const GURL& image_url, | |
49 bool is_favicon, | |
50 uint32_t max_image_size, | |
51 bool bypass_cache); | |
52 | |
53 // This callback is triggered when DownloadImage completes, either | |
54 // succesfully or with a failure. See DownloadImage for more | |
55 // details. | |
56 void DidDownloadImage( | |
57 uint32_t max_image_size, | |
58 MultiResolutionImageResourceFetcher* fetcher, | |
59 const std::vector<SkBitmap>& images); | |
60 | |
61 // Decodes a data: URL image or returns an empty image in case of failure. | |
62 SkBitmap ImageFromDataUrl(const GURL&) const; | |
63 | |
64 // RenderFrameObserver implementation. | |
65 bool OnMessageReceived(const IPC::Message& message) override; | |
66 | |
67 typedef ScopedVector<MultiResolutionImageResourceFetcher> | |
68 ImageResourceFetcherList; | |
69 | |
70 // ImageResourceFetchers schedule via DownloadImage. | |
71 ImageResourceFetcherList image_fetchers_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(ImageLoadingHelper); | |
74 }; | |
75 | |
76 } // namespace content | |
77 | |
78 #endif // CONTENT_RENDERER_IMAGE_LOADING_HELPER_H_ | |
79 | |
OLD | NEW |