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" |
| 15 #include "chrome/utility/safe_json_parser_handler.h" |
16 #include "chrome/utility/utility_message_handler.h" | 16 #include "chrome/utility/utility_message_handler.h" |
17 #include "content/public/child/image_decoder_utils.h" | 17 #include "content/public/child/image_decoder_utils.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 #include "content/public/common/service_registry.h" | 19 #include "content/public/common/service_registry.h" |
20 #include "content/public/utility/utility_thread.h" | 20 #include "content/public/utility/utility_thread.h" |
21 #include "courgette/courgette.h" | 21 #include "courgette/courgette.h" |
22 #include "courgette/third_party/bsdiff.h" | 22 #include "courgette/third_party/bsdiff.h" |
23 #include "ipc/ipc_channel.h" | 23 #include "ipc/ipc_channel.h" |
24 #include "skia/ext/image_operations.h" | 24 #include "skia/ext/image_operations.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 147 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
148 switches::kUtilityProcessEnableMDns)) { | 148 switches::kUtilityProcessEnableMDns)) { |
149 handlers_.push_back(new local_discovery::ServiceDiscoveryMessageHandler()); | 149 handlers_.push_back(new local_discovery::ServiceDiscoveryMessageHandler()); |
150 } | 150 } |
151 #endif | 151 #endif |
152 | 152 |
153 #if defined(OS_WIN) | 153 #if defined(OS_WIN) |
154 handlers_.push_back(new ShellHandler()); | 154 handlers_.push_back(new ShellHandler()); |
155 handlers_.push_back(new FontCacheHandler()); | 155 handlers_.push_back(new FontCacheHandler()); |
156 #endif | 156 #endif |
| 157 |
| 158 handlers_.push_back(new SafeJsonParserHandler()); |
157 } | 159 } |
158 | 160 |
159 ChromeContentUtilityClient::~ChromeContentUtilityClient() { | 161 ChromeContentUtilityClient::~ChromeContentUtilityClient() { |
160 } | 162 } |
161 | 163 |
162 void ChromeContentUtilityClient::UtilityThreadStarted() { | 164 void ChromeContentUtilityClient::UtilityThreadStarted() { |
163 #if defined(ENABLE_EXTENSIONS) | 165 #if defined(ENABLE_EXTENSIONS) |
164 extensions::UtilityHandler::UtilityThreadStarted(); | 166 extensions::UtilityHandler::UtilityThreadStarted(); |
165 #endif | 167 #endif |
166 | 168 |
(...skipping 12 matching lines...) Expand all Loading... |
179 if (filter_messages_ && !ContainsKey(message_id_whitelist_, message.type())) | 181 if (filter_messages_ && !ContainsKey(message_id_whitelist_, message.type())) |
180 return false; | 182 return false; |
181 | 183 |
182 bool handled = true; | 184 bool handled = true; |
183 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 185 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
184 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) | 186 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) |
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) | |
190 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, | 191 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, |
191 OnPatchFileBsdiff) | 192 OnPatchFileBsdiff) |
192 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, | 193 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, |
193 OnPatchFileCourgette) | 194 OnPatchFileCourgette) |
194 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) | 195 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing) |
195 #if defined(FULL_SAFE_BROWSING) | 196 #if defined(FULL_SAFE_BROWSING) |
196 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, | 197 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, |
197 OnAnalyzeZipFileForDownloadProtection) | 198 OnAnalyzeZipFileForDownloadProtection) |
198 #endif | 199 #endif |
199 #if defined(ENABLE_EXTENSIONS) | 200 #if defined(ENABLE_EXTENSIONS) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image, | 363 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image, |
363 request_id)); | 364 request_id)); |
364 } | 365 } |
365 } else { | 366 } else { |
366 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id)); | 367 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(request_id)); |
367 } | 368 } |
368 ReleaseProcessIfNeeded(); | 369 ReleaseProcessIfNeeded(); |
369 } | 370 } |
370 #endif // defined(OS_CHROMEOS) | 371 #endif // defined(OS_CHROMEOS) |
371 | 372 |
372 void ChromeContentUtilityClient::OnParseJSON(const std::string& json) { | |
373 int error_code; | |
374 std::string error; | |
375 scoped_ptr<base::Value> value = base::JSONReader::ReadAndReturnError( | |
376 json, base::JSON_PARSE_RFC, &error_code, &error); | |
377 if (value) { | |
378 base::ListValue wrapper; | |
379 wrapper.Append(value.Pass()); | |
380 Send(new ChromeUtilityHostMsg_ParseJSON_Succeeded(wrapper)); | |
381 } else { | |
382 Send(new ChromeUtilityHostMsg_ParseJSON_Failed(error)); | |
383 } | |
384 ReleaseProcessIfNeeded(); | |
385 } | |
386 | |
387 void ChromeContentUtilityClient::OnPatchFileBsdiff( | 373 void ChromeContentUtilityClient::OnPatchFileBsdiff( |
388 const base::FilePath& input_file, | 374 const base::FilePath& input_file, |
389 const base::FilePath& patch_file, | 375 const base::FilePath& patch_file, |
390 const base::FilePath& output_file) { | 376 const base::FilePath& output_file) { |
391 if (input_file.empty() || patch_file.empty() || output_file.empty()) { | 377 if (input_file.empty() || patch_file.empty() || output_file.empty()) { |
392 Send(new ChromeUtilityHostMsg_PatchFile_Finished(-1)); | 378 Send(new ChromeUtilityHostMsg_PatchFile_Finished(-1)); |
393 } else { | 379 } else { |
394 const int patch_status = courgette::ApplyBinaryPatch(input_file, | 380 const int patch_status = courgette::ApplyBinaryPatch(input_file, |
395 patch_file, | 381 patch_file, |
396 output_file); | 382 output_file); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 const std::string& mime_type, int64 total_size, bool get_attached_images) { | 427 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. | 428 // Only one IPCDataSource may be created and added to the list of handlers. |
443 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); | 429 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); |
444 handlers_.push_back(source); | 430 handlers_.push_back(source); |
445 | 431 |
446 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( | 432 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( |
447 source, mime_type, get_attached_images); | 433 source, mime_type, get_attached_images); |
448 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); | 434 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); |
449 } | 435 } |
450 #endif | 436 #endif |
OLD | NEW |