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