OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_FETCHERS_IMAGE_RESOURCE_FETCHER_H_ | 5 #ifndef CONTENT_RENDERER_FETCHERS_IMAGE_RESOURCE_FETCHER_H_ |
6 #define CONTENT_RENDERER_FETCHERS_IMAGE_RESOURCE_FETCHER_H_ | 6 #define CONTENT_RENDERER_FETCHERS_IMAGE_RESOURCE_FETCHER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "content/renderer/fetchers/resource_fetcher.h" | 10 #include "content/renderer/fetchers/resource_fetcher.h" |
11 | 11 |
12 class SkBitmap; | 12 class SkBitmap; |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 // ImageResourceFetcher handles downloading an image for a webview. Once | 16 // ImageResourceFetcher handles downloading an image for a webview. Once |
17 // downloading is done the supplied callback is notified. ImageResourceFetcher | 17 // downloading is done the supplied callback is notified. ImageResourceFetcher |
18 // is used to download the favicon and images for web apps. | 18 // is used to download the favicon and images for web apps. |
19 class ImageResourceFetcher { | 19 class ImageResourceFetcher { |
20 public: | 20 public: |
21 typedef base::Callback<void(ImageResourceFetcher*, const SkBitmap&)> Callback; | 21 typedef base::Callback<void(ImageResourceFetcher*, const SkBitmap&)> Callback; |
22 | 22 |
23 ImageResourceFetcher( | 23 ImageResourceFetcher( |
24 const GURL& image_url, | 24 const GURL& image_url, |
25 WebKit::WebFrame* frame, | 25 blink::WebFrame* frame, |
26 int id, | 26 int id, |
27 int image_size, | 27 int image_size, |
28 WebKit::WebURLRequest::TargetType target_type, | 28 blink::WebURLRequest::TargetType target_type, |
29 const Callback& callback); | 29 const Callback& callback); |
30 | 30 |
31 virtual ~ImageResourceFetcher(); | 31 virtual ~ImageResourceFetcher(); |
32 | 32 |
33 // URL of the image we're downloading. | 33 // URL of the image we're downloading. |
34 const GURL& image_url() const { return image_url_; } | 34 const GURL& image_url() const { return image_url_; } |
35 | 35 |
36 // Unique identifier for the request. | 36 // Unique identifier for the request. |
37 int id() const { return id_; } | 37 int id() const { return id_; } |
38 | 38 |
39 private: | 39 private: |
40 // ResourceFetcher::Callback. Decodes the image and invokes callback_. | 40 // ResourceFetcher::Callback. Decodes the image and invokes callback_. |
41 void OnURLFetchComplete(const WebKit::WebURLResponse& response, | 41 void OnURLFetchComplete(const blink::WebURLResponse& response, |
42 const std::string& data); | 42 const std::string& data); |
43 | 43 |
44 Callback callback_; | 44 Callback callback_; |
45 | 45 |
46 // Unique identifier for the request. | 46 // Unique identifier for the request. |
47 const int id_; | 47 const int id_; |
48 | 48 |
49 // URL of the image. | 49 // URL of the image. |
50 const GURL image_url_; | 50 const GURL image_url_; |
51 | 51 |
52 // The size of the image. This is only a hint that is used if the image | 52 // The size of the image. This is only a hint that is used if the image |
53 // contains multiple sizes. A value of 0 results in using the first frame | 53 // contains multiple sizes. A value of 0 results in using the first frame |
54 // of the image. | 54 // of the image. |
55 const int image_size_; | 55 const int image_size_; |
56 | 56 |
57 // Does the actual download. | 57 // Does the actual download. |
58 scoped_ptr<ResourceFetcher> fetcher_; | 58 scoped_ptr<ResourceFetcher> fetcher_; |
59 | 59 |
60 DISALLOW_COPY_AND_ASSIGN(ImageResourceFetcher); | 60 DISALLOW_COPY_AND_ASSIGN(ImageResourceFetcher); |
61 }; | 61 }; |
62 | 62 |
63 } // namespace content | 63 } // namespace content |
64 | 64 |
65 #endif // CONTENT_RENDERER_FETCHERS_IMAGE_RESOURCE_FETCHER_H_ | 65 #endif // CONTENT_RENDERER_FETCHERS_IMAGE_RESOURCE_FETCHER_H_ |
OLD | NEW |