Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Side by Side Diff: shell/android/task_launcher/task_launcher.cc

Issue 1280613003: Allow native_viewport to create new native windows on demand on Android. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Refactor Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // task_launcher is an application needed by the android shell. Its purpose is
6 // to create new android tasks (a.k.a. windows) upon request by the native
7 // viewport service.
8
9 #include "jni/TaskLauncher_jni.h"
10 #include "mojo/common/binding_set.h"
11 #include "mojo/public/c/system/main.h"
12 #include "mojo/public/cpp/application/application_connection.h"
13 #include "mojo/public/cpp/application/application_delegate.h"
14 #include "mojo/public/cpp/application/application_runner.h"
15 #include "services/native_viewport/native_viewport.mojom.h"
16
17 namespace shell {
18 namespace android {
19 namespace task_launcher {
20
21 bool RegisterTaskLauncherJni(JNIEnv* env) {
22 return RegisterNativesImpl(env);
23 }
24
25 class TaskLauncherAppDelegate
26 : public mojo::ApplicationDelegate,
27 public native_viewport::NativeViewportShellService,
28 public mojo::InterfaceFactory<
29 native_viewport::NativeViewportShellService> {
30 public:
31 bool ConfigureIncomingConnection(
32 mojo::ApplicationConnection* connection) override {
33 // Only accept connections from the native viewport service. Other apps
34 // should go through the native viewport application to obtain new surfaces
35 // to draw on.
36 if (connection->GetRemoteApplicationURL() !=
37 "mojo://native_viewport_service/") {
38 return false;
39 }
40 connection->AddService(this);
41 return true;
42 }
43
44 private:
45 // InterfaceFactory<native_viewport::NativeViewportShellService>
46 void Create(
47 mojo::ApplicationConnection* app,
48 mojo::InterfaceRequest<native_viewport::NativeViewportShellService>
49 request) override {
50 bindings_.AddBinding(this, request.Pass());
51 }
52
53 // native_viewport::NativeViewportShellService
54 void CreateNewNativeWindow() override {
55 JNIEnv* env = base::android::AttachCurrentThread();
56 jobject context = base::android::GetApplicationContext();
57 Java_TaskLauncher_sendIntent(env, context);
58 }
59
60 mojo::BindingSet<native_viewport::NativeViewportShellService> bindings_;
61 };
62
63 } // namespace task_launcher
64 } // namespace android
65 } // namespace shell
66
67 MojoResult MojoMain(MojoHandle application_request) {
68 mojo::ApplicationRunner runner(
69 new shell::android::task_launcher::TaskLauncherAppDelegate);
70 return runner.Run(application_request);
71 }
72
73 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
74 base::android::InitVM(vm);
75 JNIEnv* env = base::android::AttachCurrentThread();
76
77 if (!shell::android::task_launcher::RegisterTaskLauncherJni(env))
78 return -1;
79
80 return JNI_VERSION_1_4;
81 }
82
83 extern "C" JNI_EXPORT void InitApplicationContext(
84 const base::android::JavaRef<jobject>& context) {
85 JNIEnv* env = base::android::AttachCurrentThread();
86 base::android::InitApplicationContext(env, context);
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698