OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/cast_channel/cast_message_util.h" | 5 #include "chrome/browser/extensions/api/cast_channel/cast_message_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/extensions/api/cast_channel/cast_channel.pb.h" | 11 #include "chrome/browser/extensions/api/cast_channel/cast_channel.pb.h" |
12 #include "chrome/common/extensions/api/cast_channel.h" | 12 #include "chrome/common/extensions/api/cast_channel.h" |
13 | 13 |
| 14 namespace { |
| 15 static const char kAuthNamespace[] = "com.google.cast.tp.deviceauth"; |
| 16 } // namespace |
| 17 |
14 namespace extensions { | 18 namespace extensions { |
15 namespace api { | 19 namespace api { |
16 namespace cast_channel { | 20 namespace cast_channel { |
17 | 21 |
18 bool MessageInfoToCastMessage(const MessageInfo& message, | 22 bool MessageInfoToCastMessage(const MessageInfo& message, |
19 CastMessage* message_proto) { | 23 CastMessage* message_proto) { |
20 DCHECK(message_proto); | 24 DCHECK(message_proto); |
21 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); | 25 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); |
22 message_proto->set_source_id(message.source_id); | 26 message_proto->set_source_id(message.source_id); |
23 message_proto->set_destination_id(message.destination_id); | 27 message_proto->set_destination_id(message.destination_id); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 80 } |
77 if (value.get()) { | 81 if (value.get()) { |
78 DCHECK(!message->data.get()); | 82 DCHECK(!message->data.get()); |
79 message->data.reset(value.release()); | 83 message->data.reset(value.release()); |
80 return true; | 84 return true; |
81 } else { | 85 } else { |
82 return false; | 86 return false; |
83 } | 87 } |
84 } | 88 } |
85 | 89 |
86 const std::string MessageProtoToString(const CastMessage& message_proto) { | 90 std::string MessageProtoToString(const CastMessage& message_proto) { |
87 std::string out("{"); | 91 std::string out("{"); |
88 out += "namespace = " + message_proto.namespace_(); | 92 out += "namespace = " + message_proto.namespace_(); |
89 out += ", sourceId = " + message_proto.source_id(); | 93 out += ", sourceId = " + message_proto.source_id(); |
90 out += ", destId = " + message_proto.destination_id(); | 94 out += ", destId = " + message_proto.destination_id(); |
91 out += ", type = " + base::IntToString(message_proto.payload_type()); | 95 out += ", type = " + base::IntToString(message_proto.payload_type()); |
92 out += ", str = \"" + message_proto.payload_utf8() + "\"}"; | 96 out += ", str = \"" + message_proto.payload_utf8() + "\"}"; |
93 return out; | 97 return out; |
94 } | 98 } |
95 | 99 |
| 100 std::string AuthMessageToString(const DeviceAuthMessage& message) { |
| 101 std::string result; |
| 102 if (message.SerializeToString(&result)) |
| 103 return result; |
| 104 else |
| 105 return ""; |
| 106 } |
| 107 |
| 108 void CreateAuthChallengeMessage(CastMessage* message_proto) { |
| 109 CHECK(message_proto); |
| 110 DeviceAuthMessage auth_message; |
| 111 auth_message.mutable_challenge(); |
| 112 std::string auth_message_string; |
| 113 auth_message.SerializeToString(&auth_message_string); |
| 114 |
| 115 message_proto->set_namespace_(kAuthNamespace); |
| 116 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); |
| 117 message_proto->set_payload_binary(auth_message_string); |
| 118 } |
| 119 |
| 120 bool IsAuthMessage(const CastMessage& message) { |
| 121 return message.namespace_() == kAuthNamespace; |
| 122 } |
| 123 |
96 } // namespace cast_channel | 124 } // namespace cast_channel |
97 } // namespace api | 125 } // namespace api |
98 } // namespace extensions | 126 } // namespace extensions |
OLD | NEW |