| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This is a terminal client (i.e., a "raw" |mojo.terminal.Terminal| -- e.g., | 5 // This is a terminal client (i.e., a "raw" |mojo.terminal.Terminal| -- e.g., |
| 6 // moterm -- can be asked to talk to this) that prompts the user for a native | 6 // moterm -- can be asked to talk to this) that prompts the user for a native |
| 7 // (Linux) binary to run and then does so (via mojo:native_support). | 7 // (Linux) binary to run and then does so (via mojo:native_support). |
| 8 // | 8 // |
| 9 // E.g., first run mojo:moterm_example_app (embedded by a window manager). Then, | 9 // E.g., first run mojo:moterm_example_app (embedded by a window manager). Then, |
| 10 // at the prompt, enter "mojo:native_run_app". At the next prompt, enter "bash" | 10 // at the prompt, enter "mojo:native_run_app". At the next prompt, enter "bash" |
| 11 // (or "echo hello mojo"). | 11 // (or "echo hello mojo"). |
| 12 // | 12 // |
| 13 // TODO(vtl): Maybe it should optionally be able to extract the binary path (and | 13 // TODO(vtl): Maybe it should optionally be able to extract the binary path (and |
| 14 // args) from the connection URL? | 14 // args) from the connection URL? |
| 15 | 15 |
| 16 #include <string.h> | 16 #include <string.h> |
| 17 | 17 |
| 18 #include <string> | 18 #include <string> |
| 19 #include <utility> | 19 #include <utility> |
| 20 #include <vector> | 20 #include <vector> |
| 21 | 21 |
| 22 #include "base/logging.h" | 22 #include "base/logging.h" |
| 23 #include "base/macros.h" | 23 #include "base/macros.h" |
| 24 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
| 25 #include "mojo/application/application_runner_chromium.h" | |
| 26 #include "mojo/public/c/system/main.h" | 25 #include "mojo/public/c/system/main.h" |
| 27 #include "mojo/public/cpp/application/application_delegate.h" | 26 #include "mojo/public/cpp/application/application_delegate.h" |
| 28 #include "mojo/public/cpp/application/application_impl.h" | 27 #include "mojo/public/cpp/application/application_impl_base.h" |
| 29 #include "mojo/public/cpp/application/connect.h" | 28 #include "mojo/public/cpp/application/connect.h" |
| 29 #include "mojo/public/cpp/application/run_application.h" |
| 30 #include "mojo/public/cpp/application/service_provider_impl.h" | 30 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 31 #include "mojo/public/cpp/bindings/interface_request.h" | 31 #include "mojo/public/cpp/bindings/interface_request.h" |
| 32 #include "mojo/public/cpp/bindings/strong_binding.h" | 32 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 33 #include "mojo/services/files/interfaces/files.mojom.h" | 33 #include "mojo/services/files/interfaces/files.mojom.h" |
| 34 #include "mojo/services/files/interfaces/ioctl.mojom.h" | 34 #include "mojo/services/files/interfaces/ioctl.mojom.h" |
| 35 #include "mojo/services/files/interfaces/ioctl_terminal.mojom.h" | 35 #include "mojo/services/files/interfaces/ioctl_terminal.mojom.h" |
| 36 #include "mojo/services/files/interfaces/types.mojom.h" | 36 #include "mojo/services/files/interfaces/types.mojom.h" |
| 37 #include "mojo/services/native_support/interfaces/process.mojom.h" | 37 #include "mojo/services/native_support/interfaces/process.mojom.h" |
| 38 #include "mojo/services/terminal/interfaces/terminal_client.mojom.h" | 38 #include "mojo/services/terminal/interfaces/terminal_client.mojom.h" |
| 39 | 39 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 private: | 216 private: |
| 217 mojo::StrongBinding<TerminalClient> binding_; | 217 mojo::StrongBinding<TerminalClient> binding_; |
| 218 native_support::Process* native_support_process_; | 218 native_support::Process* native_support_process_; |
| 219 | 219 |
| 220 DISALLOW_COPY_AND_ASSIGN(TerminalClientImpl); | 220 DISALLOW_COPY_AND_ASSIGN(TerminalClientImpl); |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 class NativeRunApp : public mojo::ApplicationDelegate { | 223 class NativeRunApp : public mojo::ApplicationImplBase { |
| 224 public: | 224 public: |
| 225 NativeRunApp() : application_impl_(nullptr) {} | 225 NativeRunApp() {} |
| 226 ~NativeRunApp() override {} | 226 ~NativeRunApp() override {} |
| 227 | 227 |
| 228 private: | 228 private: |
| 229 // |mojo::ApplicationDelegate|: | 229 // |mojo::ApplicationImplBase| overrides: |
| 230 void Initialize(mojo::ApplicationImpl* application_impl) override { | 230 void OnInitialize() override { |
| 231 DCHECK(!application_impl_); | 231 mojo::ConnectToService(shell(), "mojo:native_support", |
| 232 application_impl_ = application_impl; | |
| 233 mojo::ConnectToService(application_impl_->shell(), "mojo:native_support", | |
| 234 GetProxy(&native_support_process_)); | 232 GetProxy(&native_support_process_)); |
| 235 } | 233 } |
| 236 | 234 |
| 237 bool ConfigureIncomingConnection( | 235 bool OnAcceptConnection( |
| 238 mojo::ServiceProviderImpl* service_provider_impl) override { | 236 mojo::ServiceProviderImpl* service_provider_impl) override { |
| 239 service_provider_impl->AddService<TerminalClient>( | 237 service_provider_impl->AddService<TerminalClient>( |
| 240 [this](const mojo::ConnectionContext& connection_context, | 238 [this](const mojo::ConnectionContext& connection_context, |
| 241 mojo::InterfaceRequest<TerminalClient> terminal_client_request) { | 239 mojo::InterfaceRequest<TerminalClient> terminal_client_request) { |
| 242 new TerminalClientImpl(terminal_client_request.Pass(), | 240 new TerminalClientImpl(terminal_client_request.Pass(), |
| 243 native_support_process_.get()); | 241 native_support_process_.get()); |
| 244 }); | 242 }); |
| 245 return true; | 243 return true; |
| 246 } | 244 } |
| 247 | 245 |
| 248 mojo::ApplicationImpl* application_impl_; | |
| 249 native_support::ProcessPtr native_support_process_; | 246 native_support::ProcessPtr native_support_process_; |
| 250 | 247 |
| 251 DISALLOW_COPY_AND_ASSIGN(NativeRunApp); | 248 DISALLOW_COPY_AND_ASSIGN(NativeRunApp); |
| 252 }; | 249 }; |
| 253 | 250 |
| 254 MojoResult MojoMain(MojoHandle application_request) { | 251 MojoResult MojoMain(MojoHandle application_request) { |
| 255 mojo::ApplicationRunnerChromium runner(new NativeRunApp()); | 252 NativeRunApp native_run_app; |
| 256 return runner.Run(application_request); | 253 return mojo::RunMainApplication(application_request, &native_run_app); |
| 257 } | 254 } |
| OLD | NEW |