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