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