Chromium Code Reviews| 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" | |
| 10 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 11 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 12 #include "chrome/common/chrome_utility_messages.h" | 11 #include "chrome/common/chrome_utility_messages.h" |
| 13 #include "chrome/common/safe_browsing/zip_analyzer.h" | 12 #include "chrome/common/safe_browsing/zip_analyzer.h" |
| 14 #include "chrome/common/safe_browsing/zip_analyzer_results.h" | 13 #include "chrome/common/safe_browsing/zip_analyzer_results.h" |
| 15 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" | 14 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" |
| 16 #include "chrome/utility/utility_message_handler.h" | 15 #include "chrome/utility/utility_message_handler.h" |
| 17 #include "content/public/child/image_decoder_utils.h" | 16 #include "content/public/child/image_decoder_utils.h" |
| 18 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 19 #include "content/public/common/service_registry.h" | 18 #include "content/public/common/service_registry.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 #endif | 52 #endif |
| 54 | 53 |
| 55 #if defined(ENABLE_PRINT_PREVIEW) || defined(OS_WIN) | 54 #if defined(ENABLE_PRINT_PREVIEW) || defined(OS_WIN) |
| 56 #include "chrome/utility/printing_handler.h" | 55 #include "chrome/utility/printing_handler.h" |
| 57 #endif | 56 #endif |
| 58 | 57 |
| 59 #if defined(ENABLE_MDNS) | 58 #if defined(ENABLE_MDNS) |
| 60 #include "chrome/utility/local_discovery/service_discovery_message_handler.h" | 59 #include "chrome/utility/local_discovery/service_discovery_message_handler.h" |
| 61 #endif | 60 #endif |
| 62 | 61 |
| 62 #include "chrome/utility/safe_json_parser_handler.h" | |
|
Robert Sesek
2015/05/14 20:12:33
Put this in the proper #includes block.
Eran Messeri
2015/05/15 12:52:40
Done.
| |
| 63 | |
| 63 namespace { | 64 namespace { |
| 64 | 65 |
| 65 bool Send(IPC::Message* message) { | 66 bool Send(IPC::Message* message) { |
| 66 return content::UtilityThread::Get()->Send(message); | 67 return content::UtilityThread::Get()->Send(message); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void ReleaseProcessIfNeeded() { | 70 void ReleaseProcessIfNeeded() { |
| 70 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 71 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 71 } | 72 } |
| 72 | 73 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 117 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 117 switches::kUtilityProcessEnableMDns)) { | 118 switches::kUtilityProcessEnableMDns)) { |
| 118 handlers_.push_back(new local_discovery::ServiceDiscoveryMessageHandler()); | 119 handlers_.push_back(new local_discovery::ServiceDiscoveryMessageHandler()); |
| 119 } | 120 } |
| 120 #endif | 121 #endif |
| 121 | 122 |
| 122 #if defined(OS_WIN) | 123 #if defined(OS_WIN) |
| 123 handlers_.push_back(new ShellHandler()); | 124 handlers_.push_back(new ShellHandler()); |
| 124 handlers_.push_back(new FontCacheHandler()); | 125 handlers_.push_back(new FontCacheHandler()); |
| 125 #endif | 126 #endif |
| 127 | |
| 128 handlers_.push_back(new SafeJsonParserHandler()); | |
| 126 } | 129 } |
| 127 | 130 |
| 128 ChromeContentUtilityClient::~ChromeContentUtilityClient() { | 131 ChromeContentUtilityClient::~ChromeContentUtilityClient() { |
| 129 } | 132 } |
| 130 | 133 |
| 131 void ChromeContentUtilityClient::UtilityThreadStarted() { | 134 void ChromeContentUtilityClient::UtilityThreadStarted() { |
| 132 #if defined(ENABLE_EXTENSIONS) | 135 #if defined(ENABLE_EXTENSIONS) |
| 133 extensions::UtilityHandler::UtilityThreadStarted(); | 136 extensions::UtilityHandler::UtilityThreadStarted(); |
| 134 #endif | 137 #endif |
| 135 | 138 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 148 if (filter_messages_ && !ContainsKey(message_id_whitelist_, message.type())) | 151 if (filter_messages_ && !ContainsKey(message_id_whitelist_, message.type())) |
| 149 return false; | 152 return false; |
| 150 | 153 |
| 151 bool handled = true; | 154 bool handled = true; |
| 152 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 155 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
| 153 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) | 156 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) |
| 154 #if defined(OS_CHROMEOS) | 157 #if defined(OS_CHROMEOS) |
| 155 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, | 158 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RobustJPEGDecodeImage, |
| 156 OnRobustJPEGDecodeImage) | 159 OnRobustJPEGDecodeImage) |
| 157 #endif // defined(OS_CHROMEOS) | 160 #endif // defined(OS_CHROMEOS) |
| 158 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) | |
| 159 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, | 161 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, |
| 160 OnPatchFileBsdiff) | 162 OnPatchFileBsdiff) |
| 161 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, | 163 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, |
| 162 OnPatchFileCourgette) | 164 OnPatchFileCourgette) |
| 163 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) | 165 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) |
| 164 #if defined(FULL_SAFE_BROWSING) | 166 #if defined(FULL_SAFE_BROWSING) |
| 165 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, | 167 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, |
| 166 OnAnalyzeZipFileForDownloadProtection) | 168 OnAnalyzeZipFileForDownloadProtection) |
| 167 #endif | 169 #endif |
| 168 #if defined(ENABLE_EXTENSIONS) | 170 #if defined(ENABLE_EXTENSIONS) |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image, | 331 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image, |
| 330 request_id)); | 332 request_id)); |
| 331 } | 333 } |
| 332 } else { | 334 } else { |
| 333 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id)); | 335 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id)); |
| 334 } | 336 } |
| 335 ReleaseProcessIfNeeded(); | 337 ReleaseProcessIfNeeded(); |
| 336 } | 338 } |
| 337 #endif // defined(OS_CHROMEOS) | 339 #endif // defined(OS_CHROMEOS) |
| 338 | 340 |
| 339 void ChromeContentUtilityClient::OnParseJSON(const std::string& json) { | |
| 340 int error_code; | |
| 341 std::string error; | |
| 342 base::Value* value = base::JSONReader::ReadAndReturnError( | |
| 343 json, base::JSON_PARSE_RFC, &error_code, &error); | |
| 344 if (value) { | |
| 345 base::ListValue wrapper; | |
| 346 wrapper.Append(value); | |
| 347 Send(new ChromeUtilityHostMsg_ParseJSON_Succeeded(wrapper)); | |
| 348 } else { | |
| 349 Send(new ChromeUtilityHostMsg_ParseJSON_Failed(error)); | |
| 350 } | |
| 351 ReleaseProcessIfNeeded(); | |
| 352 } | |
| 353 | |
| 354 void ChromeContentUtilityClient::OnPatchFileBsdiff( | 341 void ChromeContentUtilityClient::OnPatchFileBsdiff( |
| 355 const base::FilePath& input_file, | 342 const base::FilePath& input_file, |
| 356 const base::FilePath& patch_file, | 343 const base::FilePath& patch_file, |
| 357 const base::FilePath& output_file) { | 344 const base::FilePath& output_file) { |
| 358 if (input_file.empty() || patch_file.empty() || output_file.empty()) { | 345 if (input_file.empty() || patch_file.empty() || output_file.empty()) { |
| 359 Send(new ChromeUtilityHostMsg_PatchFile_Finished(-1)); | 346 Send(new ChromeUtilityHostMsg_PatchFile_Finished(-1)); |
| 360 } else { | 347 } else { |
| 361 const int patch_status = courgette::ApplyBinaryPatch(input_file, | 348 const int patch_status = courgette::ApplyBinaryPatch(input_file, |
| 362 patch_file, | 349 patch_file, |
| 363 output_file); | 350 output_file); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 const std::string& mime_type, int64 total_size, bool get_attached_images) { | 395 const std::string& mime_type, int64 total_size, bool get_attached_images) { |
| 409 // Only one IPCDataSource may be created and added to the list of handlers. | 396 // Only one IPCDataSource may be created and added to the list of handlers. |
| 410 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); | 397 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); |
| 411 handlers_.push_back(source); | 398 handlers_.push_back(source); |
| 412 | 399 |
| 413 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( | 400 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( |
| 414 source, mime_type, get_attached_images); | 401 source, mime_type, get_attached_images); |
| 415 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); | 402 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); |
| 416 } | 403 } |
| 417 #endif | 404 #endif |
| OLD | NEW |