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 "extensions/browser/api/cast_channel/cast_message_util.h" | 5 #include "extensions/browser/api/cast_channel/cast_message_util.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 if (!message.data) | 30 if (!message.data) |
31 return false; | 31 return false; |
32 | 32 |
33 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); | 33 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); |
34 message_proto->set_source_id(message.source_id); | 34 message_proto->set_source_id(message.source_id); |
35 message_proto->set_destination_id(message.destination_id); | 35 message_proto->set_destination_id(message.destination_id); |
36 message_proto->set_namespace_(message.namespace_); | 36 message_proto->set_namespace_(message.namespace_); |
37 // Determine the type of the base::Value and set the message payload | 37 // Determine the type of the base::Value and set the message payload |
38 // appropriately. | 38 // appropriately. |
39 std::string data; | 39 std::string data; |
40 base::BinaryValue* real_value; | |
41 switch (message.data->GetType()) { | 40 switch (message.data->GetType()) { |
42 // JS string | 41 // JS string |
43 case base::Value::Type::STRING: | 42 case base::Value::Type::STRING: |
44 if (message.data->GetAsString(&data)) { | 43 if (message.data->GetAsString(&data)) { |
45 message_proto->set_payload_type(CastMessage_PayloadType_STRING); | 44 message_proto->set_payload_type(CastMessage_PayloadType_STRING); |
46 message_proto->set_payload_utf8(data); | 45 message_proto->set_payload_utf8(data); |
47 } | 46 } |
48 break; | 47 break; |
49 // JS ArrayBuffer | 48 // JS ArrayBuffer |
50 case base::Value::Type::BINARY: | 49 case base::Value::Type::BINARY: |
51 real_value = static_cast<base::BinaryValue*>(message.data.get()); | 50 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); |
52 if (real_value->GetBuffer()) { | 51 message_proto->set_payload_binary(message.data->GetBuffer(), |
53 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); | 52 message.data->GetSize()); |
54 message_proto->set_payload_binary(real_value->GetBuffer(), | |
55 real_value->GetSize()); | |
56 } | |
57 break; | 53 break; |
58 default: | 54 default: |
59 // Unknown value type. message_proto will remain uninitialized because | 55 // Unknown value type. message_proto will remain uninitialized because |
60 // payload_type is unset. | 56 // payload_type is unset. |
61 break; | 57 break; |
62 } | 58 } |
63 return message_proto->IsInitialized(); | 59 return message_proto->IsInitialized(); |
64 } | 60 } |
65 | 61 |
66 bool IsCastMessageValid(const CastMessage& message_proto) { | 62 bool IsCastMessageValid(const CastMessage& message_proto) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 message_proto->set_payload_binary(auth_message_string); | 149 message_proto->set_payload_binary(auth_message_string); |
154 } | 150 } |
155 | 151 |
156 bool IsAuthMessage(const CastMessage& message) { | 152 bool IsAuthMessage(const CastMessage& message) { |
157 return message.namespace_() == kAuthNamespace; | 153 return message.namespace_() == kAuthNamespace; |
158 } | 154 } |
159 | 155 |
160 } // namespace cast_channel | 156 } // namespace cast_channel |
161 } // namespace api | 157 } // namespace api |
162 } // namespace extensions | 158 } // namespace extensions |
OLD | NEW |