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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 decoded_image.reset(); | 230 decoded_image.reset(); |
231 LOG(ERROR) << "Decoded image too large for IPC message"; | 231 LOG(ERROR) << "Decoded image too large for IPC message"; |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 return decoded_image; | 235 return decoded_image; |
236 } | 236 } |
237 | 237 |
238 // static | 238 // static |
239 void ChromeContentUtilityClient::DecodeImageAndSend( | 239 void ChromeContentUtilityClient::DecodeImageAndSend( |
240 const std::vector<unsigned char>& encoded_data, bool shrink_to_fit){ | 240 const std::vector<unsigned char>& encoded_data, |
| 241 bool shrink_to_fit, |
| 242 int id) { |
241 SkBitmap decoded_image = DecodeImage(encoded_data, shrink_to_fit); | 243 SkBitmap decoded_image = DecodeImage(encoded_data, shrink_to_fit); |
242 | 244 |
243 if (decoded_image.empty()) { | 245 if (decoded_image.empty()) { |
244 Send(new ChromeUtilityHostMsg_DecodeImage_Failed()); | 246 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(id)); |
245 } else { | 247 } else { |
246 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image)); | 248 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image, id)); |
247 } | 249 } |
248 ReleaseProcessIfNeeded(); | 250 ReleaseProcessIfNeeded(); |
249 } | 251 } |
250 | 252 |
251 void ChromeContentUtilityClient::OnDecodeImage( | 253 void ChromeContentUtilityClient::OnDecodeImage( |
252 const std::vector<unsigned char>& encoded_data, bool shrink_to_fit) { | 254 const std::vector<unsigned char>& encoded_data, |
253 DecodeImageAndSend(encoded_data, shrink_to_fit); | 255 bool shrink_to_fit, |
| 256 int id) { |
| 257 DecodeImageAndSend(encoded_data, shrink_to_fit, id); |
254 } | 258 } |
255 | 259 |
256 #if defined(OS_CHROMEOS) | 260 #if defined(OS_CHROMEOS) |
257 void ChromeContentUtilityClient::OnCreateZipFile( | 261 void ChromeContentUtilityClient::OnCreateZipFile( |
258 const base::FilePath& src_dir, | 262 const base::FilePath& src_dir, |
259 const std::vector<base::FilePath>& src_relative_paths, | 263 const std::vector<base::FilePath>& src_relative_paths, |
260 const base::FileDescriptor& dest_fd) { | 264 const base::FileDescriptor& dest_fd) { |
261 // dest_fd should be closed in the function. See ipc/ipc_message_util.h for | 265 // dest_fd should be closed in the function. See ipc/ipc_message_util.h for |
262 // details. | 266 // details. |
263 base::ScopedFD fd_closer(dest_fd.fd); | 267 base::ScopedFD fd_closer(dest_fd.fd); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 bool supports_syscall = sandbox::SandboxBPF::SupportsSeccompSandbox( | 299 bool supports_syscall = sandbox::SandboxBPF::SupportsSeccompSandbox( |
296 sandbox::SandboxBPF::SeccompLevel::MULTI_THREADED); | 300 sandbox::SandboxBPF::SeccompLevel::MULTI_THREADED); |
297 Send(new ChromeUtilityHostMsg_DetectSeccompSupport_ResultSyscall( | 301 Send(new ChromeUtilityHostMsg_DetectSeccompSupport_ResultSyscall( |
298 supports_syscall)); | 302 supports_syscall)); |
299 | 303 |
300 ReleaseProcessIfNeeded(); | 304 ReleaseProcessIfNeeded(); |
301 } | 305 } |
302 #endif // defined(OS_ANDROID) && defined(USE_SECCOMP_BPF) | 306 #endif // defined(OS_ANDROID) && defined(USE_SECCOMP_BPF) |
303 | 307 |
304 void ChromeContentUtilityClient::OnRobustJPEGDecodeImage( | 308 void ChromeContentUtilityClient::OnRobustJPEGDecodeImage( |
305 const std::vector<unsigned char>& encoded_data) { | 309 const std::vector<unsigned char>& encoded_data, |
| 310 int id) { |
306 // Our robust jpeg decoding is using IJG libjpeg. | 311 // Our robust jpeg decoding is using IJG libjpeg. |
307 if (gfx::JPEGCodec::JpegLibraryVariant() == gfx::JPEGCodec::IJG_LIBJPEG && | 312 if (gfx::JPEGCodec::JpegLibraryVariant() == gfx::JPEGCodec::IJG_LIBJPEG && |
308 !encoded_data.empty()) { | 313 !encoded_data.empty()) { |
309 scoped_ptr<SkBitmap> decoded_image(gfx::JPEGCodec::Decode( | 314 scoped_ptr<SkBitmap> decoded_image(gfx::JPEGCodec::Decode( |
310 &encoded_data[0], encoded_data.size())); | 315 &encoded_data[0], encoded_data.size())); |
311 if (!decoded_image.get() || decoded_image->empty()) { | 316 if (!decoded_image.get() || decoded_image->empty()) { |
312 Send(new ChromeUtilityHostMsg_DecodeImage_Failed()); | 317 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(id)); |
313 } else { | 318 } else { |
314 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image)); | 319 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image, id)); |
315 } | 320 } |
316 } else { | 321 } else { |
317 Send(new ChromeUtilityHostMsg_DecodeImage_Failed()); | 322 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(id)); |
318 } | 323 } |
319 ReleaseProcessIfNeeded(); | 324 ReleaseProcessIfNeeded(); |
320 } | 325 } |
321 | 326 |
322 void ChromeContentUtilityClient::OnParseJSON(const std::string& json) { | 327 void ChromeContentUtilityClient::OnParseJSON(const std::string& json) { |
323 int error_code; | 328 int error_code; |
324 std::string error; | 329 std::string error; |
325 base::Value* value = base::JSONReader::ReadAndReturnError( | 330 base::Value* value = base::JSONReader::ReadAndReturnError( |
326 json, base::JSON_PARSE_RFC, &error_code, &error); | 331 json, base::JSON_PARSE_RFC, &error_code, &error); |
327 if (value) { | 332 if (value) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 const std::string& mime_type, int64 total_size, bool get_attached_images) { | 394 const std::string& mime_type, int64 total_size, bool get_attached_images) { |
390 // Only one IPCDataSource may be created and added to the list of handlers. | 395 // Only one IPCDataSource may be created and added to the list of handlers. |
391 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); | 396 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); |
392 handlers_.push_back(source); | 397 handlers_.push_back(source); |
393 | 398 |
394 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( | 399 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( |
395 source, mime_type, get_attached_images); | 400 source, mime_type, get_attached_images); |
396 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); | 401 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); |
397 } | 402 } |
398 #endif | 403 #endif |
OLD | NEW |