| 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/android/mojo_main.h" | 5 #include "mojo/shell/android/mojo_main.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "jni/MojoMain_jni.h" | 14 #include "jni/MojoMain_jni.h" |
| 15 #include "mojo/services/native_viewport/native_viewport_service.h" |
| 15 #include "mojo/shell/context.h" | 16 #include "mojo/shell/context.h" |
| 16 #include "mojo/shell/init.h" | 17 #include "mojo/shell/init.h" |
| 17 #include "mojo/shell/run.h" | 18 #include "mojo/shell/run.h" |
| 19 #include "mojo/shell/service_manager.h" |
| 18 #include "ui/gl/gl_surface_egl.h" | 20 #include "ui/gl/gl_surface_egl.h" |
| 19 | 21 |
| 20 using base::LazyInstance; | 22 using base::LazyInstance; |
| 21 | 23 |
| 22 namespace mojo { | 24 namespace mojo { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 base::AtExitManager* g_at_exit = 0; | 28 base::AtExitManager* g_at_exit = 0; |
| 27 | 29 |
| 28 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop = | 30 LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop = |
| 29 LAZY_INSTANCE_INITIALIZER; | 31 LAZY_INSTANCE_INITIALIZER; |
| 30 | 32 |
| 31 LazyInstance<scoped_ptr<shell::Context> > g_context = | 33 LazyInstance<scoped_ptr<shell::Context> > g_context = |
| 32 LAZY_INSTANCE_INITIALIZER; | 34 LAZY_INSTANCE_INITIALIZER; |
| 33 | 35 |
| 36 class NativeViewportServiceLoader : public shell::ServiceManager::Loader { |
| 37 public: |
| 38 NativeViewportServiceLoader() {} |
| 39 virtual ~NativeViewportServiceLoader() {} |
| 40 |
| 41 private: |
| 42 virtual void Load(const GURL& url, |
| 43 shell::ServiceManager* manager, |
| 44 ScopedMessagePipeHandle service_handle) |
| 45 MOJO_OVERRIDE { |
| 46 service_.reset(CreateNativeViewportService(service_handle.Pass())); |
| 47 service_->set_context(g_context.Get().get()); |
| 48 } |
| 49 scoped_ptr<services::NativeViewportService> service_; |
| 50 }; |
| 51 |
| 52 LazyInstance<scoped_ptr<NativeViewportServiceLoader> > |
| 53 g_viewport_service_loader = LAZY_INSTANCE_INITIALIZER; |
| 54 |
| 34 } // namspace | 55 } // namspace |
| 35 | 56 |
| 36 static void Init(JNIEnv* env, jclass clazz, jobject context) { | 57 static void Init(JNIEnv* env, jclass clazz, jobject context) { |
| 37 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); | 58 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); |
| 38 | 59 |
| 39 base::android::InitApplicationContext(env, scoped_context); | 60 base::android::InitApplicationContext(env, scoped_context); |
| 40 | 61 |
| 41 if (g_at_exit) | 62 if (g_at_exit) |
| 42 return; | 63 return; |
| 43 g_at_exit = new base::AtExitManager(); | 64 g_at_exit = new base::AtExitManager(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 // initialization? | 75 // initialization? |
| 55 | 76 |
| 56 gfx::GLSurface::InitializeOneOff(); | 77 gfx::GLSurface::InitializeOneOff(); |
| 57 } | 78 } |
| 58 | 79 |
| 59 static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) { | 80 static void Start(JNIEnv* env, jclass clazz, jobject context, jstring jurl) { |
| 60 if (jurl) { | 81 if (jurl) { |
| 61 std::string app_url = base::android::ConvertJavaStringToUTF8(env, jurl); | 82 std::string app_url = base::android::ConvertJavaStringToUTF8(env, jurl); |
| 62 std::vector<std::string> argv; | 83 std::vector<std::string> argv; |
| 63 argv.push_back("mojo_shell"); | 84 argv.push_back("mojo_shell"); |
| 64 argv.push_back("--app=" + app_url); | 85 argv.push_back(app_url); |
| 65 CommandLine::ForCurrentProcess()->InitFromArgv(argv); | 86 CommandLine::ForCurrentProcess()->InitFromArgv(argv); |
| 66 } | 87 } |
| 67 | 88 |
| 68 base::android::ScopedJavaGlobalRef<jobject> activity; | 89 base::android::ScopedJavaGlobalRef<jobject> activity; |
| 69 activity.Reset(env, context); | 90 activity.Reset(env, context); |
| 70 | 91 |
| 71 shell::Context* shell_context = new shell::Context(); | 92 shell::Context* shell_context = new shell::Context(); |
| 72 shell_context->set_activity(activity.obj()); | 93 shell_context->set_activity(activity.obj()); |
| 94 g_viewport_service_loader.Get().reset(new NativeViewportServiceLoader()); |
| 95 shell_context->service_manager()->SetLoaderForURL( |
| 96 g_viewport_service_loader.Get().get(), |
| 97 GURL("mojo:mojo_native_viewport_service")); |
| 98 |
| 73 g_context.Get().reset(shell_context); | 99 g_context.Get().reset(shell_context); |
| 74 shell::Run(shell_context); | 100 shell::Run(shell_context); |
| 75 } | 101 } |
| 76 | 102 |
| 77 bool RegisterMojoMain(JNIEnv* env) { | 103 bool RegisterMojoMain(JNIEnv* env) { |
| 78 return RegisterNativesImpl(env); | 104 return RegisterNativesImpl(env); |
| 79 } | 105 } |
| 80 | 106 |
| 81 } // namespace mojo | 107 } // namespace mojo |
| OLD | NEW |