| Index: mojo/shell/android/apk/src/org/chromium/mojo/shell/ShellMain.java
|
| diff --git a/mojo/shell/android/apk/src/org/chromium/mojo/shell/ShellMain.java b/mojo/shell/android/apk/src/org/chromium/mojo/shell/ShellMain.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1f55fa2c86776366a1b887e3f90d2a46f8325e57
|
| --- /dev/null
|
| +++ b/mojo/shell/android/apk/src/org/chromium/mojo/shell/ShellMain.java
|
| @@ -0,0 +1,105 @@
|
| +// Copyright 2013 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.
|
| +
|
| +package org.chromium.mojo.shell;
|
| +
|
| +import android.app.Activity;
|
| +import android.content.Context;
|
| +import android.util.Log;
|
| +
|
| +import org.chromium.base.CalledByNative;
|
| +import org.chromium.base.JNINamespace;
|
| +
|
| +import java.io.File;
|
| +import java.util.ArrayList;
|
| +import java.util.Arrays;
|
| +import java.util.List;
|
| +
|
| +/**
|
| + * A placeholder class to call native functions.
|
| + **/
|
| +@JNINamespace("mojo::shell")
|
| +public class ShellMain {
|
| + private static final String TAG = "ShellMain";
|
| +
|
| + // Directory where applications bundled with the shell will be extracted.
|
| + private static final String LOCAL_APP_DIRECTORY = "local_apps";
|
| + // Individual applications bundled with the shell as assets.
|
| + private static final String NETWORK_LIBRARY_APP = "network_service.mojo";
|
| + // The mojo_shell library is also an executable run in forked processes when running
|
| + // multi-process.
|
| + private static final String MOJO_SHELL_EXECUTABLE = "libmojo_shell.so";
|
| +
|
| + /**
|
| + * A guard flag for calling nativeInit() only once.
|
| + **/
|
| + private static boolean sInitialized = false;
|
| +
|
| + /**
|
| + * Initializes the native system.
|
| + **/
|
| + static void ensureInitialized(Context applicationContext, String[] parameters) {
|
| + if (sInitialized) return;
|
| + try {
|
| + FileHelper.extractFromAssets(applicationContext, NETWORK_LIBRARY_APP,
|
| + getLocalAppsDir(applicationContext), false);
|
| + File mojoShell = new File(applicationContext.getApplicationInfo().nativeLibraryDir,
|
| + MOJO_SHELL_EXECUTABLE);
|
| +
|
| + List<String> parametersList = new ArrayList<String>();
|
| + // Program name.
|
| + if (parameters != null) {
|
| + parametersList.addAll(Arrays.asList(parameters));
|
| + }
|
| +
|
| + nativeInit(applicationContext, mojoShell.getAbsolutePath(),
|
| + parametersList.toArray(new String[parametersList.size()]),
|
| + getLocalAppsDir(applicationContext).getAbsolutePath(),
|
| + getTmpDir(applicationContext).getAbsolutePath());
|
| + sInitialized = true;
|
| + } catch (Exception e) {
|
| + Log.e(TAG, "ShellMain initialization failed.", e);
|
| + throw new RuntimeException(e);
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Starts the specified application in the specified context.
|
| + *
|
| + * @return <code>true</code> if an application has been launched.
|
| + **/
|
| + static boolean start() {
|
| + return nativeStart();
|
| + }
|
| +
|
| + /**
|
| + * Adds the given URL to the set of mojo applications to run on start.
|
| + */
|
| + static void addApplicationURL(String url) {
|
| + nativeAddApplicationURL(url);
|
| + }
|
| +
|
| + private static File getLocalAppsDir(Context context) {
|
| + return context.getDir(LOCAL_APP_DIRECTORY, Context.MODE_PRIVATE);
|
| + }
|
| +
|
| + private static File getTmpDir(Context context) {
|
| + return new File(context.getCacheDir(), "tmp");
|
| + }
|
| +
|
| + @CalledByNative
|
| + private static void finishActivity(Activity activity) {
|
| + activity.finish();
|
| + }
|
| +
|
| + /**
|
| + * Initializes the native system. This API should be called only once per process.
|
| + **/
|
| + private static native void nativeInit(Context context, String mojoShellPath,
|
| + String[] parameters, String bundledAppsDirectory, String tmpDir);
|
| +
|
| + private static native boolean nativeStart();
|
| +
|
| + private static native void nativeAddApplicationURL(String url);
|
| +}
|
|
|