OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
Ted C
2012/05/09 00:26:41
2012
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/android/command_line.h" | |
6 | |
7 #include "base/android/jni_string.h" | |
8 #include "base/command_line.h" | |
9 #include "base/logging.h" | |
10 #include "jni/command_line_jni.h" | |
11 #include "content/browser/android/jni_helper.h" | |
12 | |
13 using base::android::ConvertJavaStringToUTF8; | |
14 | |
15 namespace { | |
16 | |
17 void AppendJavaStringArrayToCommandLine(JNIEnv* env, | |
18 jobjectArray array, | |
19 bool includes_program) { | |
20 CommandLine::StringVector vec; | |
21 if (array) | |
22 ConvertJavaArrayOfStringsToVectorOfStrings(env, array, &vec); | |
23 if (!includes_program) | |
24 vec.insert(vec.begin(), ""); | |
25 CommandLine extra_command_line(vec); | |
26 CommandLine::ForCurrentProcess()->AppendArguments(extra_command_line, | |
27 includes_program); | |
28 } | |
29 | |
30 } // namespace | |
31 | |
32 static void Reset(JNIEnv* env, jclass clazz) { | |
33 CommandLine::Reset(); | |
34 } | |
35 | |
36 static jboolean HasSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { | |
37 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | |
38 return CommandLine::ForCurrentProcess()->HasSwitch(switch_string); | |
39 } | |
40 | |
41 static jstring GetSwitchValue(JNIEnv* env, jclass clazz, jstring jswitch) { | |
42 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | |
43 std::string value(CommandLine::ForCurrentProcess()->GetSwitchValueNative( | |
44 switch_string)); | |
45 if (value.empty()) | |
46 return 0; | |
47 // OK to release, JNI binding. | |
48 return base::android::ConvertUTF8ToJavaString(env, value).Release(); | |
49 } | |
50 | |
51 static void AppendSwitch(JNIEnv* env, jclass clazz, jstring jswitch) { | |
52 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | |
53 CommandLine::ForCurrentProcess()->AppendSwitch(switch_string); | |
54 } | |
55 | |
56 static void AppendSwitchWithValue(JNIEnv* env, jclass clazz, | |
57 jstring jswitch, jstring jvalue) { | |
58 std::string switch_string(ConvertJavaStringToUTF8(env, jswitch)); | |
59 std::string value_string (ConvertJavaStringToUTF8(env, jvalue)); | |
60 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switch_string, | |
61 value_string); | |
62 } | |
63 | |
64 static void AppendSwitchesAndArguments(JNIEnv* env, jclass clazz, | |
65 jobjectArray array) { | |
66 AppendJavaStringArrayToCommandLine(env, array, false); | |
67 } | |
68 | |
69 void InitNativeCommandLineFromJavaArray(JNIEnv* env, jobjectArray array) { | |
70 // TODO(port): Make an overload of Init() that takes StringVector rather than | |
71 // have to round-trip via AppendArguments. | |
72 CommandLine::Init(0, NULL); | |
73 AppendJavaStringArrayToCommandLine(env, array, true); | |
74 } | |
75 | |
76 bool RegisterCommandLine(JNIEnv* env) { | |
77 return RegisterNativesImpl(env); | |
78 } | |
OLD | NEW |