| 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/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/common/chrome_utility_messages.h" | 16 #include "chrome/common/chrome_utility_messages.h" |
| 17 #include "chrome/common/file_patcher.mojom.h" | 17 #include "chrome/common/file_patcher.mojom.h" |
| 18 #include "chrome/common/safe_browsing/zip_analyzer.h" | 18 #include "chrome/common/safe_browsing/zip_analyzer.h" |
| 19 #include "chrome/common/safe_browsing/zip_analyzer_results.h" | 19 #include "chrome/common/safe_browsing/zip_analyzer_results.h" |
| 20 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" | |
| 21 #include "chrome/utility/utility_message_handler.h" | 20 #include "chrome/utility/utility_message_handler.h" |
| 22 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" | 21 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" |
| 23 #include "content/public/child/image_decoder_utils.h" | 22 #include "content/public/child/image_decoder_utils.h" |
| 24 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/common/service_info.h" | 24 #include "content/public/common/service_info.h" |
| 26 #include "content/public/utility/utility_thread.h" | 25 #include "content/public/utility/utility_thread.h" |
| 27 #include "courgette/courgette.h" | 26 #include "courgette/courgette.h" |
| 28 #include "courgette/third_party/bsdiff/bsdiff.h" | 27 #include "courgette/third_party/bsdiff/bsdiff.h" |
| 29 #include "extensions/features/features.h" | 28 #include "extensions/features/features.h" |
| 30 #include "ipc/ipc_channel.h" | 29 #include "ipc/ipc_channel.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 #include "net/proxy/proxy_resolver_v8.h" | 43 #include "net/proxy/proxy_resolver_v8.h" |
| 45 #endif | 44 #endif |
| 46 | 45 |
| 47 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
| 48 #include "chrome/utility/ipc_shell_handler_win.h" | 47 #include "chrome/utility/ipc_shell_handler_win.h" |
| 49 #include "chrome/utility/shell_handler_impl_win.h" | 48 #include "chrome/utility/shell_handler_impl_win.h" |
| 50 #endif | 49 #endif |
| 51 | 50 |
| 52 #if BUILDFLAG(ENABLE_EXTENSIONS) | 51 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 53 #include "chrome/utility/extensions/extensions_handler.h" | 52 #include "chrome/utility/extensions/extensions_handler.h" |
| 54 #include "chrome/utility/image_writer/image_writer_handler.h" | |
| 55 #endif | 53 #endif |
| 56 | 54 |
| 57 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \ | 55 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \ |
| 58 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) | 56 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) |
| 59 #include "chrome/utility/printing_handler.h" | 57 #include "chrome/utility/printing_handler.h" |
| 60 #endif | 58 #endif |
| 61 | 59 |
| 62 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) | 60 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) |
| 63 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" | 61 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" |
| 64 #endif | 62 #endif |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 #endif // !defined(OS_ANDROID) | 140 #endif // !defined(OS_ANDROID) |
| 143 | 141 |
| 144 std::unique_ptr<service_manager::Service> CreateImageDecoderService() { | 142 std::unique_ptr<service_manager::Service> CreateImageDecoderService() { |
| 145 content::UtilityThread::Get()->EnsureBlinkInitialized(); | 143 content::UtilityThread::Get()->EnsureBlinkInitialized(); |
| 146 return image_decoder::ImageDecoderService::Create(); | 144 return image_decoder::ImageDecoderService::Create(); |
| 147 } | 145 } |
| 148 | 146 |
| 149 } // namespace | 147 } // namespace |
| 150 | 148 |
| 151 ChromeContentUtilityClient::ChromeContentUtilityClient() | 149 ChromeContentUtilityClient::ChromeContentUtilityClient() |
| 152 : filter_messages_(false) { | 150 : utility_process_running_elevated_(false) { |
| 153 #if BUILDFLAG(ENABLE_EXTENSIONS) | 151 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 154 handlers_.push_back(new extensions::ExtensionsHandler()); | 152 handlers_.push_back(new extensions::ExtensionsHandler()); |
| 155 handlers_.push_back(new image_writer::ImageWriterHandler()); | |
| 156 #endif | 153 #endif |
| 157 | 154 |
| 158 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \ | 155 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \ |
| 159 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) | 156 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) |
| 160 handlers_.push_back(new printing::PrintingHandler()); | 157 handlers_.push_back(new printing::PrintingHandler()); |
| 161 #endif | 158 #endif |
| 162 | 159 |
| 163 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
| 164 handlers_.push_back(new IPCShellHandler()); | 161 handlers_.push_back(new IPCShellHandler()); |
| 165 #endif | 162 #endif |
| 166 } | 163 } |
| 167 | 164 |
| 168 ChromeContentUtilityClient::~ChromeContentUtilityClient() { | 165 ChromeContentUtilityClient::~ChromeContentUtilityClient() = default; |
| 169 } | |
| 170 | 166 |
| 171 void ChromeContentUtilityClient::UtilityThreadStarted() { | 167 void ChromeContentUtilityClient::UtilityThreadStarted() { |
| 172 #if BUILDFLAG(ENABLE_EXTENSIONS) | 168 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 173 extensions::UtilityHandler::UtilityThreadStarted(); | 169 extensions::UtilityHandler::UtilityThreadStarted(); |
| 174 #endif | 170 #endif |
| 175 | 171 |
| 176 if (kMessageWhitelistSize > 0) { | 172 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 177 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 173 if (command_line->HasSwitch(switches::kUtilityProcessRunningElevated)) |
| 178 if (command_line->HasSwitch(switches::kUtilityProcessRunningElevated)) { | 174 utility_process_running_elevated_ = true; |
| 179 message_id_whitelist_.insert(kMessageWhitelist, | |
| 180 kMessageWhitelist + kMessageWhitelistSize); | |
| 181 filter_messages_ = true; | |
| 182 } | |
| 183 } | |
| 184 } | 175 } |
| 185 | 176 |
| 186 bool ChromeContentUtilityClient::OnMessageReceived( | 177 bool ChromeContentUtilityClient::OnMessageReceived( |
| 187 const IPC::Message& message) { | 178 const IPC::Message& message) { |
| 188 if (filter_messages_ && | 179 if (utility_process_running_elevated_) |
| 189 !base::ContainsKey(message_id_whitelist_, message.type())) { | |
| 190 return false; | 180 return false; |
| 191 } | |
| 192 | 181 |
| 193 bool handled = true; | 182 bool handled = true; |
| 194 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 183 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
| 195 #if defined(FULL_SAFE_BROWSING) | 184 #if defined(FULL_SAFE_BROWSING) |
| 196 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, | 185 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, |
| 197 OnAnalyzeZipFileForDownloadProtection) | 186 OnAnalyzeZipFileForDownloadProtection) |
| 198 #if defined(OS_MACOSX) | 187 #if defined(OS_MACOSX) |
| 199 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, | 188 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, |
| 200 OnAnalyzeDmgFileForDownloadProtection) | 189 OnAnalyzeDmgFileForDownloadProtection) |
| 201 #endif // defined(OS_MACOSX) | 190 #endif // defined(OS_MACOSX) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 217 // for loop was using iterators explicitly, as originally done). | 206 // for loop was using iterators explicitly, as originally done). |
| 218 if (handler->OnMessageReceived(message)) | 207 if (handler->OnMessageReceived(message)) |
| 219 return true; | 208 return true; |
| 220 } | 209 } |
| 221 | 210 |
| 222 return false; | 211 return false; |
| 223 } | 212 } |
| 224 | 213 |
| 225 void ChromeContentUtilityClient::ExposeInterfacesToBrowser( | 214 void ChromeContentUtilityClient::ExposeInterfacesToBrowser( |
| 226 service_manager::InterfaceRegistry* registry) { | 215 service_manager::InterfaceRegistry* registry) { |
| 227 const bool running_elevated = | |
| 228 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 229 switches::kUtilityProcessRunningElevated); | |
| 230 #if BUILDFLAG(ENABLE_EXTENSIONS) | 216 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 231 ChromeContentUtilityClient* utility_client = this; | 217 ChromeContentUtilityClient* utility_client = this; |
| 232 extensions::ExtensionsHandler::ExposeInterfacesToBrowser( | 218 extensions::ExtensionsHandler::ExposeInterfacesToBrowser( |
| 233 registry, utility_client, running_elevated); | 219 registry, utility_client, utility_process_running_elevated_); |
| 234 #endif | 220 #endif |
| 235 // If our process runs with elevated privileges, only add elevated Mojo | 221 // If our process runs with elevated privileges, only add elevated Mojo |
| 236 // services to the interface registry. | 222 // services to the interface registry. |
| 237 if (running_elevated) | 223 if (utility_process_running_elevated_) |
| 238 return; | 224 return; |
| 239 | 225 |
| 240 registry->AddInterface(base::Bind(&FilePatcherImpl::Create)); | 226 registry->AddInterface(base::Bind(&FilePatcherImpl::Create)); |
| 241 #if !defined(OS_ANDROID) | 227 #if !defined(OS_ANDROID) |
| 242 registry->AddInterface<net::interfaces::ProxyResolverFactory>( | 228 registry->AddInterface<net::interfaces::ProxyResolverFactory>( |
| 243 base::Bind(CreateProxyResolverFactory)); | 229 base::Bind(CreateProxyResolverFactory)); |
| 244 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); | 230 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); |
| 245 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); | 231 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); |
| 246 #endif | 232 #endif |
| 247 registry->AddInterface( | 233 registry->AddInterface( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 safe_browsing::zip_analyzer::Results results; | 307 safe_browsing::zip_analyzer::Results results; |
| 322 safe_browsing::dmg::AnalyzeDMGFile( | 308 safe_browsing::dmg::AnalyzeDMGFile( |
| 323 IPC::PlatformFileForTransitToFile(dmg_file), &results); | 309 IPC::PlatformFileForTransitToFile(dmg_file), &results); |
| 324 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( | 310 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( |
| 325 results)); | 311 results)); |
| 326 ReleaseProcessIfNeeded(); | 312 ReleaseProcessIfNeeded(); |
| 327 } | 313 } |
| 328 #endif // defined(OS_MACOSX) | 314 #endif // defined(OS_MACOSX) |
| 329 | 315 |
| 330 #endif // defined(FULL_SAFE_BROWSING) | 316 #endif // defined(FULL_SAFE_BROWSING) |
| OLD | NEW |