OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "content/common/android/gin_java_bridge_value.h" | 5 #include "content/common/android/gin_java_bridge_value.h" |
6 | 6 |
7 namespace content { | 7 namespace content { |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // static | 48 // static |
49 std::unique_ptr<base::BinaryValue> GinJavaBridgeValue::CreateObjectIDValue( | 49 std::unique_ptr<base::BinaryValue> GinJavaBridgeValue::CreateObjectIDValue( |
50 int32_t in_value) { | 50 int32_t in_value) { |
51 GinJavaBridgeValue gin_value(TYPE_OBJECT_ID); | 51 GinJavaBridgeValue gin_value(TYPE_OBJECT_ID); |
52 gin_value.pickle_.WriteInt(in_value); | 52 gin_value.pickle_.WriteInt(in_value); |
53 return gin_value.SerializeToBinaryValue(); | 53 return gin_value.SerializeToBinaryValue(); |
54 } | 54 } |
55 | 55 |
56 // static | 56 // static |
57 bool GinJavaBridgeValue::ContainsGinJavaBridgeValue(const base::Value* value) { | 57 bool GinJavaBridgeValue::ContainsGinJavaBridgeValue(const base::Value* value) { |
58 if (!value->IsType(base::Value::TYPE_BINARY)) | 58 if (!value->IsType(base::Value::Type::BINARY)) |
59 return false; | 59 return false; |
60 const base::BinaryValue* binary_value = | 60 const base::BinaryValue* binary_value = |
61 reinterpret_cast<const base::BinaryValue*>(value); | 61 reinterpret_cast<const base::BinaryValue*>(value); |
62 if (binary_value->GetSize() < sizeof(Header)) | 62 if (binary_value->GetSize() < sizeof(Header)) |
63 return false; | 63 return false; |
64 base::Pickle pickle(binary_value->GetBuffer(), binary_value->GetSize()); | 64 base::Pickle pickle(binary_value->GetBuffer(), binary_value->GetSize()); |
65 // Broken binary value: payload or header size is wrong | 65 // Broken binary value: payload or header size is wrong |
66 if (!pickle.data() || pickle.size() - pickle.payload_size() != sizeof(Header)) | 66 if (!pickle.data() || pickle.size() - pickle.payload_size() != sizeof(Header)) |
67 return false; | 67 return false; |
68 Header* header = pickle.headerT<Header>(); | 68 Header* header = pickle.headerT<Header>(); |
69 return (header->magic == kHeaderMagic && | 69 return (header->magic == kHeaderMagic && |
70 header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE); | 70 header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE); |
71 } | 71 } |
72 | 72 |
73 // static | 73 // static |
74 std::unique_ptr<const GinJavaBridgeValue> GinJavaBridgeValue::FromValue( | 74 std::unique_ptr<const GinJavaBridgeValue> GinJavaBridgeValue::FromValue( |
75 const base::Value* value) { | 75 const base::Value* value) { |
76 return std::unique_ptr<const GinJavaBridgeValue>( | 76 return std::unique_ptr<const GinJavaBridgeValue>( |
77 value->IsType(base::Value::TYPE_BINARY) | 77 value->IsType(base::Value::Type::BINARY) |
78 ? new GinJavaBridgeValue( | 78 ? new GinJavaBridgeValue( |
79 reinterpret_cast<const base::BinaryValue*>(value)) | 79 reinterpret_cast<const base::BinaryValue*>(value)) |
80 : NULL); | 80 : NULL); |
81 } | 81 } |
82 | 82 |
83 GinJavaBridgeValue::Type GinJavaBridgeValue::GetType() const { | 83 GinJavaBridgeValue::Type GinJavaBridgeValue::GetType() const { |
84 const Header* header = pickle_.headerT<Header>(); | 84 const Header* header = pickle_.headerT<Header>(); |
85 DCHECK(header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE); | 85 DCHECK(header->type >= TYPE_FIRST_VALUE && header->type < TYPE_LAST_VALUE); |
86 return static_cast<Type>(header->type); | 86 return static_cast<Type>(header->type); |
87 } | 87 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 DCHECK(ContainsGinJavaBridgeValue(value)); | 120 DCHECK(ContainsGinJavaBridgeValue(value)); |
121 } | 121 } |
122 | 122 |
123 std::unique_ptr<base::BinaryValue> | 123 std::unique_ptr<base::BinaryValue> |
124 GinJavaBridgeValue::SerializeToBinaryValue() { | 124 GinJavaBridgeValue::SerializeToBinaryValue() { |
125 return base::BinaryValue::CreateWithCopiedBuffer( | 125 return base::BinaryValue::CreateWithCopiedBuffer( |
126 reinterpret_cast<const char*>(pickle_.data()), pickle_.size()); | 126 reinterpret_cast<const char*>(pickle_.data()), pickle_.size()); |
127 } | 127 } |
128 | 128 |
129 } // namespace content | 129 } // namespace content |
OLD | NEW |