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 package org.chromium.mojo_shell_apk; | 5 package org.chromium.mojo_shell_apk; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.util.Log; | 8 import android.util.Log; |
9 | 9 |
10 import org.chromium.base.JNINamespace; | 10 import org.chromium.base.JNINamespace; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 if (sInitialized) | 49 if (sInitialized) |
50 return; | 50 return; |
51 try { | 51 try { |
52 FileHelper.extractFromAssets(applicationContext, NETWORK_LIBRARY_APP
, | 52 FileHelper.extractFromAssets(applicationContext, NETWORK_LIBRARY_APP
, |
53 getLocalAppsDir(applicationContext), false); | 53 getLocalAppsDir(applicationContext), false); |
54 File mojoShell = new File(applicationContext.getApplicationInfo().na
tiveLibraryDir, | 54 File mojoShell = new File(applicationContext.getApplicationInfo().na
tiveLibraryDir, |
55 MOJO_SHELL_EXECUTABLE); | 55 MOJO_SHELL_EXECUTABLE); |
56 | 56 |
57 List<String> parametersList = new ArrayList<String>(); | 57 List<String> parametersList = new ArrayList<String>(); |
58 // Program name. | 58 // Program name. |
59 parametersList.add("mojo_shell"); | |
60 if (parameters != null) { | 59 if (parameters != null) { |
61 parametersList.addAll(Arrays.asList(parameters)); | 60 parametersList.addAll(Arrays.asList(parameters)); |
62 } | 61 } |
63 | 62 |
64 nativeInit(applicationContext, | 63 nativeInit(applicationContext, |
65 mojoShell.getAbsolutePath(), | 64 mojoShell.getAbsolutePath(), |
66 parametersList.toArray(new String[parametersList.size()]), | 65 parametersList.toArray(new String[parametersList.size()]), |
67 getLocalAppsDir(applicationContext).getAbsolutePath()); | 66 getLocalAppsDir(applicationContext).getAbsolutePath()); |
68 sInitialized = true; | 67 sInitialized = true; |
69 } catch (Exception e) { | 68 } catch (Exception e) { |
70 Log.e(TAG, "MojoMain initialization failed.", e); | 69 Log.e(TAG, "MojoMain initialization failed.", e); |
71 throw new RuntimeException(e); | 70 throw new RuntimeException(e); |
72 } | 71 } |
73 } | 72 } |
74 | 73 |
75 /** | 74 /** |
76 * Starts the specified application in the specified context. | 75 * Starts the specified application in the specified context. |
| 76 * |
| 77 * @return <code>true</code> if an application has been launched. |
77 **/ | 78 **/ |
78 static void start(final String appUrl) { | 79 static boolean start() { |
79 nativeStart(appUrl); | 80 return nativeStart(); |
| 81 } |
| 82 |
| 83 /** |
| 84 * Adds the given URL to the set of mojo applications to run on start. |
| 85 */ |
| 86 static void addApplicationURL(String url) { |
| 87 nativeAddApplicationURL(url); |
80 } | 88 } |
81 | 89 |
82 private static File getLocalAppsDir(Context context) { | 90 private static File getLocalAppsDir(Context context) { |
83 return context.getDir(LOCAL_APP_DIRECTORY, Context.MODE_PRIVATE); | 91 return context.getDir(LOCAL_APP_DIRECTORY, Context.MODE_PRIVATE); |
84 } | 92 } |
85 | 93 |
86 /** | 94 /** |
87 * Initializes the native system. This API should be called only once per pr
ocess. | 95 * Initializes the native system. This API should be called only once per pr
ocess. |
88 **/ | 96 **/ |
89 private static native void nativeInit(Context context, String mojoShellPath, | 97 private static native void nativeInit(Context context, String mojoShellPath, |
90 String[] parameters, | 98 String[] parameters, |
91 String bundledAppsDirectory); | 99 String bundledAppsDirectory); |
92 | 100 |
93 private static native void nativeStart(String appUrl); | 101 private static native boolean nativeStart(); |
94 | 102 |
| 103 private static native void nativeAddApplicationURL(String url); |
95 } | 104 } |
OLD | NEW |