| Index: shell/android/task_launcher/task_launcher.cc
|
| diff --git a/shell/android/task_launcher/task_launcher.cc b/shell/android/task_launcher/task_launcher.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cfacca7e5f203e7b8c5eece26be39856407e61e5
|
| --- /dev/null
|
| +++ b/shell/android/task_launcher/task_launcher.cc
|
| @@ -0,0 +1,87 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +// task_launcher is an application needed by the android shell. Its purpose is
|
| +// to create new android tasks (a.k.a. windows) upon request by the native
|
| +// viewport service.
|
| +
|
| +#include "jni/TaskLauncher_jni.h"
|
| +#include "mojo/common/binding_set.h"
|
| +#include "mojo/public/c/system/main.h"
|
| +#include "mojo/public/cpp/application/application_connection.h"
|
| +#include "mojo/public/cpp/application/application_delegate.h"
|
| +#include "mojo/public/cpp/application/application_runner.h"
|
| +#include "services/native_viewport/native_viewport.mojom.h"
|
| +
|
| +namespace shell {
|
| +namespace android {
|
| +namespace task_launcher {
|
| +
|
| +bool RegisterTaskLauncherJni(JNIEnv* env) {
|
| + return RegisterNativesImpl(env);
|
| +}
|
| +
|
| +class TaskLauncherAppDelegate
|
| + : public mojo::ApplicationDelegate,
|
| + public native_viewport::NativeViewportShellService,
|
| + public mojo::InterfaceFactory<
|
| + native_viewport::NativeViewportShellService> {
|
| + public:
|
| + bool ConfigureIncomingConnection(
|
| + mojo::ApplicationConnection* connection) override {
|
| + // Only accept connections from the native viewport service. Other apps
|
| + // should go through the native viewport application to obtain new surfaces
|
| + // to draw on.
|
| + if (connection->GetRemoteApplicationURL() !=
|
| + "mojo://native_viewport_service/") {
|
| + return false;
|
| + }
|
| + connection->AddService(this);
|
| + return true;
|
| + }
|
| +
|
| + private:
|
| + // InterfaceFactory<native_viewport::NativeViewportShellService>
|
| + void Create(
|
| + mojo::ApplicationConnection* app,
|
| + mojo::InterfaceRequest<native_viewport::NativeViewportShellService>
|
| + request) override {
|
| + bindings_.AddBinding(this, request.Pass());
|
| + }
|
| +
|
| + // native_viewport::NativeViewportShellService
|
| + void CreateNewNativeWindow() override {
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + jobject context = base::android::GetApplicationContext();
|
| + Java_TaskLauncher_sendIntent(env, context);
|
| + }
|
| +
|
| + mojo::BindingSet<native_viewport::NativeViewportShellService> bindings_;
|
| +};
|
| +
|
| +} // namespace task_launcher
|
| +} // namespace android
|
| +} // namespace shell
|
| +
|
| +MojoResult MojoMain(MojoHandle application_request) {
|
| + mojo::ApplicationRunner runner(
|
| + new shell::android::task_launcher::TaskLauncherAppDelegate);
|
| + return runner.Run(application_request);
|
| +}
|
| +
|
| +JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
| + base::android::InitVM(vm);
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| +
|
| + if (!shell::android::task_launcher::RegisterTaskLauncherJni(env))
|
| + return -1;
|
| +
|
| + return JNI_VERSION_1_4;
|
| +}
|
| +
|
| +extern "C" JNI_EXPORT void InitApplicationContext(
|
| + const base::android::JavaRef<jobject>& context) {
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + base::android::InitApplicationContext(env, context);
|
| +}
|
|
|