| 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/shell/context.h" | 5 #include "mojo/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 28 matching lines...) Expand all Loading... |
| 39 #include "ui/gl/gl_share_group.h" | 39 #include "ui/gl/gl_share_group.h" |
| 40 #endif // defined(OS_ANDROID) | 40 #endif // defined(OS_ANDROID) |
| 41 | 41 |
| 42 namespace mojo { | 42 namespace mojo { |
| 43 namespace shell { | 43 namespace shell { |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 // These mojo: URLs are loaded directly from the local filesystem. They | 46 // These mojo: URLs are loaded directly from the local filesystem. They |
| 47 // correspond to shared libraries bundled alongside the mojo_shell. | 47 // correspond to shared libraries bundled alongside the mojo_shell. |
| 48 const char* kLocalMojoURLs[] = { | 48 const char* kLocalMojoURLs[] = { |
| 49 "mojo:mojo_network_service", | 49 "mojo:network_service", |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // Used to ensure we only init once. | 52 // Used to ensure we only init once. |
| 53 class Setup { | 53 class Setup { |
| 54 public: | 54 public: |
| 55 Setup() { | 55 Setup() { |
| 56 embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( | 56 embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( |
| 57 new mojo::embedder::SimplePlatformSupport())); | 57 new mojo::embedder::SimplePlatformSupport())); |
| 58 } | 58 } |
| 59 | 59 |
| 60 ~Setup() { | 60 ~Setup() { |
| 61 } | 61 } |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(Setup); | 64 DISALLOW_COPY_AND_ASSIGN(Setup); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; | 67 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; |
| 68 | 68 |
| 69 void InitContentHandlers(DynamicApplicationLoader* loader, | 69 void InitContentHandlers(DynamicApplicationLoader* loader, |
| 70 base::CommandLine* command_line) { | 70 base::CommandLine* command_line) { |
| 71 // Default content handlers. | 71 // Default content handlers. |
| 72 loader->RegisterContentHandler("image/png", GURL("mojo://mojo_png_viewer/")); | 72 loader->RegisterContentHandler("image/png", GURL("mojo://png_viewer/")); |
| 73 loader->RegisterContentHandler("text/html", GURL("mojo://mojo_html_viewer/")); | 73 loader->RegisterContentHandler("text/html", GURL("mojo://html_viewer/")); |
| 74 | 74 |
| 75 // Command-line-specified content handlers. | 75 // Command-line-specified content handlers. |
| 76 std::string handlers_spec = command_line->GetSwitchValueASCII( | 76 std::string handlers_spec = command_line->GetSwitchValueASCII( |
| 77 switches::kContentHandlers); | 77 switches::kContentHandlers); |
| 78 if (handlers_spec.empty()) | 78 if (handlers_spec.empty()) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 std::vector<std::string> parts; | 81 std::vector<std::string> parts; |
| 82 base::SplitString(handlers_spec, ',', &parts); | 82 base::SplitString(handlers_spec, ',', &parts); |
| 83 if (parts.size() % 2 != 0) { | 83 if (parts.size() % 2 != 0) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 scoped_ptr<ApplicationLoader>(dynamic_application_loader)); | 205 scoped_ptr<ApplicationLoader>(dynamic_application_loader)); |
| 206 | 206 |
| 207 // The native viewport service synchronously waits for certain messages. If we | 207 // The native viewport service synchronously waits for certain messages. If we |
| 208 // don't run it on its own thread we can easily deadlock. Long term native | 208 // don't run it on its own thread we can easily deadlock. Long term native |
| 209 // viewport should run its own process so that this isn't an issue. | 209 // viewport should run its own process so that this isn't an issue. |
| 210 #if defined(OS_ANDROID) | 210 #if defined(OS_ANDROID) |
| 211 application_manager_.SetLoaderForURL( | 211 application_manager_.SetLoaderForURL( |
| 212 scoped_ptr<ApplicationLoader>(new UIApplicationLoader( | 212 scoped_ptr<ApplicationLoader>(new UIApplicationLoader( |
| 213 scoped_ptr<ApplicationLoader>(new NativeViewportApplicationLoader()), | 213 scoped_ptr<ApplicationLoader>(new NativeViewportApplicationLoader()), |
| 214 this)), | 214 this)), |
| 215 GURL("mojo:mojo_native_viewport_service")); | 215 GURL("mojo:native_viewport_service")); |
| 216 #endif | 216 #endif |
| 217 | 217 |
| 218 if (command_line->HasSwitch(switches::kSpy)) { | 218 if (command_line->HasSwitch(switches::kSpy)) { |
| 219 spy_.reset( | 219 spy_.reset( |
| 220 new mojo::Spy(&application_manager_, | 220 new mojo::Spy(&application_manager_, |
| 221 command_line->GetSwitchValueASCII(switches::kSpy))); | 221 command_line->GetSwitchValueASCII(switches::kSpy))); |
| 222 // TODO(cpu): the spy can snoop, but can't tell anybody until | 222 // TODO(cpu): the spy can snoop, but can't tell anybody until |
| 223 // the Spy::WebSocketDelegate is implemented. In the original repo this | 223 // the Spy::WebSocketDelegate is implemented. In the original repo this |
| 224 // was implemented by src\mojo\spy\websocket_server.h and .cc. | 224 // was implemented by src\mojo\spy\websocket_server.h and .cc. |
| 225 } | 225 } |
| 226 | 226 |
| 227 #if defined(OS_ANDROID) | 227 #if defined(OS_ANDROID) |
| 228 // On android, the network service is bundled with the shell because the | 228 // On android, the network service is bundled with the shell because the |
| 229 // network stack depends on the android runtime. | 229 // network stack depends on the android runtime. |
| 230 { | 230 { |
| 231 scoped_ptr<BackgroundShellApplicationLoader> loader( | 231 scoped_ptr<BackgroundShellApplicationLoader> loader( |
| 232 new BackgroundShellApplicationLoader( | 232 new BackgroundShellApplicationLoader( |
| 233 scoped_ptr<ApplicationLoader>(new NetworkApplicationLoader()), | 233 scoped_ptr<ApplicationLoader>(new NetworkApplicationLoader()), |
| 234 "network_service", | 234 "network_service", |
| 235 base::MessageLoop::TYPE_IO)); | 235 base::MessageLoop::TYPE_IO)); |
| 236 application_manager_.SetLoaderForURL(loader.Pass(), | 236 application_manager_.SetLoaderForURL(loader.Pass(), |
| 237 GURL("mojo:mojo_network_service")); | 237 GURL("mojo:network_service")); |
| 238 } | 238 } |
| 239 #endif | 239 #endif |
| 240 | 240 |
| 241 if (listener_) | 241 if (listener_) |
| 242 listener_->WaitForListening(); | 242 listener_->WaitForListening(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void Context::OnApplicationError(const GURL& gurl) { | 245 void Context::OnApplicationError(const GURL& gurl) { |
| 246 if (app_urls_.find(gurl) != app_urls_.end()) { | 246 if (app_urls_.find(gurl) != app_urls_.end()) { |
| 247 app_urls_.erase(gurl); | 247 app_urls_.erase(gurl); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 262 ScopedMessagePipeHandle Context::ConnectToServiceByName( | 262 ScopedMessagePipeHandle Context::ConnectToServiceByName( |
| 263 const GURL& application_url, | 263 const GURL& application_url, |
| 264 const std::string& service_name) { | 264 const std::string& service_name) { |
| 265 app_urls_.insert(application_url); | 265 app_urls_.insert(application_url); |
| 266 return application_manager_.ConnectToServiceByName( | 266 return application_manager_.ConnectToServiceByName( |
| 267 application_url, service_name).Pass(); | 267 application_url, service_name).Pass(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // namespace shell | 270 } // namespace shell |
| 271 } // namespace mojo | 271 } // namespace mojo |
| OLD | NEW |