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 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/common/file_patcher.mojom.h" | 16 #include "chrome/common/file_patcher.mojom.h" |
17 #include "chrome/utility/utility_message_handler.h" | 17 #include "chrome/utility/utility_message_handler.h" |
18 #include "components/payments/content/utility/payment_manifest_parser.h" | 18 #include "components/payments/content/utility/payment_manifest_parser.h" |
19 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" | 19 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" |
20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
21 #include "content/public/common/service_info.h" | 21 #include "content/public/common/service_info.h" |
| 22 #include "content/public/common/service_manager_connection.h" |
| 23 #include "content/public/common/simple_connection_filter.h" |
22 #include "content/public/utility/utility_thread.h" | 24 #include "content/public/utility/utility_thread.h" |
23 #include "courgette/courgette.h" | 25 #include "courgette/courgette.h" |
24 #include "courgette/third_party/bsdiff/bsdiff.h" | 26 #include "courgette/third_party/bsdiff/bsdiff.h" |
25 #include "extensions/features/features.h" | 27 #include "extensions/features/features.h" |
26 #include "mojo/public/cpp/bindings/strong_binding.h" | 28 #include "mojo/public/cpp/bindings/strong_binding.h" |
27 #include "printing/features/features.h" | 29 #include "printing/features/features.h" |
28 #include "services/service_manager/public/cpp/interface_registry.h" | 30 #include "services/service_manager/public/cpp/binder_registry.h" |
29 #include "third_party/zlib/google/zip.h" | 31 #include "third_party/zlib/google/zip.h" |
30 | 32 |
31 #if !defined(OS_ANDROID) | 33 #if !defined(OS_ANDROID) |
32 #include "chrome/common/resource_usage_reporter.mojom.h" | 34 #include "chrome/common/resource_usage_reporter.mojom.h" |
33 #include "chrome/utility/media_router/dial_device_description_parser_impl.h" | 35 #include "chrome/utility/media_router/dial_device_description_parser_impl.h" |
34 #include "chrome/utility/profile_import_handler.h" | 36 #include "chrome/utility/profile_import_handler.h" |
35 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" | 37 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" |
36 #include "net/proxy/proxy_resolver_v8.h" | 38 #include "net/proxy/proxy_resolver_v8.h" |
37 #endif // !defined(OS_ANDROID) | 39 #endif // !defined(OS_ANDROID) |
38 | 40 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 ChromeContentUtilityClient::~ChromeContentUtilityClient() = default; | 239 ChromeContentUtilityClient::~ChromeContentUtilityClient() = default; |
238 | 240 |
239 void ChromeContentUtilityClient::UtilityThreadStarted() { | 241 void ChromeContentUtilityClient::UtilityThreadStarted() { |
240 #if BUILDFLAG(ENABLE_EXTENSIONS) | 242 #if BUILDFLAG(ENABLE_EXTENSIONS) |
241 extensions::utility_handler::UtilityThreadStarted(); | 243 extensions::utility_handler::UtilityThreadStarted(); |
242 #endif | 244 #endif |
243 | 245 |
244 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 246 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
245 if (command_line->HasSwitch(switches::kUtilityProcessRunningElevated)) | 247 if (command_line->HasSwitch(switches::kUtilityProcessRunningElevated)) |
246 utility_process_running_elevated_ = true; | 248 utility_process_running_elevated_ = true; |
| 249 |
| 250 auto registry = base::MakeUnique<service_manager::BinderRegistry>(); |
| 251 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 252 extensions::ExtensionsHandler::ExposeInterfacesToBrowser( |
| 253 registry.get(), utility_process_running_elevated_); |
| 254 extensions::utility_handler::ExposeInterfacesToBrowser( |
| 255 registry.get(), utility_process_running_elevated_); |
| 256 #endif |
| 257 // If our process runs with elevated privileges, only add elevated Mojo |
| 258 // interfaces to the interface registry. |
| 259 if (!utility_process_running_elevated_) { |
| 260 registry->AddInterface(base::Bind(&FilePatcherImpl::Create), |
| 261 base::ThreadTaskRunnerHandle::Get()); |
| 262 #if !defined(OS_ANDROID) |
| 263 registry->AddInterface<net::interfaces::ProxyResolverFactory>( |
| 264 base::Bind(CreateProxyResolverFactory), |
| 265 base::ThreadTaskRunnerHandle::Get()); |
| 266 registry->AddInterface(base::Bind(CreateResourceUsageReporter), |
| 267 base::ThreadTaskRunnerHandle::Get()); |
| 268 registry->AddInterface(base::Bind(&ProfileImportHandler::Create), |
| 269 base::ThreadTaskRunnerHandle::Get()); |
| 270 registry->AddInterface( |
| 271 base::Bind(&media_router::DialDeviceDescriptionParserImpl::Create), |
| 272 base::ThreadTaskRunnerHandle::Get()); |
| 273 #endif // !defined(OS_ANDROID) |
| 274 registry->AddInterface(base::Bind(&payments::PaymentManifestParser::Create), |
| 275 base::ThreadTaskRunnerHandle::Get()); |
| 276 registry->AddInterface( |
| 277 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create), |
| 278 base::ThreadTaskRunnerHandle::Get()); |
| 279 #if defined(OS_WIN) |
| 280 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create), |
| 281 base::ThreadTaskRunnerHandle::Get()); |
| 282 #endif |
| 283 #if defined(OS_CHROMEOS) |
| 284 registry->AddInterface(base::Bind(&ZipFileCreatorImpl::Create), |
| 285 base::ThreadTaskRunnerHandle::Get()); |
| 286 #endif |
| 287 #if defined(FULL_SAFE_BROWSING) |
| 288 registry->AddInterface(base::Bind(&SafeArchiveAnalyzerImpl::Create), |
| 289 base::ThreadTaskRunnerHandle::Get()); |
| 290 #endif |
| 291 } |
| 292 content::ChildThread::Get() |
| 293 ->GetServiceManagerConnection() |
| 294 ->AddConnectionFilter(base::MakeUnique<content::SimpleConnectionFilter>( |
| 295 std::move(registry))); |
247 } | 296 } |
248 | 297 |
249 bool ChromeContentUtilityClient::OnMessageReceived( | 298 bool ChromeContentUtilityClient::OnMessageReceived( |
250 const IPC::Message& message) { | 299 const IPC::Message& message) { |
251 if (utility_process_running_elevated_) | 300 if (utility_process_running_elevated_) |
252 return false; | 301 return false; |
253 | 302 |
254 for (const auto& handler : handlers_) { | 303 for (const auto& handler : handlers_) { |
255 if (handler->OnMessageReceived(message)) | 304 if (handler->OnMessageReceived(message)) |
256 return true; | 305 return true; |
257 } | 306 } |
258 | 307 |
259 return false; | 308 return false; |
260 } | 309 } |
261 | 310 |
262 void ChromeContentUtilityClient::ExposeInterfacesToBrowser( | |
263 service_manager::InterfaceRegistry* registry) { | |
264 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
265 extensions::ExtensionsHandler::ExposeInterfacesToBrowser( | |
266 registry, utility_process_running_elevated_); | |
267 extensions::utility_handler::ExposeInterfacesToBrowser( | |
268 registry, utility_process_running_elevated_); | |
269 #endif | |
270 // If our process runs with elevated privileges, only add elevated Mojo | |
271 // interfaces to the interface registry. | |
272 if (utility_process_running_elevated_) | |
273 return; | |
274 | |
275 registry->AddInterface(base::Bind(&FilePatcherImpl::Create)); | |
276 #if !defined(OS_ANDROID) | |
277 registry->AddInterface<net::interfaces::ProxyResolverFactory>( | |
278 base::Bind(CreateProxyResolverFactory)); | |
279 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); | |
280 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); | |
281 registry->AddInterface( | |
282 base::Bind(&media_router::DialDeviceDescriptionParserImpl::Create)); | |
283 #endif // !defined(OS_ANDROID) | |
284 registry->AddInterface(base::Bind(&payments::PaymentManifestParser::Create)); | |
285 registry->AddInterface( | |
286 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); | |
287 #if defined(OS_WIN) | |
288 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); | |
289 #endif | |
290 #if defined(OS_CHROMEOS) | |
291 registry->AddInterface(base::Bind(&ZipFileCreatorImpl::Create)); | |
292 #endif | |
293 #if defined(FULL_SAFE_BROWSING) | |
294 registry->AddInterface(base::Bind(&SafeArchiveAnalyzerImpl::Create)); | |
295 #endif | |
296 } | |
297 | |
298 // static | 311 // static |
299 void ChromeContentUtilityClient::PreSandboxStartup() { | 312 void ChromeContentUtilityClient::PreSandboxStartup() { |
300 #if BUILDFLAG(ENABLE_EXTENSIONS) | 313 #if BUILDFLAG(ENABLE_EXTENSIONS) |
301 extensions::ExtensionsHandler::PreSandboxStartup(); | 314 extensions::ExtensionsHandler::PreSandboxStartup(); |
302 #endif | 315 #endif |
303 } | 316 } |
OLD | NEW |