| 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" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 #if defined(OS_CHROMEOS) | 203 #if defined(OS_CHROMEOS) |
| 204 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) | 204 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile) |
| 205 #endif | 205 #endif |
| 206 IPC_MESSAGE_UNHANDLED(handled = false) | 206 IPC_MESSAGE_UNHANDLED(handled = false) |
| 207 IPC_END_MESSAGE_MAP() | 207 IPC_END_MESSAGE_MAP() |
| 208 | 208 |
| 209 if (handled) | 209 if (handled) |
| 210 return true; | 210 return true; |
| 211 | 211 |
| 212 for (auto* handler : handlers_) { | 212 for (auto* handler : handlers_) { |
| 213 // At least one of the utility process handlers adds a new handler to | |
| 214 // |handlers_| when it handles a message. This causes any iterator over | |
| 215 // |handlers_| to become invalid. Therefore, it is necessary to break the | |
| 216 // loop at this point instead of evaluating it as a loop condition (if the | |
| 217 // for loop was using iterators explicitly, as originally done). | |
| 218 if (handler->OnMessageReceived(message)) | 213 if (handler->OnMessageReceived(message)) |
| 219 return true; | 214 return true; |
| 220 } | 215 } |
| 221 | 216 |
| 222 return false; | 217 return false; |
| 223 } | 218 } |
| 224 | 219 |
| 225 void ChromeContentUtilityClient::ExposeInterfacesToBrowser( | 220 void ChromeContentUtilityClient::ExposeInterfacesToBrowser( |
| 226 service_manager::InterfaceRegistry* registry) { | 221 service_manager::InterfaceRegistry* registry) { |
| 227 const bool running_elevated = | 222 const bool utility_process_running_elevated = |
| 228 base::CommandLine::ForCurrentProcess()->HasSwitch( | 223 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 229 switches::kUtilityProcessRunningElevated); | 224 switches::kUtilityProcessRunningElevated); |
| 230 #if BUILDFLAG(ENABLE_EXTENSIONS) | 225 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 231 ChromeContentUtilityClient* utility_client = this; | |
| 232 extensions::ExtensionsHandler::ExposeInterfacesToBrowser( | 226 extensions::ExtensionsHandler::ExposeInterfacesToBrowser( |
| 233 registry, utility_client, running_elevated); | 227 registry, utility_process_running_elevated); |
| 234 #endif | 228 #endif |
| 235 // If our process runs with elevated privileges, only add elevated Mojo | 229 // If our process runs with elevated privileges, only add elevated Mojo |
| 236 // services to the interface registry. | 230 // services to the interface registry. |
| 237 if (running_elevated) | 231 if (utility_process_running_elevated) |
| 238 return; | 232 return; |
| 239 | 233 |
| 240 registry->AddInterface(base::Bind(&FilePatcherImpl::Create)); | 234 registry->AddInterface(base::Bind(&FilePatcherImpl::Create)); |
| 241 #if !defined(OS_ANDROID) | 235 #if !defined(OS_ANDROID) |
| 242 registry->AddInterface<net::interfaces::ProxyResolverFactory>( | 236 registry->AddInterface<net::interfaces::ProxyResolverFactory>( |
| 243 base::Bind(CreateProxyResolverFactory)); | 237 base::Bind(CreateProxyResolverFactory)); |
| 244 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); | 238 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); |
| 245 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); | 239 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); |
| 246 #endif | 240 #endif |
| 247 registry->AddInterface( | 241 registry->AddInterface( |
| 248 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); | 242 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); |
| 249 #if defined(OS_WIN) | 243 #if defined(OS_WIN) |
| 250 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); | 244 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); |
| 251 #endif | 245 #endif |
| 252 } | 246 } |
| 253 | 247 |
| 254 void ChromeContentUtilityClient::RegisterServices(StaticServiceMap* services) { | 248 void ChromeContentUtilityClient::RegisterServices(StaticServiceMap* services) { |
| 255 content::ServiceInfo image_decoder_info; | 249 content::ServiceInfo image_decoder_info; |
| 256 image_decoder_info.factory = base::Bind(&CreateImageDecoderService); | 250 image_decoder_info.factory = base::Bind(&CreateImageDecoderService); |
| 257 services->insert( | 251 services->insert( |
| 258 std::make_pair(image_decoder::mojom::kServiceName, image_decoder_info)); | 252 std::make_pair(image_decoder::mojom::kServiceName, image_decoder_info)); |
| 259 } | 253 } |
| 260 | 254 |
| 261 void ChromeContentUtilityClient::AddHandler( | |
| 262 std::unique_ptr<UtilityMessageHandler> handler) { | |
| 263 handlers_.push_back(std::move(handler)); | |
| 264 } | |
| 265 | |
| 266 // static | 255 // static |
| 267 void ChromeContentUtilityClient::PreSandboxStartup() { | 256 void ChromeContentUtilityClient::PreSandboxStartup() { |
| 268 #if BUILDFLAG(ENABLE_EXTENSIONS) | 257 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 269 extensions::ExtensionsHandler::PreSandboxStartup(); | 258 extensions::ExtensionsHandler::PreSandboxStartup(); |
| 270 #endif | 259 #endif |
| 271 } | 260 } |
| 272 | 261 |
| 273 #if defined(OS_CHROMEOS) | 262 #if defined(OS_CHROMEOS) |
| 274 void ChromeContentUtilityClient::OnCreateZipFile( | 263 void ChromeContentUtilityClient::OnCreateZipFile( |
| 275 const base::FilePath& src_dir, | 264 const base::FilePath& src_dir, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 safe_browsing::zip_analyzer::Results results; | 310 safe_browsing::zip_analyzer::Results results; |
| 322 safe_browsing::dmg::AnalyzeDMGFile( | 311 safe_browsing::dmg::AnalyzeDMGFile( |
| 323 IPC::PlatformFileForTransitToFile(dmg_file), &results); | 312 IPC::PlatformFileForTransitToFile(dmg_file), &results); |
| 324 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( | 313 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( |
| 325 results)); | 314 results)); |
| 326 ReleaseProcessIfNeeded(); | 315 ReleaseProcessIfNeeded(); |
| 327 } | 316 } |
| 328 #endif // defined(OS_MACOSX) | 317 #endif // defined(OS_MACOSX) |
| 329 | 318 |
| 330 #endif // defined(FULL_SAFE_BROWSING) | 319 #endif // defined(FULL_SAFE_BROWSING) |
| OLD | NEW |