| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/runner/context.h" | 5 #include "mojo/shell/standalone/context.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/i18n/icu_util.h" | 16 #include "base/i18n/icu_util.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 21 #include "base/process/process_info.h" | 21 #include "base/process/process_info.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
| 25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 26 #include "base/trace_event/trace_event.h" | 26 #include "base/trace_event/trace_event.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "components/devtools_service/public/cpp/switches.h" | 28 #include "components/devtools_service/public/cpp/switches.h" |
| 29 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h
" | 29 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h
" |
| 30 #include "components/tracing/tracing_switches.h" | 30 #include "components/tracing/tracing_switches.h" |
| 31 #include "mojo/public/cpp/bindings/strong_binding.h" | 31 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 32 #include "mojo/runner/register_local_aliases.h" | |
| 33 #include "mojo/runner/switches.h" | |
| 34 #include "mojo/runner/tracer.h" | |
| 35 #include "mojo/services/tracing/public/cpp/switches.h" | 32 #include "mojo/services/tracing/public/cpp/switches.h" |
| 36 #include "mojo/services/tracing/public/cpp/trace_provider_impl.h" | 33 #include "mojo/services/tracing/public/cpp/trace_provider_impl.h" |
| 37 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 34 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
| 38 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" | 35 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" |
| 39 #include "mojo/shell/application_loader.h" | 36 #include "mojo/shell/application_loader.h" |
| 40 #include "mojo/shell/connect_to_application_params.h" | 37 #include "mojo/shell/connect_to_application_params.h" |
| 41 #include "mojo/shell/package_manager/package_manager_impl.h" | 38 #include "mojo/shell/package_manager/package_manager_impl.h" |
| 42 #include "mojo/shell/public/cpp/application_connection.h" | 39 #include "mojo/shell/public/cpp/application_connection.h" |
| 43 #include "mojo/shell/public/cpp/application_delegate.h" | 40 #include "mojo/shell/public/cpp/application_delegate.h" |
| 44 #include "mojo/shell/public/cpp/application_impl.h" | 41 #include "mojo/shell/public/cpp/application_impl.h" |
| 45 #include "mojo/shell/query_util.h" | 42 #include "mojo/shell/query_util.h" |
| 46 #include "mojo/shell/runner/host/in_process_native_runner.h" | 43 #include "mojo/shell/runner/host/in_process_native_runner.h" |
| 47 #include "mojo/shell/runner/host/out_of_process_native_runner.h" | 44 #include "mojo/shell/runner/host/out_of_process_native_runner.h" |
| 45 #include "mojo/shell/standalone/register_local_aliases.h" |
| 46 #include "mojo/shell/standalone/switches.h" |
| 47 #include "mojo/shell/standalone/tracer.h" |
| 48 #include "mojo/shell/switches.h" | 48 #include "mojo/shell/switches.h" |
| 49 #include "mojo/util/filename_util.h" | 49 #include "mojo/util/filename_util.h" |
| 50 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | 50 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| 51 #include "url/gurl.h" | 51 #include "url/gurl.h" |
| 52 | 52 |
| 53 namespace mojo { | 53 namespace mojo { |
| 54 namespace runner { | 54 namespace shell { |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| 57 // Used to ensure we only init once. | 57 // Used to ensure we only init once. |
| 58 class Setup { | 58 class Setup { |
| 59 public: | 59 public: |
| 60 Setup() { | 60 Setup() { |
| 61 embedder::PreInitializeParentProcess(); | 61 embedder::PreInitializeParentProcess(); |
| 62 embedder::Init(); | 62 embedder::Init(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 ~Setup() {} | 65 ~Setup() {} |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 DISALLOW_COPY_AND_ASSIGN(Setup); | 68 DISALLOW_COPY_AND_ASSIGN(Setup); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 void InitContentHandlers(shell::PackageManagerImpl* manager, | 71 void InitContentHandlers(PackageManagerImpl* manager, |
| 72 const base::CommandLine& command_line) { | 72 const base::CommandLine& command_line) { |
| 73 // Default content handlers. | 73 // Default content handlers. |
| 74 manager->RegisterContentHandler("application/javascript", | 74 manager->RegisterContentHandler("application/javascript", |
| 75 GURL("mojo:html_viewer")); | 75 GURL("mojo:html_viewer")); |
| 76 manager->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer")); | 76 manager->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer")); |
| 77 manager->RegisterContentHandler("image/gif", GURL("mojo:html_viewer")); | 77 manager->RegisterContentHandler("image/gif", GURL("mojo:html_viewer")); |
| 78 manager->RegisterContentHandler("image/jpeg", GURL("mojo:html_viewer")); | 78 manager->RegisterContentHandler("image/jpeg", GURL("mojo:html_viewer")); |
| 79 manager->RegisterContentHandler("image/png", GURL("mojo:html_viewer")); | 79 manager->RegisterContentHandler("image/png", GURL("mojo:html_viewer")); |
| 80 manager->RegisterContentHandler("text/css", GURL("mojo:html_viewer")); | 80 manager->RegisterContentHandler("text/css", GURL("mojo:html_viewer")); |
| 81 manager->RegisterContentHandler("text/html", GURL("mojo:html_viewer")); | 81 manager->RegisterContentHandler("text/html", GURL("mojo:html_viewer")); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers | 114 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers |
| 115 << ": '" << parts[i + 1] << "' is not a valid URL."; | 115 << ": '" << parts[i + 1] << "' is not a valid URL."; |
| 116 return; | 116 return; |
| 117 } | 117 } |
| 118 // TODO(eseidel): We should also validate that the mimetype is valid | 118 // TODO(eseidel): We should also validate that the mimetype is valid |
| 119 // net/base/mime_util.h could do this, but we don't want to depend on net. | 119 // net/base/mime_util.h could do this, but we don't want to depend on net. |
| 120 manager->RegisterContentHandler(parts[i], url); | 120 manager->RegisterContentHandler(parts[i], url); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 void InitDevToolsServiceIfNeeded(shell::ApplicationManager* manager, | 124 void InitDevToolsServiceIfNeeded(ApplicationManager* manager, |
| 125 const base::CommandLine& command_line) { | 125 const base::CommandLine& command_line) { |
| 126 if (!command_line.HasSwitch(devtools_service::kRemoteDebuggingPort)) | 126 if (!command_line.HasSwitch(devtools_service::kRemoteDebuggingPort)) |
| 127 return; | 127 return; |
| 128 | 128 |
| 129 std::string port_str = | 129 std::string port_str = |
| 130 command_line.GetSwitchValueASCII(devtools_service::kRemoteDebuggingPort); | 130 command_line.GetSwitchValueASCII(devtools_service::kRemoteDebuggingPort); |
| 131 unsigned port; | 131 unsigned port; |
| 132 if (!base::StringToUint(port_str, &port) || port > 65535) { | 132 if (!base::StringToUint(port_str, &port) || port > 65535) { |
| 133 LOG(ERROR) << "Invalid value for switch " | 133 LOG(ERROR) << "Invalid value for switch " |
| 134 << devtools_service::kRemoteDebuggingPort << ": '" << port_str | 134 << devtools_service::kRemoteDebuggingPort << ": '" << port_str |
| 135 << "' is not a valid port number."; | 135 << "' is not a valid port number."; |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 | 138 |
| 139 ServiceProviderPtr devtools_service_provider; | 139 ServiceProviderPtr devtools_service_provider; |
| 140 scoped_ptr<shell::ConnectToApplicationParams> params( | 140 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
| 141 new shell::ConnectToApplicationParams); | 141 params->set_source(Identity(GURL("mojo:shell"), std::string(), |
| 142 params->set_source(shell::Identity(GURL("mojo:shell"), std::string(), | 142 GetPermissiveCapabilityFilter())); |
| 143 shell::GetPermissiveCapabilityFilter())); | 143 params->SetTarget(Identity(GURL("mojo:devtools_service"), std::string(), |
| 144 params->SetTarget(shell::Identity(GURL("mojo:devtools_service"), | 144 GetPermissiveCapabilityFilter())); |
| 145 std::string(), | |
| 146 shell::GetPermissiveCapabilityFilter())); | |
| 147 params->set_services(GetProxy(&devtools_service_provider)); | 145 params->set_services(GetProxy(&devtools_service_provider)); |
| 148 manager->ConnectToApplication(std::move(params)); | 146 manager->ConnectToApplication(std::move(params)); |
| 149 | 147 |
| 150 devtools_service::DevToolsCoordinatorPtr devtools_coordinator; | 148 devtools_service::DevToolsCoordinatorPtr devtools_coordinator; |
| 151 devtools_service_provider->ConnectToService( | 149 devtools_service_provider->ConnectToService( |
| 152 devtools_service::DevToolsCoordinator::Name_, | 150 devtools_service::DevToolsCoordinator::Name_, |
| 153 GetProxy(&devtools_coordinator).PassMessagePipe()); | 151 GetProxy(&devtools_coordinator).PassMessagePipe()); |
| 154 devtools_coordinator->Initialize(static_cast<uint16_t>(port)); | 152 devtools_coordinator->Initialize(static_cast<uint16_t>(port)); |
| 155 } | 153 } |
| 156 | 154 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 208 |
| 211 EnsureEmbedderIsInitialized(); | 209 EnsureEmbedderIsInitialized(); |
| 212 task_runners_.reset( | 210 task_runners_.reset( |
| 213 new TaskRunners(base::MessageLoop::current()->task_runner())); | 211 new TaskRunners(base::MessageLoop::current()->task_runner())); |
| 214 | 212 |
| 215 // TODO(vtl): This should be MASTER, not NONE. | 213 // TODO(vtl): This should be MASTER, not NONE. |
| 216 embedder::InitIPCSupport(embedder::ProcessType::NONE, this, | 214 embedder::InitIPCSupport(embedder::ProcessType::NONE, this, |
| 217 task_runners_->io_runner(), | 215 task_runners_->io_runner(), |
| 218 embedder::ScopedPlatformHandle()); | 216 embedder::ScopedPlatformHandle()); |
| 219 | 217 |
| 220 package_manager_ = new shell::PackageManagerImpl( | 218 package_manager_ = |
| 221 shell_file_root, task_runners_->blocking_pool()); | 219 new PackageManagerImpl(shell_file_root, task_runners_->blocking_pool()); |
| 222 InitContentHandlers(package_manager_, command_line); | 220 InitContentHandlers(package_manager_, command_line); |
| 223 | 221 |
| 224 RegisterLocalAliases(package_manager_); | 222 RegisterLocalAliases(package_manager_); |
| 225 | 223 |
| 226 scoped_ptr<shell::NativeRunnerFactory> runner_factory; | 224 scoped_ptr<NativeRunnerFactory> runner_factory; |
| 227 if (command_line.HasSwitch(switches::kMojoSingleProcess)) { | 225 if (command_line.HasSwitch(switches::kMojoSingleProcess)) { |
| 228 #if defined(COMPONENT_BUILD) | 226 #if defined(COMPONENT_BUILD) |
| 229 LOG(ERROR) << "Running Mojo in single process component build, which isn't " | 227 LOG(ERROR) << "Running Mojo in single process component build, which isn't " |
| 230 << "supported because statics in apps interact. Use static build" | 228 << "supported because statics in apps interact. Use static build" |
| 231 << " or don't pass --single-process."; | 229 << " or don't pass --single-process."; |
| 232 #endif | 230 #endif |
| 233 runner_factory.reset(new shell::InProcessNativeRunnerFactory( | 231 runner_factory.reset( |
| 234 task_runners_->blocking_pool())); | 232 new InProcessNativeRunnerFactory(task_runners_->blocking_pool())); |
| 235 } else { | 233 } else { |
| 236 runner_factory.reset(new shell::OutOfProcessNativeRunnerFactory( | 234 runner_factory.reset( |
| 237 task_runners_->blocking_pool())); | 235 new OutOfProcessNativeRunnerFactory(task_runners_->blocking_pool())); |
| 238 } | 236 } |
| 239 application_manager_.reset(new shell::ApplicationManager( | 237 application_manager_.reset(new ApplicationManager( |
| 240 make_scoped_ptr(package_manager_), std::move(runner_factory), | 238 make_scoped_ptr(package_manager_), std::move(runner_factory), |
| 241 task_runners_->blocking_pool())); | 239 task_runners_->blocking_pool())); |
| 242 | 240 |
| 243 ServiceProviderPtr tracing_services; | 241 ServiceProviderPtr tracing_services; |
| 244 ServiceProviderPtr tracing_exposed_services; | 242 ServiceProviderPtr tracing_exposed_services; |
| 245 new TracingServiceProvider(&tracer_, GetProxy(&tracing_exposed_services)); | 243 new TracingServiceProvider(&tracer_, GetProxy(&tracing_exposed_services)); |
| 246 | 244 |
| 247 scoped_ptr<shell::ConnectToApplicationParams> params( | 245 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
| 248 new shell::ConnectToApplicationParams); | 246 params->set_source(Identity(GURL("mojo:shell"), std::string(), |
| 249 params->set_source(shell::Identity(GURL("mojo:shell"), std::string(), | 247 GetPermissiveCapabilityFilter())); |
| 250 shell::GetPermissiveCapabilityFilter())); | 248 params->SetTarget(Identity(GURL("mojo:tracing"), std::string(), |
| 251 params->SetTarget(shell::Identity(GURL("mojo:tracing"), std::string(), | 249 GetPermissiveCapabilityFilter())); |
| 252 shell::GetPermissiveCapabilityFilter())); | |
| 253 params->set_services(GetProxy(&tracing_services)); | 250 params->set_services(GetProxy(&tracing_services)); |
| 254 params->set_exposed_services(std::move(tracing_exposed_services)); | 251 params->set_exposed_services(std::move(tracing_exposed_services)); |
| 255 application_manager_->ConnectToApplication(std::move(params)); | 252 application_manager_->ConnectToApplication(std::move(params)); |
| 256 | 253 |
| 257 if (command_line.HasSwitch(tracing::kTraceStartup)) { | 254 if (command_line.HasSwitch(tracing::kTraceStartup)) { |
| 258 tracing::TraceCollectorPtr coordinator; | 255 tracing::TraceCollectorPtr coordinator; |
| 259 auto coordinator_request = GetProxy(&coordinator); | 256 auto coordinator_request = GetProxy(&coordinator); |
| 260 tracing_services->ConnectToService(tracing::TraceCollector::Name_, | 257 tracing_services->ConnectToService(tracing::TraceCollector::Name_, |
| 261 coordinator_request.PassMessagePipe()); | 258 coordinator_request.PassMessagePipe()); |
| 262 tracer_.StartCollectingFromTracingService(std::move(coordinator)); | 259 tracer_.StartCollectingFromTracingService(std::move(coordinator)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 base::MessageLoop::current()->QuitWhenIdle(); | 301 base::MessageLoop::current()->QuitWhenIdle(); |
| 305 } | 302 } |
| 306 | 303 |
| 307 void Context::Run(const GURL& url) { | 304 void Context::Run(const GURL& url) { |
| 308 DCHECK(app_complete_callback_.is_null()); | 305 DCHECK(app_complete_callback_.is_null()); |
| 309 ServiceProviderPtr services; | 306 ServiceProviderPtr services; |
| 310 ServiceProviderPtr exposed_services; | 307 ServiceProviderPtr exposed_services; |
| 311 | 308 |
| 312 app_urls_.insert(url); | 309 app_urls_.insert(url); |
| 313 | 310 |
| 314 scoped_ptr<shell::ConnectToApplicationParams> params( | 311 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
| 315 new shell::ConnectToApplicationParams); | 312 params->SetTarget( |
| 316 params->SetTarget(shell::Identity(url, std::string(), | 313 Identity(url, std::string(), GetPermissiveCapabilityFilter())); |
| 317 shell::GetPermissiveCapabilityFilter())); | |
| 318 params->set_services(GetProxy(&services)); | 314 params->set_services(GetProxy(&services)); |
| 319 params->set_exposed_services(std::move(exposed_services)); | 315 params->set_exposed_services(std::move(exposed_services)); |
| 320 params->set_on_application_end( | 316 params->set_on_application_end( |
| 321 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); | 317 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); |
| 322 application_manager_->ConnectToApplication(std::move(params)); | 318 application_manager_->ConnectToApplication(std::move(params)); |
| 323 } | 319 } |
| 324 | 320 |
| 325 void Context::RunCommandLineApplication(const base::Closure& callback) { | 321 void Context::RunCommandLineApplication(const base::Closure& callback) { |
| 326 DCHECK(app_urls_.empty()); | 322 DCHECK(app_urls_.empty()); |
| 327 DCHECK(app_complete_callback_.is_null()); | 323 DCHECK(app_complete_callback_.is_null()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 345 task_runners_->shell_runner()); | 341 task_runners_->shell_runner()); |
| 346 if (app_complete_callback_.is_null()) { | 342 if (app_complete_callback_.is_null()) { |
| 347 base::MessageLoop::current()->QuitWhenIdle(); | 343 base::MessageLoop::current()->QuitWhenIdle(); |
| 348 } else { | 344 } else { |
| 349 app_complete_callback_.Run(); | 345 app_complete_callback_.Run(); |
| 350 } | 346 } |
| 351 } | 347 } |
| 352 } | 348 } |
| 353 } | 349 } |
| 354 | 350 |
| 355 } // namespace runner | 351 } // namespace shell |
| 356 } // namespace mojo | 352 } // namespace mojo |
| OLD | NEW |