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/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/common/extensions/extension_l10n_util.h" | 21 #include "chrome/common/extensions/extension_l10n_util.h" |
22 #include "chrome/common/extensions/unpacker.h" | 22 #include "chrome/common/extensions/unpacker.h" |
23 #include "chrome/common/extensions/update_manifest.h" | 23 #include "chrome/common/extensions/update_manifest.h" |
24 #include "chrome/common/web_resource/web_resource_unpacker.h" | 24 #include "chrome/common/web_resource/web_resource_unpacker.h" |
25 #include "chrome/utility/profile_import_handler.h" | 25 #include "chrome/utility/profile_import_handler.h" |
26 #include "content/public/utility/utility_thread.h" | 26 #include "content/public/utility/utility_thread.h" |
27 #include "printing/backend/print_backend.h" | 27 #include "printing/backend/print_backend.h" |
28 #include "printing/page_range.h" | 28 #include "printing/page_range.h" |
29 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
30 #include "ui/base/ui_base_switches.h" | 30 #include "ui/base/ui_base_switches.h" |
| 31 #include "ui/gfx/codec/jpeg_codec.h" |
31 #include "ui/gfx/rect.h" | 32 #include "ui/gfx/rect.h" |
32 #include "webkit/glue/image_decoder.h" | 33 #include "webkit/glue/image_decoder.h" |
33 | 34 |
34 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
35 #include "base/file_util.h" | 36 #include "base/file_util.h" |
36 #include "base/path_service.h" | 37 #include "base/path_service.h" |
37 #include "base/win/iat_patch_function.h" | 38 #include "base/win/iat_patch_function.h" |
38 #include "base/win/scoped_handle.h" | 39 #include "base/win/scoped_handle.h" |
39 #include "content/public/common/content_switches.h" | 40 #include "content/public/common/content_switches.h" |
40 #include "printing/emf_win.h" | 41 #include "printing/emf_win.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 77 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
77 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) | 78 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) |
78 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource, | 79 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource, |
79 OnUnpackWebResource) | 80 OnUnpackWebResource) |
80 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, | 81 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, |
81 OnParseUpdateManifest) | 82 OnParseUpdateManifest) |
82 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) | 83 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) |
83 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) | 84 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) |
84 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, | 85 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, |
85 OnRenderPDFPagesToMetafile) | 86 OnRenderPDFPagesToMetafile) |
| 87 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, |
| 88 OnRobustJPEGDecodeImage) |
86 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) | 89 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) |
87 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, | 90 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, |
88 OnGetPrinterCapsAndDefaults) | 91 OnGetPrinterCapsAndDefaults) |
89 IPC_MESSAGE_UNHANDLED(handled = false) | 92 IPC_MESSAGE_UNHANDLED(handled = false) |
90 IPC_END_MESSAGE_MAP() | 93 IPC_END_MESSAGE_MAP() |
91 | 94 |
92 #if !defined(OS_ANDROID) | 95 #if !defined(OS_ANDROID) |
93 if (!handled) | 96 if (!handled) |
94 handled = import_handler_->OnMessageReceived(message); | 97 handled = import_handler_->OnMessageReceived(message); |
95 #endif | 98 #endif |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 *highest_rendered_page_number = page_number; | 353 *highest_rendered_page_number = page_number; |
351 ret = true; | 354 ret = true; |
352 metafile.FinishPage(); | 355 metafile.FinishPage(); |
353 } | 356 } |
354 } | 357 } |
355 metafile.FinishDocument(); | 358 metafile.FinishDocument(); |
356 return ret; | 359 return ret; |
357 } | 360 } |
358 #endif // defined(OS_WIN) | 361 #endif // defined(OS_WIN) |
359 | 362 |
| 363 void ChromeContentUtilityClient::OnRobustJPEGDecodeImage( |
| 364 const std::vector<unsigned char>& encoded_data) { |
| 365 scoped_ptr<SkBitmap> decoded_image(gfx::JPEGCodec::Decode( |
| 366 &encoded_data[0], encoded_data.size())); |
| 367 if (decoded_image->empty()) { |
| 368 Send(new ChromeUtilityHostMsg_DecodeImage_Failed()); |
| 369 } else { |
| 370 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image)); |
| 371 } |
| 372 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 373 } |
360 | 374 |
361 void ChromeContentUtilityClient::OnParseJSON(const std::string& json) { | 375 void ChromeContentUtilityClient::OnParseJSON(const std::string& json) { |
362 int error_code; | 376 int error_code; |
363 std::string error; | 377 std::string error; |
364 Value* value = base::JSONReader::ReadAndReturnError( | 378 Value* value = base::JSONReader::ReadAndReturnError( |
365 json, base::JSON_PARSE_RFC, &error_code, &error); | 379 json, base::JSON_PARSE_RFC, &error_code, &error); |
366 if (value) { | 380 if (value) { |
367 ListValue wrapper; | 381 ListValue wrapper; |
368 wrapper.Append(value); | 382 wrapper.Append(value); |
369 Send(new ChromeUtilityHostMsg_ParseJSON_Succeeded(wrapper)); | 383 Send(new ChromeUtilityHostMsg_ParseJSON_Succeeded(wrapper)); |
(...skipping 19 matching lines...) Expand all Loading... |
389 } else | 403 } else |
390 #endif | 404 #endif |
391 { | 405 { |
392 Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed( | 406 Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed( |
393 printer_name)); | 407 printer_name)); |
394 } | 408 } |
395 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 409 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
396 } | 410 } |
397 | 411 |
398 } // namespace chrome | 412 } // namespace chrome |
OLD | NEW |