OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.mojo.shell; |
| 6 |
| 7 import android.app.Activity; |
| 8 import android.content.Intent; |
| 9 import android.os.Bundle; |
| 10 import android.util.JsonReader; |
| 11 import android.util.Log; |
| 12 |
| 13 import java.io.IOException; |
| 14 import java.io.StringReader; |
| 15 import java.util.ArrayList; |
| 16 import java.util.List; |
| 17 |
| 18 /** |
| 19 * Activity for managing the Mojo Shell. |
| 20 */ |
| 21 public class MojoShellActivity extends Activity { |
| 22 private static final String TAG = "MojoShellActivity"; |
| 23 |
| 24 @Override |
| 25 protected void onCreate(final Bundle savedInstanceState) { |
| 26 super.onCreate(savedInstanceState); |
| 27 |
| 28 // TODO(ppi): Gotcha - the call below will work only once per process li
fetime, but the OS |
| 29 // has no obligation to kill the application process between destroying
and restarting the |
| 30 // activity. If the application process is kept alive, initialization pa
rameters sent with |
| 31 // the intent will be stale. |
| 32 // TODO(qsr): We should be passing application context here as required
by |
| 33 // InitApplicationContext on the native side. Currently we can't, as Pla
tformViewportAndroid |
| 34 // relies on this being the activity context. |
| 35 ShellMain.ensureInitialized(this, getParametersFromIntent(getIntent())); |
| 36 |
| 37 // TODO(eseidel): ShellMain can fail, but we're ignoring the return. |
| 38 ShellMain.start(); |
| 39 } |
| 40 |
| 41 private static String[] getParametersFromIntent(Intent intent) { |
| 42 if (intent == null) { |
| 43 return null; |
| 44 } |
| 45 String[] parameters = intent.getStringArrayExtra("parameters"); |
| 46 if (parameters != null) { |
| 47 return parameters; |
| 48 } |
| 49 String encodedParameters = intent.getStringExtra("encodedParameters"); |
| 50 if (encodedParameters != null) { |
| 51 JsonReader reader = new JsonReader(new StringReader(encodedParameter
s)); |
| 52 List<String> parametersList = new ArrayList<String>(); |
| 53 try { |
| 54 reader.beginArray(); |
| 55 while (reader.hasNext()) { |
| 56 parametersList.add(reader.nextString()); |
| 57 } |
| 58 reader.endArray(); |
| 59 reader.close(); |
| 60 return parametersList.toArray(new String[parametersList.size()])
; |
| 61 } catch (IOException e) { |
| 62 Log.w(TAG, e.getMessage(), e); |
| 63 } |
| 64 } |
| 65 return null; |
| 66 } |
| 67 } |
OLD | NEW |