OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef COMPONENTS_SAFE_JSON_JSON_SANITIZER_H_ |
| 6 #define COMPONENTS_SAFE_JSON_JSON_SANITIZER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 |
| 14 #if defined(OS_ANDROID) |
| 15 #include <jni.h> |
| 16 #endif |
| 17 |
| 18 namespace safe_json { |
| 19 |
| 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&)>; |
| 29 |
| 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); |
| 37 |
| 38 #if defined(OS_ANDROID) |
| 39 static bool Register(JNIEnv* env); |
| 40 #endif |
| 41 |
| 42 protected: |
| 43 JsonSanitizer() {} |
| 44 ~JsonSanitizer() {} |
| 45 |
| 46 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(JsonSanitizer); |
| 48 }; |
| 49 |
| 50 } // namespace safe_json |
| 51 |
| 52 #endif // COMPONENTS_SAFE_JSON_JSON_SANITIZER_H_ |
OLD | NEW |