| 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" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "extensions/browser/api/cast_channel/cast_auth_util.h" |
| 12 #include "extensions/common/api/cast_channel.h" | 13 #include "extensions/common/api/cast_channel.h" |
| 13 #include "extensions/common/api/cast_channel/cast_channel.pb.h" | 14 #include "extensions/common/api/cast_channel/cast_channel.pb.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 static const char kAuthNamespace[] = | 17 static const char kAuthNamespace[] = |
| 17 "urn:x-cast:com.google.cast.tp.deviceauth"; | 18 "urn:x-cast:com.google.cast.tp.deviceauth"; |
| 18 // Sender and receiver IDs to use for platform messages. | 19 // Sender and receiver IDs to use for platform messages. |
| 19 static const char kPlatformSenderId[] = "sender-0"; | 20 static const char kPlatformSenderId[] = "sender-0"; |
| 20 static const char kPlatformReceiverId[] = "receiver-0"; | 21 static const char kPlatformReceiverId[] = "receiver-0"; |
| 21 } // namespace | 22 } // namespace |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 128 } |
| 128 if (message.has_error()) { | 129 if (message.has_error()) { |
| 129 out += ", error: {"; | 130 out += ", error: {"; |
| 130 out += base::IntToString(message.error().error_type()); | 131 out += base::IntToString(message.error().error_type()); |
| 131 out += "}"; | 132 out += "}"; |
| 132 } | 133 } |
| 133 out += "}"; | 134 out += "}"; |
| 134 return out; | 135 return out; |
| 135 } | 136 } |
| 136 | 137 |
| 137 void CreateAuthChallengeMessage(CastMessage* message_proto) { | 138 void CreateAuthChallengeMessage(CastMessage* message_proto, |
| 139 const AuthContext& auth_context) { |
| 138 CHECK(message_proto); | 140 CHECK(message_proto); |
| 139 DeviceAuthMessage auth_message; | 141 DeviceAuthMessage auth_message; |
| 140 auth_message.mutable_challenge(); | 142 auth_message.mutable_challenge()->set_sender_nonce(auth_context.nonce()); |
| 141 std::string auth_message_string; | 143 std::string auth_message_string; |
| 142 auth_message.SerializeToString(&auth_message_string); | 144 auth_message.SerializeToString(&auth_message_string); |
| 143 | 145 |
| 144 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); | 146 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); |
| 145 message_proto->set_source_id(kPlatformSenderId); | 147 message_proto->set_source_id(kPlatformSenderId); |
| 146 message_proto->set_destination_id(kPlatformReceiverId); | 148 message_proto->set_destination_id(kPlatformReceiverId); |
| 147 message_proto->set_namespace_(kAuthNamespace); | 149 message_proto->set_namespace_(kAuthNamespace); |
| 148 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); | 150 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); |
| 149 message_proto->set_payload_binary(auth_message_string); | 151 message_proto->set_payload_binary(auth_message_string); |
| 150 } | 152 } |
| 151 | 153 |
| 152 bool IsAuthMessage(const CastMessage& message) { | 154 bool IsAuthMessage(const CastMessage& message) { |
| 153 return message.namespace_() == kAuthNamespace; | 155 return message.namespace_() == kAuthNamespace; |
| 154 } | 156 } |
| 155 | 157 |
| 156 } // namespace cast_channel | 158 } // namespace cast_channel |
| 157 } // namespace api | 159 } // namespace api |
| 158 } // namespace extensions | 160 } // namespace extensions |
| OLD | NEW |