| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/common/android/command_line.h" | 5 #include "base/android/command_line.h" |
| 6 | 6 |
| 7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "jni/CommandLine_jni.h" | 11 #include "jni/CommandLine_jni.h" |
| 12 | 12 |
| 13 using base::android::AppendJavaStringArrayToStringVector; | 13 using base::android::ConvertUTF8ToJavaString; |
| 14 using base::android::ConvertJavaStringToUTF8; | 14 using base::android::ConvertJavaStringToUTF8; |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 void AppendJavaStringArrayToCommandLine(JNIEnv* env, | 18 void AppendJavaStringArrayToCommandLine(JNIEnv* env, |
| 19 jobjectArray array, | 19 jobjectArray array, |
| 20 bool includes_program) { | 20 bool includes_program) { |
| 21 std::vector<std::string> vec; | 21 std::vector<std::string> vec; |
| 22 if (array) | 22 if (array) |
| 23 AppendJavaStringArrayToStringVector(env, array, &vec); | 23 base::android::AppendJavaStringArrayToStringVector(env, array, &vec); |
| 24 if (!includes_program) | 24 if (!includes_program) |
| 25 vec.insert(vec.begin(), ""); | 25 vec.insert(vec.begin(), ""); |
| 26 CommandLine extra_command_line(vec); | 26 CommandLine extra_command_line(vec); |
| 27 CommandLine::ForCurrentProcess()->AppendArguments(extra_command_line, | 27 CommandLine::ForCurrentProcess()->AppendArguments(extra_command_line, |
| 28 includes_program); | 28 includes_program); |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 static void Reset(JNIEnv* env, jclass clazz) { | 33 static void Reset(JNIEnv* env, jclass clazz) { |
| 34 CommandLine::Reset(); | 34 CommandLine::Reset(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 static jboolean HasSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { | 37 static jboolean HasSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { |
| 38 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | 38 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); |
| 39 return CommandLine::ForCurrentProcess()->HasSwitch(switch_string); | 39 return CommandLine::ForCurrentProcess()->HasSwitch(switch_string); |
| 40 } | 40 } |
| 41 | 41 |
| 42 static jstring GetSwitchValue(JNIEnv* env, jclass clazz, jstring jswitch) { | 42 static jstring GetSwitchValue(JNIEnv* env, jclass clazz, jstring jswitch) { |
| 43 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | 43 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); |
| 44 std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueNative( | 44 std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueNative( |
| 45 switch_string)); | 45 switch_string)); |
| 46 if (value.empty()) | 46 if (value.empty()) |
| 47 return 0; | 47 return 0; |
| 48 // OK to release, JNI binding. | 48 // OK to release, JNI binding. |
| 49 return base::android::ConvertUTF8ToJavaString(env, value).Release(); | 49 return ConvertUTF8ToJavaString(env, value).Release(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 static void AppendSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { | 52 static void AppendSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { |
| 53 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | 53 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); |
| 54 CommandLine::ForCurrentProcess()->AppendSwitch(switch_string); | 54 CommandLine::ForCurrentProcess()->AppendSwitch(switch_string); |
| 55 } | 55 } |
| 56 | 56 |
| 57 static void AppendSwitchWithValue(JNIEnv* env, jclass clazz, | 57 static void AppendSwitchWithValue(JNIEnv* env, jclass clazz, |
| 58 jstring jswitch, jstring jvalue) { | 58 jstring jswitch, jstring jvalue) { |
| 59 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | 59 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); |
| 60 std::string value_string (ConvertJavaStringToUTF8(env, jvalue)); | 60 std::string value_string (ConvertJavaStringToUTF8(env, jvalue)); |
| 61 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switch_string, | 61 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switch_string, |
| 62 value_string); | 62 value_string); |
| 63 } | 63 } |
| 64 | 64 |
| 65 static void AppendSwitchesAndArguments(JNIEnv* env, jclass clazz, | 65 static void AppendSwitchesAndArguments(JNIEnv* env, jclass clazz, |
| 66 jobjectArray array) { | 66 jobjectArray array) { |
| 67 AppendJavaStringArrayToCommandLine(env, array, false); | 67 AppendJavaStringArrayToCommandLine(env, array, false); |
| 68 } | 68 } |
| 69 | 69 |
| 70 namespace base { |
| 71 namespace android { |
| 72 |
| 70 void InitNativeCommandLineFromJavaArray(JNIEnv* env, jobjectArray array) { | 73 void InitNativeCommandLineFromJavaArray(JNIEnv* env, jobjectArray array) { |
| 71 // TODO(port): Make an overload of Init() that takes StringVector rather than | 74 // TODO(port): Make an overload of Init() that takes StringVector rather than |
| 72 // have to round-trip via AppendArguments. | 75 // have to round-trip via AppendArguments. |
| 73 CommandLine::Init(0, NULL); | 76 CommandLine::Init(0, NULL); |
| 74 AppendJavaStringArrayToCommandLine(env, array, true); | 77 AppendJavaStringArrayToCommandLine(env, array, true); |
| 75 } | 78 } |
| 76 | 79 |
| 77 bool RegisterCommandLine(JNIEnv* env) { | 80 bool RegisterCommandLine(JNIEnv* env) { |
| 78 return RegisterNativesImpl(env); | 81 return RegisterNativesImpl(env); |
| 79 } | 82 } |
| 83 |
| 84 } // namespace android |
| 85 } // namespace base |
| OLD | NEW |