[email protected] | 44013f68 | 2012-05-31 13:49:40 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_IMAGE_DECODER_H_ |
6 | #define CHROME_BROWSER_IMAGE_DECODER_H_ | ||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 7 | |
[email protected] | 928c0e71 | 2011-03-16 15:01:57 | [diff] [blame] | 8 | #include <string> |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 9 | #include <vector> |
10 | |||||
[email protected] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 12 | #include "content/public/browser/browser_thread.h" |
13 | #include "content/public/browser/utility_process_host_client.h" | ||||
[email protected] | 373c106 | 2011-06-09 21:11:51 | [diff] [blame] | 14 | |
15 | class SkBitmap; | ||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 16 | |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 17 | // Decodes an image in a sandboxed process. |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 18 | class ImageDecoder : public content::UtilityProcessHostClient { |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 19 | public: |
20 | class Delegate { | ||||
21 | public: | ||||
22 | // Called when image is decoded. | ||||
[email protected] | 928c0e71 | 2011-03-16 15:01:57 | [diff] [blame] | 23 | // |decoder| is used to identify the image in case of decoding several |
24 | // images simultaneously. | ||||
25 | virtual void OnImageDecoded(const ImageDecoder* decoder, | ||||
26 | const SkBitmap& decoded_image) = 0; | ||||
27 | |||||
28 | // Called when decoding image failed. Delegate can do some cleanup in | ||||
29 | // this handler. | ||||
30 | virtual void OnDecodeImageFailed(const ImageDecoder* decoder) {} | ||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 31 | |
32 | protected: | ||||
33 | virtual ~Delegate() {} | ||||
34 | }; | ||||
35 | |||||
[email protected] | 11f16d10 | 2012-08-29 23:12:15 | [diff] [blame^] | 36 | enum ImageCodec { |
37 | DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage). | ||||
38 | ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec. | ||||
39 | }; | ||||
40 | |||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 41 | ImageDecoder(Delegate* delegate, |
[email protected] | 11f16d10 | 2012-08-29 23:12:15 | [diff] [blame^] | 42 | const std::string& image_data, |
43 | ImageCodec image_codec); | ||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 44 | |
45 | // Starts image decoding. | ||||
46 | void Start(); | ||||
47 | |||||
[email protected] | bebc8e12 | 2012-06-12 19:52:34 | [diff] [blame] | 48 | const std::vector<unsigned char>& get_image_data() const { |
49 | return image_data_; | ||||
50 | } | ||||
51 | |||||
[email protected] | 11b0856d | 2012-06-13 19:21:56 | [diff] [blame] | 52 | void set_delegate(Delegate* delegate) { delegate_ = delegate; } |
53 | |||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 54 | private: |
55 | // It's a reference counted object, so destructor is private. | ||||
[email protected] | 863e6d96 | 2011-05-15 19:39:35 | [diff] [blame] | 56 | virtual ~ImageDecoder(); |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 57 | |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 58 | // Overidden from UtilityProcessHostClient: |
[email protected] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 59 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
[email protected] | 373c106 | 2011-06-09 21:11:51 | [diff] [blame] | 60 | |
61 | // IPC message handlers. | ||||
62 | void OnDecodeImageSucceeded(const SkBitmap& decoded_image); | ||||
63 | void OnDecodeImageFailed(); | ||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 64 | |
65 | // Launches sandboxed process that will decode the image. | ||||
[email protected] | 4d9dcff | 2011-04-06 22:49:08 | [diff] [blame] | 66 | void DecodeImageInSandbox(const std::vector<unsigned char>& image_data); |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 67 | |
68 | Delegate* delegate_; | ||||
69 | std::vector<unsigned char> image_data_; | ||||
[email protected] | 11f16d10 | 2012-08-29 23:12:15 | [diff] [blame^] | 70 | const ImageCodec image_codec_; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 71 | content::BrowserThread::ID target_thread_id_; |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 72 | |
73 | DISALLOW_COPY_AND_ASSIGN(ImageDecoder); | ||||
74 | }; | ||||
75 | |||||
[email protected] | 6d33da17 | 2011-11-22 03:56:09 | [diff] [blame] | 76 | #endif // CHROME_BROWSER_IMAGE_DECODER_H_ |