• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 CONTENT_COMMON_ANDROID_GIN_JAVA_BRIDGE_VALUE_H_
6 #define CONTENT_COMMON_ANDROID_GIN_JAVA_BRIDGE_VALUE_H_
7 
8 #include "base/memory/scoped_ptr.h"
9 #include "base/pickle.h"
10 #include "base/values.h"
11 #include "content/common/content_export.h"
12 
13 // In Java Bridge, we need to pass some kinds of values that can't
14 // be put into base::Value. And since base::Value is not extensible,
15 // we transfer these special values via base::BinaryValue.
16 
17 namespace content {
18 
19 class GinJavaBridgeValue {
20  public:
21   enum Type {
22     TYPE_FIRST_VALUE = 0,
23     // JavaScript 'undefined'
24     TYPE_UNDEFINED = 0,
25     // JavaScript NaN and Infinity
26     TYPE_NONFINITE,
27     // Bridge Object ID
28     TYPE_OBJECT_ID,
29     TYPE_LAST_VALUE
30   };
31 
32   // Serialization
33   CONTENT_EXPORT static scoped_ptr<base::BinaryValue> CreateUndefinedValue();
34   CONTENT_EXPORT static scoped_ptr<base::BinaryValue> CreateNonFiniteValue(
35       float in_value);
36   CONTENT_EXPORT static scoped_ptr<base::BinaryValue> CreateNonFiniteValue(
37       double in_value);
38   CONTENT_EXPORT static scoped_ptr<base::BinaryValue> CreateObjectIDValue(
39       int32 in_value);
40 
41   // De-serialization
42   CONTENT_EXPORT static bool ContainsGinJavaBridgeValue(
43       const base::Value* value);
44   CONTENT_EXPORT static scoped_ptr<const GinJavaBridgeValue> FromValue(
45       const base::Value* value);
46 
47   CONTENT_EXPORT Type GetType() const;
48   CONTENT_EXPORT bool IsType(Type type) const;
49 
50   CONTENT_EXPORT bool GetAsNonFinite(float* out_value) const;
51   CONTENT_EXPORT bool GetAsObjectID(int32* out_object_id) const;
52 
53  private:
54   explicit GinJavaBridgeValue(Type type);
55   explicit GinJavaBridgeValue(const base::BinaryValue* value);
56   base::BinaryValue* SerializeToBinaryValue();
57 
58   Pickle pickle_;
59 
60   DISALLOW_COPY_AND_ASSIGN(GinJavaBridgeValue);
61 };
62 
63 }  // namespace content
64 
65 #endif  // CONTENT_COMMON_ANDROID_GIN_JAVA_BRIDGE_VALUE_H_
66