1 // Copyright 2016 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 COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DECODER_H_ 6 #define COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DECODER_H_ 7 8 #include <string> 9 10 #include "base/callback_forward.h" 11 #include "base/macros.h" 12 13 namespace gfx { 14 class Image; 15 class Size; 16 } // namespace gfx 17 18 namespace image_fetcher { 19 20 using ImageDecodedCallback = base::OnceCallback<void(const gfx::Image&)>; 21 22 // ImageDecoder defines the common interface for decoding images. This is 23 // expected to process untrusted input from the web so implementations must be 24 // sure to decode safely. 25 class ImageDecoder { 26 public: ImageDecoder()27 ImageDecoder() {} ~ImageDecoder()28 virtual ~ImageDecoder() {} 29 30 // Decodes the passed |image_data| and runs the given callback. The callback 31 // is run even if decoding the image fails. In case an error occured during 32 // decoding the image an empty image is passed to the callback. 33 // For images with multiple frames (e.g. ico files), a frame with a size as 34 // close as possible to |desired_image_frame_size| is chosen (tries to take 35 // one in larger size if there's no precise match). Passing gfx::Size() as 36 // |desired_image_frame_size| is also supported and will result in chosing the 37 // smallest available size. 38 virtual void DecodeImage(const std::string& image_data, 39 const gfx::Size& desired_image_frame_size, 40 ImageDecodedCallback callback) = 0; 41 42 private: 43 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); 44 }; 45 46 } // namespace image_fetcher 47 48 #endif // COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DECODER_H_ 49