1 // Copyright (c) 2012 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_MULTI_RESOLUTION_IMAGE_RESOURCE_FETCHER_H_ 6 #define CONTENT_RENDERER_FETCHERS_MULTI_RESOLUTION_IMAGE_RESOURCE_FETCHER_H_ 7 8 #include <vector> 9 10 #include "base/basictypes.h" 11 #include "base/callback.h" 12 #include "content/renderer/fetchers/resource_fetcher.h" 13 14 class SkBitmap; 15 16 namespace content { 17 18 // A resource fetcher that returns all (differently-sized) frames in 19 // an image. Useful for favicons. 20 class MultiResolutionImageResourceFetcher{ 21 public: 22 typedef base::Callback<void(MultiResolutionImageResourceFetcher*, 23 const std::vector<SkBitmap>&)> Callback; 24 25 MultiResolutionImageResourceFetcher( 26 const GURL& image_url, 27 WebKit::WebFrame* frame, 28 int id, 29 WebKit::WebURLRequest::TargetType target_type, 30 const Callback& callback); 31 32 virtual ~MultiResolutionImageResourceFetcher(); 33 34 // URL of the image we're downloading. 35 const GURL& image_url() const { return image_url_; } 36 37 // Unique identifier for the request. 38 int id() const { return id_; } 39 40 // HTTP status code upon fetch completion. 41 int http_status_code() const { return http_status_code_; } 42 43 private: 44 // ResourceFetcher::Callback. Decodes the image and invokes callback_. 45 void OnURLFetchComplete(const WebKit::WebURLResponse& response, 46 const std::string& data); 47 48 Callback callback_; 49 50 // Unique identifier for the request. 51 const int id_; 52 53 // HTTP status code upon fetch completion. 54 int http_status_code_; 55 56 // URL of the image. 57 const GURL image_url_; 58 59 // Does the actual download. 60 scoped_ptr<ResourceFetcher> fetcher_; 61 62 DISALLOW_COPY_AND_ASSIGN(MultiResolutionImageResourceFetcher); 63 }; 64 65 } // namespace content 66 67 #endif // CONTENT_RENDERER_FETCHERS_MULTI_RESOLUTION_IMAGE_RESOURCE_FETCHER_H_ 68