Update V8 to version 4.7.21.
[chromium-blink-merge.git] / components / safe_json / json_sanitizer.h
blob3f393d55f2615812af1e86f697d7199011f6a9d8
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_
8 #include <string>
10 #include "base/callback_forward.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
14 #if defined(OS_ANDROID)
15 #include <jni.h>
16 #endif
18 namespace safe_json {
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.
26 class JsonSanitizer {
27 public:
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
33 // method returns.
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);
40 #endif
42 protected:
43 JsonSanitizer() {}
44 ~JsonSanitizer() {}
46 private:
47 DISALLOW_COPY_AND_ASSIGN(JsonSanitizer);
50 } // namespace safe_json
52 #endif // COMPONENTS_SAFE_JSON_JSON_SANITIZER_H_