| 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" |
| 16 #include "chrome/common/safe_browsing/zip_analyzer.h" | 17 #include "chrome/common/safe_browsing/zip_analyzer.h" |
| 17 #include "chrome/common/safe_browsing/zip_analyzer_results.h" | 18 #include "chrome/common/safe_browsing/zip_analyzer_results.h" |
| 18 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" | 19 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" |
| 19 #include "chrome/utility/utility_message_handler.h" | 20 #include "chrome/utility/utility_message_handler.h" |
| 20 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" | 21 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" |
| 21 #include "content/public/child/image_decoder_utils.h" | 22 #include "content/public/child/image_decoder_utils.h" |
| 22 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/common/service_info.h" | 24 #include "content/public/common/service_info.h" |
| 24 #include "content/public/utility/utility_thread.h" | 25 #include "content/public/utility/utility_thread.h" |
| 25 #include "courgette/courgette.h" | 26 #include "courgette/courgette.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 56 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) | 57 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) |
| 57 #include "chrome/utility/printing_handler.h" | 58 #include "chrome/utility/printing_handler.h" |
| 58 #endif | 59 #endif |
| 59 | 60 |
| 60 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) | 61 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) |
| 61 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" | 62 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" |
| 62 #endif | 63 #endif |
| 63 | 64 |
| 64 namespace { | 65 namespace { |
| 65 | 66 |
| 67 #if defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING) |
| 66 bool Send(IPC::Message* message) { | 68 bool Send(IPC::Message* message) { |
| 67 return content::UtilityThread::Get()->Send(message); | 69 return content::UtilityThread::Get()->Send(message); |
| 68 } | 70 } |
| 69 | 71 |
| 70 void ReleaseProcessIfNeeded() { | 72 void ReleaseProcessIfNeeded() { |
| 71 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 73 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 72 } | 74 } |
| 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 }; |
| 73 | 110 |
| 74 #if !defined(OS_ANDROID) | 111 #if !defined(OS_ANDROID) |
| 75 void CreateProxyResolverFactory( | 112 void CreateProxyResolverFactory( |
| 76 net::interfaces::ProxyResolverFactoryRequest request) { | 113 net::interfaces::ProxyResolverFactoryRequest request) { |
| 77 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(), | 114 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(), |
| 78 std::move(request)); | 115 std::move(request)); |
| 79 } | 116 } |
| 80 | 117 |
| 81 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter { | 118 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter { |
| 82 public: | 119 public: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 185 |
| 149 bool ChromeContentUtilityClient::OnMessageReceived( | 186 bool ChromeContentUtilityClient::OnMessageReceived( |
| 150 const IPC::Message& message) { | 187 const IPC::Message& message) { |
| 151 if (filter_messages_ && | 188 if (filter_messages_ && |
| 152 !base::ContainsKey(message_id_whitelist_, message.type())) { | 189 !base::ContainsKey(message_id_whitelist_, message.type())) { |
| 153 return false; | 190 return false; |
| 154 } | 191 } |
| 155 | 192 |
| 156 bool handled = true; | 193 bool handled = true; |
| 157 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 194 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
| 158 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileBsdiff, | |
| 159 OnPatchFileBsdiff) | |
| 160 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_PatchFileCourgette, | |
| 161 OnPatchFileCourgette) | |
| 162 #if defined(FULL_SAFE_BROWSING) | 195 #if defined(FULL_SAFE_BROWSING) |
| 163 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, | 196 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, |
| 164 OnAnalyzeZipFileForDownloadProtection) | 197 OnAnalyzeZipFileForDownloadProtection) |
| 165 #if defined(OS_MACOSX) | 198 #if defined(OS_MACOSX) |
| 166 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, | 199 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, |
| 167 OnAnalyzeDmgFileForDownloadProtection) | 200 OnAnalyzeDmgFileForDownloadProtection) |
| 168 #endif // defined(OS_MACOSX) | 201 #endif // defined(OS_MACOSX) |
| 169 #endif // defined(FULL_SAFE_BROWSING) | 202 #endif // defined(FULL_SAFE_BROWSING) |
| 170 #if defined(OS_CHROMEOS) | 203 #if defined(OS_CHROMEOS) |
| 171 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) | 204 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 193 service_manager::InterfaceRegistry* registry) { | 226 service_manager::InterfaceRegistry* registry) { |
| 194 // When the utility process is running with elevated privileges, we need to | 227 // When the utility process is running with elevated privileges, we need to |
| 195 // filter messages so that only a whitelist of IPCs can run. In Mojo, there's | 228 // filter messages so that only a whitelist of IPCs can run. In Mojo, there's |
| 196 // no way of filtering individual messages. Instead, we can avoid adding | 229 // no way of filtering individual messages. Instead, we can avoid adding |
| 197 // non-whitelisted Mojo services to the service_manager::InterfaceRegistry. | 230 // non-whitelisted Mojo services to the service_manager::InterfaceRegistry. |
| 198 // TODO(amistry): Use a whitelist once the whistlisted IPCs have been | 231 // TODO(amistry): Use a whitelist once the whistlisted IPCs have been |
| 199 // converted to Mojo. | 232 // converted to Mojo. |
| 200 if (filter_messages_) | 233 if (filter_messages_) |
| 201 return; | 234 return; |
| 202 | 235 |
| 236 registry->AddInterface(base::Bind(&FilePatcherImpl::Create)); |
| 203 #if !defined(OS_ANDROID) | 237 #if !defined(OS_ANDROID) |
| 204 registry->AddInterface<net::interfaces::ProxyResolverFactory>( | 238 registry->AddInterface<net::interfaces::ProxyResolverFactory>( |
| 205 base::Bind(CreateProxyResolverFactory)); | 239 base::Bind(CreateProxyResolverFactory)); |
| 206 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); | 240 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); |
| 207 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); | 241 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); |
| 208 #endif | 242 #endif |
| 209 registry->AddInterface( | 243 registry->AddInterface( |
| 210 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); | 244 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); |
| 211 #if defined(OS_WIN) | 245 #if defined(OS_WIN) |
| 212 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); | 246 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd); | 291 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd); |
| 258 | 292 |
| 259 if (succeeded) | 293 if (succeeded) |
| 260 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded()); | 294 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded()); |
| 261 else | 295 else |
| 262 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed()); | 296 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed()); |
| 263 ReleaseProcessIfNeeded(); | 297 ReleaseProcessIfNeeded(); |
| 264 } | 298 } |
| 265 #endif // defined(OS_CHROMEOS) | 299 #endif // defined(OS_CHROMEOS) |
| 266 | 300 |
| 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 | |
| 291 #if defined(FULL_SAFE_BROWSING) | 301 #if defined(FULL_SAFE_BROWSING) |
| 292 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( | 302 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( |
| 293 const IPC::PlatformFileForTransit& zip_file, | 303 const IPC::PlatformFileForTransit& zip_file, |
| 294 const IPC::PlatformFileForTransit& temp_file) { | 304 const IPC::PlatformFileForTransit& temp_file) { |
| 295 safe_browsing::zip_analyzer::Results results; | 305 safe_browsing::zip_analyzer::Results results; |
| 296 safe_browsing::zip_analyzer::AnalyzeZipFile( | 306 safe_browsing::zip_analyzer::AnalyzeZipFile( |
| 297 IPC::PlatformFileForTransitToFile(zip_file), | 307 IPC::PlatformFileForTransitToFile(zip_file), |
| 298 IPC::PlatformFileForTransitToFile(temp_file), &results); | 308 IPC::PlatformFileForTransitToFile(temp_file), &results); |
| 299 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( | 309 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( |
| 300 results)); | 310 results)); |
| 301 ReleaseProcessIfNeeded(); | 311 ReleaseProcessIfNeeded(); |
| 302 } | 312 } |
| 303 | 313 |
| 304 #if defined(OS_MACOSX) | 314 #if defined(OS_MACOSX) |
| 305 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection( | 315 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection( |
| 306 const IPC::PlatformFileForTransit& dmg_file) { | 316 const IPC::PlatformFileForTransit& dmg_file) { |
| 307 safe_browsing::zip_analyzer::Results results; | 317 safe_browsing::zip_analyzer::Results results; |
| 308 safe_browsing::dmg::AnalyzeDMGFile( | 318 safe_browsing::dmg::AnalyzeDMGFile( |
| 309 IPC::PlatformFileForTransitToFile(dmg_file), &results); | 319 IPC::PlatformFileForTransitToFile(dmg_file), &results); |
| 310 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( | 320 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( |
| 311 results)); | 321 results)); |
| 312 ReleaseProcessIfNeeded(); | 322 ReleaseProcessIfNeeded(); |
| 313 } | 323 } |
| 314 #endif // defined(OS_MACOSX) | 324 #endif // defined(OS_MACOSX) |
| 315 | 325 |
| 316 #endif // defined(FULL_SAFE_BROWSING) | 326 #endif // defined(FULL_SAFE_BROWSING) |
| OLD | NEW |