OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/utility/chrome_content_utility_client.h" | 5 #include "chrome/utility/chrome_content_utility_client.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 175 } |
176 | 176 |
177 bool ChromeContentUtilityClient::OnMessageReceived( | 177 bool ChromeContentUtilityClient::OnMessageReceived( |
178 const IPC::Message& message) { | 178 const IPC::Message& message) { |
179 if (filter_messages_ && !ContainsKey(message_id_whitelist_, message.type())) | 179 if (filter_messages_ && !ContainsKey(message_id_whitelist_, message.type())) |
180 return false; | 180 return false; |
181 | 181 |
182 bool handled = true; | 182 bool handled = true; |
183 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 183 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
184 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) | 184 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) |
| 185 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageByHandle, |
| 186 OnDecodeImageByHandle) |
185 #if defined(OS_CHROMEOS) | 187 #if defined(OS_CHROMEOS) |
186 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, | 188 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, |
187 OnRobustJPEGDecodeImage) | 189 OnRobustJPEGDecodeImage) |
188 #endif // defined(OS_CHROMEOS) | 190 #endif // defined(OS_CHROMEOS) |
189 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) | 191 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) |
190 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, | 192 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, |
191 OnPatchFileBsdiff) | 193 OnPatchFileBsdiff) |
192 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, | 194 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, |
193 OnPatchFileCourgette) | 195 OnPatchFileCourgette) |
194 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) | 196 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 289 |
288 if (decoded_image.empty()) { | 290 if (decoded_image.empty()) { |
289 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id)); | 291 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id)); |
290 } else { | 292 } else { |
291 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image, | 293 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image, |
292 request_id)); | 294 request_id)); |
293 } | 295 } |
294 ReleaseProcessIfNeeded(); | 296 ReleaseProcessIfNeeded(); |
295 } | 297 } |
296 | 298 |
| 299 void ChromeContentUtilityClient::OnDecodeImageByHandle( |
| 300 const IPC::PlatformFileForTransit& image_file, |
| 301 bool shrink_to_fit, |
| 302 int request_id) { |
| 303 base::File file = IPC::PlatformFileForTransitToFile(image_file); |
| 304 |
| 305 std::vector<unsigned char> image_data(file.GetLength()); |
| 306 int read_bytes = file.Read( |
| 307 0, reinterpret_cast<char*>(image_data.data()), file.GetLength()); |
| 308 if (read_bytes <= 0) { |
| 309 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id)); |
| 310 return; |
| 311 } |
| 312 DecodeImageAndSend(image_data, shrink_to_fit, request_id); |
| 313 } |
| 314 |
297 void ChromeContentUtilityClient::OnDecodeImage( | 315 void ChromeContentUtilityClient::OnDecodeImage( |
298 const std::vector<unsigned char>& encoded_data, | 316 const std::vector<unsigned char>& encoded_data, |
299 bool shrink_to_fit, | 317 bool shrink_to_fit, |
300 int request_id) { | 318 int request_id) { |
301 DecodeImageAndSend(encoded_data, shrink_to_fit, request_id); | 319 DecodeImageAndSend(encoded_data, shrink_to_fit, request_id); |
302 } | 320 } |
303 | 321 |
304 #if defined(OS_CHROMEOS) | 322 #if defined(OS_CHROMEOS) |
305 void ChromeContentUtilityClient::OnCreateZipFile( | 323 void ChromeContentUtilityClient::OnCreateZipFile( |
306 const base::FilePath& src_dir, | 324 const base::FilePath& src_dir, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 const std::string& mime_type, int64 total_size, bool get_attached_images) { | 459 const std::string& mime_type, int64 total_size, bool get_attached_images) { |
442 // Only one IPCDataSource may be created and added to the list of handlers. | 460 // Only one IPCDataSource may be created and added to the list of handlers. |
443 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); | 461 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); |
444 handlers_.push_back(source); | 462 handlers_.push_back(source); |
445 | 463 |
446 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( | 464 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( |
447 source, mime_type, get_attached_images); | 465 source, mime_type, get_attached_images); |
448 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); | 466 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); |
449 } | 467 } |
450 #endif | 468 #endif |
OLD | NEW |