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 "build/build_config.h" | |
17 #include "chrome/common/chrome_utility_messages.h" | |
18 #include "chrome/common/file_patcher.mojom.h" | 16 #include "chrome/common/file_patcher.mojom.h" |
19 #include "chrome/common/safe_browsing/zip_analyzer.h" | |
20 #include "chrome/common/safe_browsing/zip_analyzer_results.h" | |
21 #include "chrome/utility/utility_message_handler.h" | 17 #include "chrome/utility/utility_message_handler.h" |
22 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" | 18 #include "components/safe_json/utility/safe_json_parser_mojo_impl.h" |
23 #include "content/public/child/image_decoder_utils.h" | 19 #include "content/public/child/image_decoder_utils.h" |
24 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
25 #include "content/public/common/service_info.h" | 21 #include "content/public/common/service_info.h" |
26 #include "content/public/utility/utility_thread.h" | 22 #include "content/public/utility/utility_thread.h" |
27 #include "courgette/courgette.h" | 23 #include "courgette/courgette.h" |
28 #include "courgette/third_party/bsdiff/bsdiff.h" | 24 #include "courgette/third_party/bsdiff/bsdiff.h" |
29 #include "extensions/features/features.h" | 25 #include "extensions/features/features.h" |
30 #include "ipc/ipc_channel.h" | |
31 #include "mojo/public/cpp/bindings/strong_binding.h" | 26 #include "mojo/public/cpp/bindings/strong_binding.h" |
32 #include "printing/features/features.h" | 27 #include "printing/features/features.h" |
33 #include "services/image_decoder/image_decoder_service.h" | 28 #include "services/image_decoder/image_decoder_service.h" |
34 #include "services/image_decoder/public/interfaces/constants.mojom.h" | 29 #include "services/image_decoder/public/interfaces/constants.mojom.h" |
35 #include "services/service_manager/public/cpp/interface_registry.h" | 30 #include "services/service_manager/public/cpp/interface_registry.h" |
36 #include "third_party/zlib/google/zip.h" | 31 #include "third_party/zlib/google/zip.h" |
37 #include "ui/gfx/geometry/size.h" | |
38 | 32 |
39 #if !defined(OS_ANDROID) | 33 #if !defined(OS_ANDROID) |
40 #include "chrome/common/resource_usage_reporter.mojom.h" | 34 #include "chrome/common/resource_usage_reporter.mojom.h" |
41 #include "chrome/utility/profile_import_handler.h" | 35 #include "chrome/utility/profile_import_handler.h" |
42 #include "mojo/public/cpp/bindings/strong_binding.h" | 36 #include "mojo/public/cpp/bindings/strong_binding.h" |
43 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" | 37 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" |
44 #include "net/proxy/proxy_resolver_v8.h" | 38 #include "net/proxy/proxy_resolver_v8.h" |
45 #endif | 39 #endif |
46 | 40 |
47 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
48 #include "chrome/common/zip_file_creator.mojom.h" | 42 #include "chrome/common/zip_file_creator.mojom.h" |
49 #endif | 43 #endif |
50 | 44 |
51 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
52 #include "chrome/utility/ipc_shell_handler_win.h" | 46 #include "chrome/utility/ipc_shell_handler_win.h" |
53 #include "chrome/utility/shell_handler_impl_win.h" | 47 #include "chrome/utility/shell_handler_impl_win.h" |
54 #endif | 48 #endif |
55 | 49 |
56 #if BUILDFLAG(ENABLE_EXTENSIONS) | 50 #if BUILDFLAG(ENABLE_EXTENSIONS) |
57 #include "chrome/utility/extensions/extensions_handler.h" | 51 #include "chrome/utility/extensions/extensions_handler.h" |
58 #endif | 52 #endif |
59 | 53 |
60 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \ | 54 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \ |
61 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) | 55 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) |
62 #include "chrome/utility/printing_handler.h" | 56 #include "chrome/utility/printing_handler.h" |
63 #endif | 57 #endif |
64 | 58 |
65 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) | 59 #if defined(FULL_SAFE_BROWSING) |
60 #include "chrome/common/safe_archive_analyzer.mojom.h" | |
61 #include "chrome/common/safe_browsing/zip_analyzer.h" | |
62 #include "chrome/common/safe_browsing/zip_analyzer_results.h" | |
63 #if defined(OS_MACOSX) | |
66 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" | 64 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" |
67 #endif | 65 #endif |
66 #endif | |
68 | 67 |
69 namespace { | 68 namespace { |
70 | 69 |
71 class FilePatcherImpl : public chrome::mojom::FilePatcher { | 70 class FilePatcherImpl : public chrome::mojom::FilePatcher { |
72 public: | 71 public: |
73 FilePatcherImpl() = default; | 72 FilePatcherImpl() = default; |
74 ~FilePatcherImpl() override = default; | 73 ~FilePatcherImpl() override = default; |
75 | 74 |
76 static void Create(chrome::mojom::FilePatcherRequest request) { | 75 static void Create(chrome::mojom::FilePatcherRequest request) { |
77 mojo::MakeStrongBinding(base::MakeUnique<FilePatcherImpl>(), | 76 mojo::MakeStrongBinding(base::MakeUnique<FilePatcherImpl>(), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 } | 127 } |
129 | 128 |
130 callback.Run(zip::ZipFiles(source_dir, source_relative_paths, | 129 callback.Run(zip::ZipFiles(source_dir, source_relative_paths, |
131 zip_file.GetPlatformFile())); | 130 zip_file.GetPlatformFile())); |
132 } | 131 } |
133 | 132 |
134 DISALLOW_COPY_AND_ASSIGN(ZipFileCreatorImpl); | 133 DISALLOW_COPY_AND_ASSIGN(ZipFileCreatorImpl); |
135 }; | 134 }; |
136 #endif // defined(OS_CHROMEOS) | 135 #endif // defined(OS_CHROMEOS) |
137 | 136 |
137 #if defined(FULL_SAFE_BROWSING) | |
138 class SafeArchiveAnalyzerImpl : public chrome::mojom::SafeArchiveAnalyzer { | |
139 public: | |
140 SafeArchiveAnalyzerImpl() = default; | |
141 ~SafeArchiveAnalyzerImpl() override = default; | |
142 | |
143 static void Create(chrome::mojom::SafeArchiveAnalyzerRequest request) { | |
144 mojo::MakeStrongBinding(base::MakeUnique<SafeArchiveAnalyzerImpl>(), | |
145 std::move(request)); | |
146 } | |
147 | |
148 private: | |
149 // chrome::mojom::SafeArchiveAnalyzer: | |
150 void AnalyzeZipFile(base::File zip_file, | |
151 base::File temporary_file, | |
152 const AnalyzeZipFileCallback& callback) override { | |
153 DCHECK(temporary_file.IsValid()); | |
Noel Gordon
2017/03/10 15:19:31
@sammc, these DCHECK are redundant, no? Mojo won'
Noel Gordon
2017/03/10 15:38:50
Reading traits, mojo can rx a kInvalidPlatformFile
| |
154 DCHECK(zip_file.IsValid()); | |
155 | |
156 safe_browsing::zip_analyzer::Results results; | |
157 safe_browsing::zip_analyzer::AnalyzeZipFile( | |
158 std::move(zip_file), std::move(temporary_file), &results); | |
159 callback.Run(results); | |
160 } | |
161 | |
162 void AnalyzeDmgFile(base::File dmg_file, | |
163 const AnalyzeDmgFileCallback& callback) override { | |
164 #if defined(OS_MACOSX) | |
165 DCHECK(dmg_file.IsValid()); | |
166 safe_browsing::zip_analyzer::Results results; | |
167 safe_browsing::dmg::AnalyzeDMGFile(std::move(dmg_file), &results); | |
168 callback.Run(results); | |
169 #else | |
170 NOTREACHED(); | |
171 #endif | |
172 } | |
173 | |
174 DISALLOW_COPY_AND_ASSIGN(SafeArchiveAnalyzerImpl); | |
175 }; | |
176 #endif // defined(FULL_SAFE_BROWSING) | |
177 | |
138 #if !defined(OS_ANDROID) | 178 #if !defined(OS_ANDROID) |
139 void CreateProxyResolverFactory( | 179 void CreateProxyResolverFactory( |
140 net::interfaces::ProxyResolverFactoryRequest request) { | 180 net::interfaces::ProxyResolverFactoryRequest request) { |
141 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(), | 181 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(), |
142 std::move(request)); | 182 std::move(request)); |
143 } | 183 } |
144 | 184 |
145 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter { | 185 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter { |
146 public: | 186 public: |
147 ResourceUsageReporterImpl() {} | 187 ResourceUsageReporterImpl() {} |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 243 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
204 if (command_line->HasSwitch(switches::kUtilityProcessRunningElevated)) | 244 if (command_line->HasSwitch(switches::kUtilityProcessRunningElevated)) |
205 utility_process_running_elevated_ = true; | 245 utility_process_running_elevated_ = true; |
206 } | 246 } |
207 | 247 |
208 bool ChromeContentUtilityClient::OnMessageReceived( | 248 bool ChromeContentUtilityClient::OnMessageReceived( |
209 const IPC::Message& message) { | 249 const IPC::Message& message) { |
210 if (utility_process_running_elevated_) | 250 if (utility_process_running_elevated_) |
211 return false; | 251 return false; |
212 | 252 |
213 bool handled = true; | |
214 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | |
215 #if defined(FULL_SAFE_BROWSING) | |
216 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, | |
217 OnAnalyzeZipFileForDownloadProtection) | |
218 #if defined(OS_MACOSX) | |
219 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, | |
220 OnAnalyzeDmgFileForDownloadProtection) | |
221 #endif // defined(OS_MACOSX) | |
222 #endif // defined(FULL_SAFE_BROWSING) | |
223 IPC_MESSAGE_UNHANDLED(handled = false) | |
224 IPC_END_MESSAGE_MAP() | |
225 | |
226 if (handled) | |
227 return true; | |
228 | |
229 for (auto* handler : handlers_) { | 253 for (auto* handler : handlers_) { |
230 if (handler->OnMessageReceived(message)) | 254 if (handler->OnMessageReceived(message)) |
231 return true; | 255 return true; |
232 } | 256 } |
233 | 257 |
234 return false; | 258 return false; |
235 } | 259 } |
236 | 260 |
237 void ChromeContentUtilityClient::ExposeInterfacesToBrowser( | 261 void ChromeContentUtilityClient::ExposeInterfacesToBrowser( |
238 service_manager::InterfaceRegistry* registry) { | 262 service_manager::InterfaceRegistry* registry) { |
(...skipping 14 matching lines...) Expand all Loading... | |
253 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); | 277 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); |
254 #endif | 278 #endif |
255 registry->AddInterface( | 279 registry->AddInterface( |
256 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); | 280 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); |
257 #if defined(OS_WIN) | 281 #if defined(OS_WIN) |
258 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); | 282 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); |
259 #endif | 283 #endif |
260 #if defined(OS_CHROMEOS) | 284 #if defined(OS_CHROMEOS) |
261 registry->AddInterface(base::Bind(&ZipFileCreatorImpl::Create)); | 285 registry->AddInterface(base::Bind(&ZipFileCreatorImpl::Create)); |
262 #endif | 286 #endif |
287 #if defined(FULL_SAFE_BROWSING) | |
288 registry->AddInterface(base::Bind(&SafeArchiveAnalyzerImpl::Create)); | |
289 #endif | |
263 } | 290 } |
264 | 291 |
265 void ChromeContentUtilityClient::RegisterServices(StaticServiceMap* services) { | 292 void ChromeContentUtilityClient::RegisterServices(StaticServiceMap* services) { |
266 content::ServiceInfo image_decoder_info; | 293 content::ServiceInfo image_decoder_info; |
267 image_decoder_info.factory = base::Bind(&CreateImageDecoderService); | 294 image_decoder_info.factory = base::Bind(&CreateImageDecoderService); |
268 services->insert( | 295 services->insert( |
269 std::make_pair(image_decoder::mojom::kServiceName, image_decoder_info)); | 296 std::make_pair(image_decoder::mojom::kServiceName, image_decoder_info)); |
270 } | 297 } |
271 | 298 |
272 // static | 299 // static |
273 void ChromeContentUtilityClient::PreSandboxStartup() { | 300 void ChromeContentUtilityClient::PreSandboxStartup() { |
274 #if BUILDFLAG(ENABLE_EXTENSIONS) | 301 #if BUILDFLAG(ENABLE_EXTENSIONS) |
275 extensions::ExtensionsHandler::PreSandboxStartup(); | 302 extensions::ExtensionsHandler::PreSandboxStartup(); |
276 #endif | 303 #endif |
277 } | 304 } |
278 | |
279 #if defined(FULL_SAFE_BROWSING) | |
280 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( | |
281 const IPC::PlatformFileForTransit& zip_file, | |
282 const IPC::PlatformFileForTransit& temp_file) { | |
283 safe_browsing::zip_analyzer::Results results; | |
284 safe_browsing::zip_analyzer::AnalyzeZipFile( | |
285 IPC::PlatformFileForTransitToFile(zip_file), | |
286 IPC::PlatformFileForTransitToFile(temp_file), &results); | |
287 content::UtilityThread::Get()->Send( | |
288 new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( | |
289 results)); | |
290 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | |
291 } | |
292 | |
293 #if defined(OS_MACOSX) | |
294 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection( | |
295 const IPC::PlatformFileForTransit& dmg_file) { | |
296 safe_browsing::zip_analyzer::Results results; | |
297 safe_browsing::dmg::AnalyzeDMGFile( | |
298 IPC::PlatformFileForTransitToFile(dmg_file), &results); | |
299 content::UtilityThread::Get()->Send( | |
300 new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( | |
301 results)); | |
302 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | |
303 } | |
304 #endif // defined(OS_MACOSX) | |
305 | |
306 #endif // defined(FULL_SAFE_BROWSING) | |
OLD | NEW |