| 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 "shell/context.h" | 5 #include "shell/context.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "mojo/public/cpp/application/application_connection.h" | 24 #include "mojo/public/cpp/application/application_connection.h" |
| 25 #include "mojo/public/cpp/application/application_delegate.h" | 25 #include "mojo/public/cpp/application/application_delegate.h" |
| 26 #include "mojo/public/cpp/application/application_impl.h" | 26 #include "mojo/public/cpp/application/application_impl.h" |
| 27 #include "mojo/spy/spy.h" | 27 #include "mojo/spy/spy.h" |
| 28 #include "services/tracing/tracing.mojom.h" | 28 #include "services/tracing/tracing.mojom.h" |
| 29 #include "shell/dynamic_application_loader.h" | 29 #include "shell/dynamic_application_loader.h" |
| 30 #include "shell/external_application_listener.h" | 30 #include "shell/external_application_listener.h" |
| 31 #include "shell/in_process_dynamic_service_runner.h" | 31 #include "shell/in_process_dynamic_service_runner.h" |
| 32 #include "shell/out_of_process_dynamic_service_runner.h" | 32 #include "shell/out_of_process_dynamic_service_runner.h" |
| 33 #include "shell/switches.h" | 33 #include "shell/switches.h" |
| 34 #include "shell/ui_application_loader_android.h" | |
| 35 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 36 | 35 |
| 37 #if defined(OS_ANDROID) | |
| 38 #include "services/gles2/gpu_impl.h" | |
| 39 #include "services/native_viewport/native_viewport_impl.h" | |
| 40 #include "shell/android/android_handler_loader.h" | |
| 41 #endif // defined(OS_ANDROID) | |
| 42 | |
| 43 namespace mojo { | 36 namespace mojo { |
| 44 namespace shell { | 37 namespace shell { |
| 45 namespace { | 38 namespace { |
| 46 | 39 |
| 47 // These mojo: URLs are loaded directly from the local filesystem. They | 40 // These mojo: URLs are loaded directly from the local filesystem. They |
| 48 // correspond to shared libraries bundled alongside the mojo_shell. | 41 // correspond to shared libraries bundled alongside the mojo_shell. |
| 49 const char* kLocalMojoURLs[] = { | 42 const char* kLocalMojoURLs[] = { |
| 50 "mojo:network_service", | 43 "mojo:network_service", |
| 51 }; | 44 }; |
| 52 | 45 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 const GURL to(pair.second); | 108 const GURL to(pair.second); |
| 116 if (!from.is_valid() || !to.is_valid()) | 109 if (!from.is_valid() || !to.is_valid()) |
| 117 return false; | 110 return false; |
| 118 resolver->AddCustomMapping(from, to); | 111 resolver->AddCustomMapping(from, to); |
| 119 } | 112 } |
| 120 return true; | 113 return true; |
| 121 } | 114 } |
| 122 | 115 |
| 123 } // namespace | 116 } // namespace |
| 124 | 117 |
| 125 #if defined(OS_ANDROID) | |
| 126 class Context::NativeViewportApplicationLoader | |
| 127 : public ApplicationLoader, | |
| 128 public ApplicationDelegate, | |
| 129 public InterfaceFactory<NativeViewport>, | |
| 130 public InterfaceFactory<Gpu> { | |
| 131 public: | |
| 132 NativeViewportApplicationLoader() : gpu_state_(new gles2::GpuImpl::State) {} | |
| 133 virtual ~NativeViewportApplicationLoader() {} | |
| 134 | |
| 135 private: | |
| 136 // ApplicationLoader implementation. | |
| 137 virtual void Load(ApplicationManager* manager, | |
| 138 const GURL& url, | |
| 139 ScopedMessagePipeHandle shell_handle, | |
| 140 LoadCallback callback) override { | |
| 141 DCHECK(shell_handle.is_valid()); | |
| 142 app_.reset(new ApplicationImpl(this, shell_handle.Pass())); | |
| 143 } | |
| 144 | |
| 145 virtual void OnApplicationError(ApplicationManager* manager, | |
| 146 const GURL& url) override {} | |
| 147 | |
| 148 // ApplicationDelegate implementation. | |
| 149 virtual bool ConfigureIncomingConnection( | |
| 150 mojo::ApplicationConnection* connection) override { | |
| 151 connection->AddService<NativeViewport>(this); | |
| 152 connection->AddService<Gpu>(this); | |
| 153 return true; | |
| 154 } | |
| 155 | |
| 156 // InterfaceFactory<NativeViewport> implementation. | |
| 157 virtual void Create(ApplicationConnection* connection, | |
| 158 InterfaceRequest<NativeViewport> request) override { | |
| 159 BindToRequest(new NativeViewportImpl(app_.get(), false), &request); | |
| 160 } | |
| 161 | |
| 162 // InterfaceFactory<Gpu> implementation. | |
| 163 virtual void Create(ApplicationConnection* connection, | |
| 164 InterfaceRequest<Gpu> request) override { | |
| 165 new gles2::GpuImpl(request.Pass(), gpu_state_); | |
| 166 } | |
| 167 | |
| 168 scoped_refptr<gles2::GpuImpl::State> gpu_state_; | |
| 169 scoped_ptr<ApplicationImpl> app_; | |
| 170 DISALLOW_COPY_AND_ASSIGN(NativeViewportApplicationLoader); | |
| 171 }; | |
| 172 #endif | |
| 173 | |
| 174 Context::Context() : application_manager_(this) { | 118 Context::Context() : application_manager_(this) { |
| 175 DCHECK(!base::MessageLoop::current()); | 119 DCHECK(!base::MessageLoop::current()); |
| 176 } | 120 } |
| 177 | 121 |
| 178 Context::~Context() { | 122 Context::~Context() { |
| 179 DCHECK(!base::MessageLoop::current()); | 123 DCHECK(!base::MessageLoop::current()); |
| 180 } | 124 } |
| 181 | 125 |
| 182 void Context::EnsureEmbedderIsInitialized() { | 126 void Context::EnsureEmbedderIsInitialized() { |
| 183 setup.Get(); | 127 setup.Get(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); | 167 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); |
| 224 else | 168 else |
| 225 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); | 169 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); |
| 226 | 170 |
| 227 DynamicApplicationLoader* dynamic_application_loader = | 171 DynamicApplicationLoader* dynamic_application_loader = |
| 228 new DynamicApplicationLoader(this, runner_factory.Pass()); | 172 new DynamicApplicationLoader(this, runner_factory.Pass()); |
| 229 InitContentHandlers(dynamic_application_loader, command_line); | 173 InitContentHandlers(dynamic_application_loader, command_line); |
| 230 application_manager_.set_default_loader( | 174 application_manager_.set_default_loader( |
| 231 scoped_ptr<ApplicationLoader>(dynamic_application_loader)); | 175 scoped_ptr<ApplicationLoader>(dynamic_application_loader)); |
| 232 | 176 |
| 233 // The native viewport service synchronously waits for certain messages. If we | |
| 234 // don't run it on its own thread we can easily deadlock. Long term native | |
| 235 // viewport should run its own process so that this isn't an issue. | |
| 236 #if defined(OS_ANDROID) | |
| 237 application_manager_.SetLoaderForURL( | |
| 238 scoped_ptr<ApplicationLoader>(new UIApplicationLoader( | |
| 239 scoped_ptr<ApplicationLoader>(new NativeViewportApplicationLoader()), | |
| 240 this)), | |
| 241 GURL("mojo:native_viewport_service")); | |
| 242 #endif | |
| 243 | |
| 244 if (command_line->HasSwitch(switches::kSpy)) { | 177 if (command_line->HasSwitch(switches::kSpy)) { |
| 245 spy_.reset( | 178 spy_.reset( |
| 246 new mojo::Spy(&application_manager_, | 179 new mojo::Spy(&application_manager_, |
| 247 command_line->GetSwitchValueASCII(switches::kSpy))); | 180 command_line->GetSwitchValueASCII(switches::kSpy))); |
| 248 // TODO(cpu): the spy can snoop, but can't tell anybody until | 181 // TODO(cpu): the spy can snoop, but can't tell anybody until |
| 249 // the Spy::WebSocketDelegate is implemented. In the original repo this | 182 // the Spy::WebSocketDelegate is implemented. In the original repo this |
| 250 // was implemented by src\mojo\spy\websocket_server.h and .cc. | 183 // was implemented by src\mojo\spy\websocket_server.h and .cc. |
| 251 } | 184 } |
| 252 | 185 |
| 253 #if defined(OS_ANDROID) | |
| 254 { | |
| 255 // Android handler is bundled with the Mojo shell, because it uses the | |
| 256 // MojoShell application as the JNI bridge to bootstrap execution of other | |
| 257 // Android Mojo apps that need JNI. | |
| 258 scoped_ptr<BackgroundShellApplicationLoader> loader( | |
| 259 new BackgroundShellApplicationLoader( | |
| 260 scoped_ptr<ApplicationLoader>(new AndroidHandlerLoader()), | |
| 261 "android_handler", base::MessageLoop::TYPE_DEFAULT)); | |
| 262 application_manager_.SetLoaderForURL(loader.Pass(), | |
| 263 GURL("mojo:android_handler")); | |
| 264 } | |
| 265 #endif | |
| 266 | |
| 267 tracing::TraceDataCollectorPtr trace_data_collector_ptr; | 186 tracing::TraceDataCollectorPtr trace_data_collector_ptr; |
| 268 application_manager_.ConnectToService(GURL("mojo:tracing"), | 187 application_manager_.ConnectToService(GURL("mojo:tracing"), |
| 269 &trace_data_collector_ptr); | 188 &trace_data_collector_ptr); |
| 270 TracingImpl::Create(trace_data_collector_ptr.Pass()); | 189 TracingImpl::Create(trace_data_collector_ptr.Pass()); |
| 271 | 190 |
| 272 if (listener_) | 191 if (listener_) |
| 273 listener_->WaitForListening(); | 192 listener_->WaitForListening(); |
| 274 | 193 |
| 275 return true; | 194 return true; |
| 276 } | 195 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 299 ScopedMessagePipeHandle Context::ConnectToServiceByName( | 218 ScopedMessagePipeHandle Context::ConnectToServiceByName( |
| 300 const GURL& application_url, | 219 const GURL& application_url, |
| 301 const std::string& service_name) { | 220 const std::string& service_name) { |
| 302 app_urls_.insert(application_url); | 221 app_urls_.insert(application_url); |
| 303 return application_manager_.ConnectToServiceByName(application_url, | 222 return application_manager_.ConnectToServiceByName(application_url, |
| 304 service_name).Pass(); | 223 service_name).Pass(); |
| 305 } | 224 } |
| 306 | 225 |
| 307 } // namespace shell | 226 } // namespace shell |
| 308 } // namespace mojo | 227 } // namespace mojo |
| OLD | NEW |