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[] = | |
16 "urn:x-cast:com.google.cast.tp.deviceauth"; | |
17 // Sender and receiver IDs to use for platform messages. | |
18 static const char kPlatformSenderId[] = "sender-0"; | |
19 static const char kPlatformReceiverId[] = "receiver-0"; | |
20 } // namespace | |
21 | |
14 namespace extensions { | 22 namespace extensions { |
15 namespace api { | 23 namespace api { |
16 namespace cast_channel { | 24 namespace cast_channel { |
17 | 25 |
18 bool MessageInfoToCastMessage(const MessageInfo& message, | 26 bool MessageInfoToCastMessage(const MessageInfo& message, |
19 CastMessage* message_proto) { | 27 CastMessage* message_proto) { |
20 DCHECK(message_proto); | 28 DCHECK(message_proto); |
21 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); | 29 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); |
22 message_proto->set_source_id(message.source_id); | 30 message_proto->set_source_id(message.source_id); |
23 message_proto->set_destination_id(message.destination_id); | 31 message_proto->set_destination_id(message.destination_id); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 } | 84 } |
77 if (value.get()) { | 85 if (value.get()) { |
78 DCHECK(!message->data.get()); | 86 DCHECK(!message->data.get()); |
79 message->data.reset(value.release()); | 87 message->data.reset(value.release()); |
80 return true; | 88 return true; |
81 } else { | 89 } else { |
82 return false; | 90 return false; |
83 } | 91 } |
84 } | 92 } |
85 | 93 |
86 const std::string MessageProtoToString(const CastMessage& message_proto) { | 94 std::string CastMessageToString(const CastMessage& message_proto) { |
87 std::string out("{"); | 95 std::string out("{"); |
88 out += "namespace = " + message_proto.namespace_(); | 96 out += "namespace = " + message_proto.namespace_(); |
89 out += ", sourceId = " + message_proto.source_id(); | 97 out += ", sourceId = " + message_proto.source_id(); |
90 out += ", destId = " + message_proto.destination_id(); | 98 out += ", destId = " + message_proto.destination_id(); |
91 out += ", type = " + base::IntToString(message_proto.payload_type()); | 99 out += ", type = " + base::IntToString(message_proto.payload_type()); |
92 out += ", str = \"" + message_proto.payload_utf8() + "\"}"; | 100 out += ", str = \"" + message_proto.payload_utf8() + "\"}"; |
93 return out; | 101 return out; |
94 } | 102 } |
95 | 103 |
104 std::string AuthMessageToString(const DeviceAuthMessage& message) { | |
105 std::string out("{"); | |
106 if (message.has_challenge()) { | |
107 out += "\n challenge = {},"; | |
108 } | |
109 if (message.has_response()) { | |
110 out += "\n response = {"; | |
111 out += "\n signature = " + message.response().signature(); | |
112 out += "\n, certificate = " + | |
113 message.response().client_auth_certificate(); | |
114 out += "\n }"; | |
115 } | |
116 if (message.has_error()) { | |
117 out += "\n error = {"; | |
118 out += base::IntToString(message.error().error_type()); | |
119 out += "}"; | |
120 } | |
121 out += "}"; | |
122 return out; | |
Ryan Sleevi
2013/10/23 19:14:05
I can't recall any code where I've seen this sort
Munjal (Google)
2013/10/23 20:08:56
It is only used in logs.
| |
123 } | |
124 | |
125 void CreateAuthChallengeMessage(CastMessage* message_proto) { | |
126 CHECK(message_proto); | |
127 DeviceAuthMessage auth_message; | |
128 auth_message.mutable_challenge(); | |
129 std::string auth_message_string; | |
130 auth_message.SerializeToString(&auth_message_string); | |
131 | |
132 message_proto->set_source_id(kPlatformSenderId); | |
133 message_proto->set_destination_id(kPlatformReceiverId); | |
134 message_proto->set_namespace_(kAuthNamespace); | |
135 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); | |
136 message_proto->set_payload_binary(auth_message_string); | |
137 } | |
138 | |
139 bool IsAuthMessage(const CastMessage& message) { | |
140 return message.namespace_() == kAuthNamespace; | |
141 } | |
142 | |
96 } // namespace cast_channel | 143 } // namespace cast_channel |
97 } // namespace api | 144 } // namespace api |
98 } // namespace extensions | 145 } // namespace extensions |
OLD | NEW |