| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/common/chrome_utility_messages.h" | 15 #include "chrome/common/chrome_utility_messages.h" |
| 16 #include "chrome/common/file_patcher.mojom.h" | |
| 17 #include "chrome/common/safe_browsing/zip_analyzer.h" | 16 #include "chrome/common/safe_browsing/zip_analyzer.h" |
| 18 #include "chrome/common/safe_browsing/zip_analyzer_results.h" | 17 #include "chrome/common/safe_browsing/zip_analyzer_results.h" |
| 19 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" | 18 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" |
| 20 #include "chrome/utility/utility_message_handler.h" | 19 #include "chrome/utility/utility_message_handler.h" |
| 21 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" | 20 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" |
| 22 #include "content/public/child/image_decoder_utils.h" | 21 #include "content/public/child/image_decoder_utils.h" |
| 23 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 24 #include "content/public/common/service_info.h" | 23 #include "content/public/common/service_info.h" |
| 25 #include "content/public/utility/utility_thread.h" | 24 #include "content/public/utility/utility_thread.h" |
| 26 #include "courgette/courgette.h" | 25 #include "courgette/courgette.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 57 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) | 56 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) |
| 58 #include "chrome/utility/printing_handler.h" | 57 #include "chrome/utility/printing_handler.h" |
| 59 #endif | 58 #endif |
| 60 | 59 |
| 61 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) | 60 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) |
| 62 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" | 61 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" |
| 63 #endif | 62 #endif |
| 64 | 63 |
| 65 namespace { | 64 namespace { |
| 66 | 65 |
| 67 #if defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING) | |
| 68 bool Send(IPC::Message* message) { | 66 bool Send(IPC::Message* message) { |
| 69 return content::UtilityThread::Get()->Send(message); | 67 return content::UtilityThread::Get()->Send(message); |
| 70 } | 68 } |
| 71 | 69 |
| 72 void ReleaseProcessIfNeeded() { | 70 void ReleaseProcessIfNeeded() { |
| 73 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 71 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 74 } | 72 } |
| 75 #endif // defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING) | |
| 76 | |
| 77 class FilePatcherImpl : public chrome::mojom::FilePatcher { | |
| 78 public: | |
| 79 FilePatcherImpl() = default; | |
| 80 ~FilePatcherImpl() override = default; | |
| 81 | |
| 82 static void Create(chrome::mojom::FilePatcherRequest request) { | |
| 83 mojo::MakeStrongBinding(base::MakeUnique<FilePatcherImpl>(), | |
| 84 std::move(request)); | |
| 85 } | |
| 86 | |
| 87 private: | |
| 88 // chrome::mojom::FilePatcher: | |
| 89 | |
| 90 void PatchFileBsdiff(base::File input_file, | |
| 91 base::File patch_file, | |
| 92 base::File output_file, | |
| 93 const PatchFileBsdiffCallback& callback) override { | |
| 94 const int patch_result_status = bsdiff::ApplyBinaryPatch( | |
| 95 std::move(input_file), std::move(patch_file), std::move(output_file)); | |
| 96 callback.Run(patch_result_status); | |
| 97 } | |
| 98 | |
| 99 void PatchFileCourgette(base::File input_file, | |
| 100 base::File patch_file, | |
| 101 base::File output_file, | |
| 102 const PatchFileCourgetteCallback& callback) override { | |
| 103 const int patch_result_status = courgette::ApplyEnsemblePatch( | |
| 104 std::move(input_file), std::move(patch_file), std::move(output_file)); | |
| 105 callback.Run(patch_result_status); | |
| 106 } | |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(FilePatcherImpl); | |
| 109 }; | |
| 110 | 73 |
| 111 #if !defined(OS_ANDROID) | 74 #if !defined(OS_ANDROID) |
| 112 void CreateProxyResolverFactory( | 75 void CreateProxyResolverFactory( |
| 113 net::interfaces::ProxyResolverFactoryRequest request) { | 76 net::interfaces::ProxyResolverFactoryRequest request) { |
| 114 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(), | 77 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(), |
| 115 std::move(request)); | 78 std::move(request)); |
| 116 } | 79 } |
| 117 | 80 |
| 118 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter { | 81 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter { |
| 119 public: | 82 public: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 148 |
| 186 bool ChromeContentUtilityClient::OnMessageReceived( | 149 bool ChromeContentUtilityClient::OnMessageReceived( |
| 187 const IPC::Message& message) { | 150 const IPC::Message& message) { |
| 188 if (filter_messages_ && | 151 if (filter_messages_ && |
| 189 !base::ContainsKey(message_id_whitelist_, message.type())) { | 152 !base::ContainsKey(message_id_whitelist_, message.type())) { |
| 190 return false; | 153 return false; |
| 191 } | 154 } |
| 192 | 155 |
| 193 bool handled = true; | 156 bool handled = true; |
| 194 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 157 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
| 158 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, |
| 159 OnPatchFileBsdiff) |
| 160 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, |
| 161 OnPatchFileCourgette) |
| 195 #if defined(FULL_SAFE_BROWSING) | 162 #if defined(FULL_SAFE_BROWSING) |
| 196 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, | 163 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, |
| 197 OnAnalyzeZipFileForDownloadProtection) | 164 OnAnalyzeZipFileForDownloadProtection) |
| 198 #if defined(OS_MACOSX) | 165 #if defined(OS_MACOSX) |
| 199 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, | 166 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, |
| 200 OnAnalyzeDmgFileForDownloadProtection) | 167 OnAnalyzeDmgFileForDownloadProtection) |
| 201 #endif // defined(OS_MACOSX) | 168 #endif // defined(OS_MACOSX) |
| 202 #endif // defined(FULL_SAFE_BROWSING) | 169 #endif // defined(FULL_SAFE_BROWSING) |
| 203 #if defined(OS_CHROMEOS) | 170 #if defined(OS_CHROMEOS) |
| 204 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) | 171 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 226 service_manager::InterfaceRegistry* registry) { | 193 service_manager::InterfaceRegistry* registry) { |
| 227 // When the utility process is running with elevated privileges, we need to | 194 // When the utility process is running with elevated privileges, we need to |
| 228 // filter messages so that only a whitelist of IPCs can run. In Mojo, there's | 195 // filter messages so that only a whitelist of IPCs can run. In Mojo, there's |
| 229 // no way of filtering individual messages. Instead, we can avoid adding | 196 // no way of filtering individual messages. Instead, we can avoid adding |
| 230 // non-whitelisted Mojo services to the service_manager::InterfaceRegistry. | 197 // non-whitelisted Mojo services to the service_manager::InterfaceRegistry. |
| 231 // TODO(amistry): Use a whitelist once the whistlisted IPCs have been | 198 // TODO(amistry): Use a whitelist once the whistlisted IPCs have been |
| 232 // converted to Mojo. | 199 // converted to Mojo. |
| 233 if (filter_messages_) | 200 if (filter_messages_) |
| 234 return; | 201 return; |
| 235 | 202 |
| 236 registry->AddInterface(base::Bind(&FilePatcherImpl::Create)); | |
| 237 #if !defined(OS_ANDROID) | 203 #if !defined(OS_ANDROID) |
| 238 registry->AddInterface<net::interfaces::ProxyResolverFactory>( | 204 registry->AddInterface<net::interfaces::ProxyResolverFactory>( |
| 239 base::Bind(CreateProxyResolverFactory)); | 205 base::Bind(CreateProxyResolverFactory)); |
| 240 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); | 206 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); |
| 241 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); | 207 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); |
| 242 #endif | 208 #endif |
| 243 registry->AddInterface( | 209 registry->AddInterface( |
| 244 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); | 210 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); |
| 245 #if defined(OS_WIN) | 211 #if defined(OS_WIN) |
| 246 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); | 212 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd); | 257 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd); |
| 292 | 258 |
| 293 if (succeeded) | 259 if (succeeded) |
| 294 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded()); | 260 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded()); |
| 295 else | 261 else |
| 296 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed()); | 262 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed()); |
| 297 ReleaseProcessIfNeeded(); | 263 ReleaseProcessIfNeeded(); |
| 298 } | 264 } |
| 299 #endif // defined(OS_CHROMEOS) | 265 #endif // defined(OS_CHROMEOS) |
| 300 | 266 |
| 267 void ChromeContentUtilityClient::OnPatchFileBsdiff( |
| 268 const IPC::PlatformFileForTransit& input_file, |
| 269 const IPC::PlatformFileForTransit& patch_file, |
| 270 const IPC::PlatformFileForTransit& output_file) { |
| 271 const int patch_status = bsdiff::ApplyBinaryPatch( |
| 272 IPC::PlatformFileForTransitToFile(input_file), |
| 273 IPC::PlatformFileForTransitToFile(patch_file), |
| 274 IPC::PlatformFileForTransitToFile(output_file)); |
| 275 Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status)); |
| 276 ReleaseProcessIfNeeded(); |
| 277 } |
| 278 |
| 279 void ChromeContentUtilityClient::OnPatchFileCourgette( |
| 280 const IPC::PlatformFileForTransit& input_file, |
| 281 const IPC::PlatformFileForTransit& patch_file, |
| 282 const IPC::PlatformFileForTransit& output_file) { |
| 283 const int patch_status = courgette::ApplyEnsemblePatch( |
| 284 IPC::PlatformFileForTransitToFile(input_file), |
| 285 IPC::PlatformFileForTransitToFile(patch_file), |
| 286 IPC::PlatformFileForTransitToFile(output_file)); |
| 287 Send(new ChromeUtilityHostMsg_PatchFile_Finished(patch_status)); |
| 288 ReleaseProcessIfNeeded(); |
| 289 } |
| 290 |
| 301 #if defined(FULL_SAFE_BROWSING) | 291 #if defined(FULL_SAFE_BROWSING) |
| 302 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( | 292 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( |
| 303 const IPC::PlatformFileForTransit& zip_file, | 293 const IPC::PlatformFileForTransit& zip_file, |
| 304 const IPC::PlatformFileForTransit& temp_file) { | 294 const IPC::PlatformFileForTransit& temp_file) { |
| 305 safe_browsing::zip_analyzer::Results results; | 295 safe_browsing::zip_analyzer::Results results; |
| 306 safe_browsing::zip_analyzer::AnalyzeZipFile( | 296 safe_browsing::zip_analyzer::AnalyzeZipFile( |
| 307 IPC::PlatformFileForTransitToFile(zip_file), | 297 IPC::PlatformFileForTransitToFile(zip_file), |
| 308 IPC::PlatformFileForTransitToFile(temp_file), &results); | 298 IPC::PlatformFileForTransitToFile(temp_file), &results); |
| 309 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( | 299 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( |
| 310 results)); | 300 results)); |
| 311 ReleaseProcessIfNeeded(); | 301 ReleaseProcessIfNeeded(); |
| 312 } | 302 } |
| 313 | 303 |
| 314 #if defined(OS_MACOSX) | 304 #if defined(OS_MACOSX) |
| 315 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection( | 305 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection( |
| 316 const IPC::PlatformFileForTransit& dmg_file) { | 306 const IPC::PlatformFileForTransit& dmg_file) { |
| 317 safe_browsing::zip_analyzer::Results results; | 307 safe_browsing::zip_analyzer::Results results; |
| 318 safe_browsing::dmg::AnalyzeDMGFile( | 308 safe_browsing::dmg::AnalyzeDMGFile( |
| 319 IPC::PlatformFileForTransitToFile(dmg_file), &results); | 309 IPC::PlatformFileForTransitToFile(dmg_file), &results); |
| 320 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( | 310 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( |
| 321 results)); | 311 results)); |
| 322 ReleaseProcessIfNeeded(); | 312 ReleaseProcessIfNeeded(); |
| 323 } | 313 } |
| 324 #endif // defined(OS_MACOSX) | 314 #endif // defined(OS_MACOSX) |
| 325 | 315 |
| 326 #endif // defined(FULL_SAFE_BROWSING) | 316 #endif // defined(FULL_SAFE_BROWSING) |
| OLD | NEW |