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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SAFE_JSON_JSON_SANITIZER_H_
6 #define COMPONENTS_SAFE_JSON_JSON_SANITIZER_H_
10 #include "base/callback_forward.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
14 #if defined(OS_ANDROID)
20 // Sanitizes and normalizes JSON by parsing it in a safe environment and
21 // re-serializing it. Parsing the sanitized JSON should result in a value
22 // identical to parsing the original JSON.
23 // This allows parsing the sanitized JSON with the regular JSONParser while
24 // reducing the risk versus parsing completely untrusted JSON. It also minifies
25 // the resulting JSON, which might save some space.
28 using StringCallback
= base::Callback
<void(const std::string
&)>;
30 // Starts sanitizing the passed in unsafe JSON string. Either the passed
31 // |success_callback| or the |error_callback| will be called with the result
32 // of the sanitization or an error message, respectively, but not before the
34 static void Sanitize(const std::string
& unsafe_json
,
35 const StringCallback
& success_callback
,
36 const StringCallback
& error_callback
);
38 #if defined(OS_ANDROID)
39 static bool Register(JNIEnv
* env
);
47 DISALLOW_COPY_AND_ASSIGN(JsonSanitizer
);
50 } // namespace safe_json
52 #endif // COMPONENTS_SAFE_JSON_JSON_SANITIZER_H_