| 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 22 matching lines...) Expand all Loading... |
| 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; | 40 base::BinaryValue* real_value; |
| 41 switch (message.data->GetType()) { | 41 switch (message.data->GetType()) { |
| 42 // JS string | 42 // JS string |
| 43 case base::Value::TYPE_STRING: | 43 case base::Value::Type::STRING: |
| 44 if (message.data->GetAsString(&data)) { | 44 if (message.data->GetAsString(&data)) { |
| 45 message_proto->set_payload_type(CastMessage_PayloadType_STRING); | 45 message_proto->set_payload_type(CastMessage_PayloadType_STRING); |
| 46 message_proto->set_payload_utf8(data); | 46 message_proto->set_payload_utf8(data); |
| 47 } | 47 } |
| 48 break; | 48 break; |
| 49 // JS ArrayBuffer | 49 // JS ArrayBuffer |
| 50 case base::Value::TYPE_BINARY: | 50 case base::Value::Type::BINARY: |
| 51 real_value = static_cast<base::BinaryValue*>(message.data.get()); | 51 real_value = static_cast<base::BinaryValue*>(message.data.get()); |
| 52 if (real_value->GetBuffer()) { | 52 if (real_value->GetBuffer()) { |
| 53 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); | 53 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); |
| 54 message_proto->set_payload_binary(real_value->GetBuffer(), | 54 message_proto->set_payload_binary(real_value->GetBuffer(), |
| 55 real_value->GetSize()); | 55 real_value->GetSize()); |
| 56 } | 56 } |
| 57 break; | 57 break; |
| 58 default: | 58 default: |
| 59 // Unknown value type. message_proto will remain uninitialized because | 59 // Unknown value type. message_proto will remain uninitialized because |
| 60 // payload_type is unset. | 60 // payload_type is unset. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 message_proto->set_payload_binary(auth_message_string); | 153 message_proto->set_payload_binary(auth_message_string); |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool IsAuthMessage(const CastMessage& message) { | 156 bool IsAuthMessage(const CastMessage& message) { |
| 157 return message.namespace_() == kAuthNamespace; | 157 return message.namespace_() == kAuthNamespace; |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace cast_channel | 160 } // namespace cast_channel |
| 161 } // namespace api | 161 } // namespace api |
| 162 } // namespace extensions | 162 } // namespace extensions |
| OLD | NEW |