OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/safe_json/json_sanitizer.h" | 5 #include "components/safe_json/json_sanitizer.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 OnError("Unsupported encoding"); | 66 OnError("Unsupported encoding"); |
67 return; | 67 return; |
68 } | 68 } |
69 | 69 |
70 JNIEnv* env = base::android::AttachCurrentThread(); | 70 JNIEnv* env = base::android::AttachCurrentThread(); |
71 base::android::ScopedJavaLocalRef<jstring> unsafe_json_java = | 71 base::android::ScopedJavaLocalRef<jstring> unsafe_json_java = |
72 base::android::ConvertUTF8ToJavaString(env, unsafe_json); | 72 base::android::ConvertUTF8ToJavaString(env, unsafe_json); |
73 | 73 |
74 // This will synchronously call either OnSuccess() or OnError(). | 74 // This will synchronously call either OnSuccess() or OnError(). |
75 Java_JsonSanitizer_sanitize(env, reinterpret_cast<jlong>(this), | 75 Java_JsonSanitizer_sanitize(env, reinterpret_cast<jlong>(this), |
76 unsafe_json_java.obj()); | 76 unsafe_json_java); |
77 } | 77 } |
78 | 78 |
79 void JsonSanitizerAndroid::OnSuccess(const std::string& json) { | 79 void JsonSanitizerAndroid::OnSuccess(const std::string& json) { |
80 base::SequencedTaskRunnerHandle::Get()->PostTask( | 80 base::SequencedTaskRunnerHandle::Get()->PostTask( |
81 FROM_HERE, base::Bind(success_callback_, json)); | 81 FROM_HERE, base::Bind(success_callback_, json)); |
82 } | 82 } |
83 | 83 |
84 void JsonSanitizerAndroid::OnError(const std::string& error) { | 84 void JsonSanitizerAndroid::OnError(const std::string& error) { |
85 base::SequencedTaskRunnerHandle::Get()->PostTask( | 85 base::SequencedTaskRunnerHandle::Get()->PostTask( |
86 FROM_HERE, base::Bind(error_callback_, error)); | 86 FROM_HERE, base::Bind(error_callback_, error)); |
(...skipping 29 matching lines...) Expand all Loading... |
116 JsonSanitizerAndroid sanitizer(success_callback, error_callback); | 116 JsonSanitizerAndroid sanitizer(success_callback, error_callback); |
117 sanitizer.Sanitize(unsafe_json); | 117 sanitizer.Sanitize(unsafe_json); |
118 } | 118 } |
119 | 119 |
120 // static | 120 // static |
121 bool JsonSanitizer::Register(JNIEnv* env) { | 121 bool JsonSanitizer::Register(JNIEnv* env) { |
122 return RegisterNativesImpl(env); | 122 return RegisterNativesImpl(env); |
123 } | 123 } |
124 | 124 |
125 } // namespace safe_json | 125 } // namespace safe_json |
OLD | NEW |