Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: content/common/presentation/presentation_struct_traits.h

Issue 2706463002: [Presentation API] Mojo typemap for content::PresentationConnectionMessage (Closed)
Patch Set: Remove TODO Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #ifndef CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ 5 #ifndef CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_
6 #define CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ 6 #define CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/optional.h"
11 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "content/public/common/presentation_connection_message.h"
12 #include "content/public/common/presentation_session.h" 15 #include "content/public/common/presentation_session.h"
13 #include "mojo/common/common_custom_types_struct_traits.h" 16 //#include "mojo/common/common_custom_types_struct_traits.h"
dcheng 2017/02/28 06:45:27 Nit: remove commented out code
mark a. foltz 2017/02/28 18:35:21 Done
14 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" 17 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h"
15 #include "url/mojo/url.mojom.h" 18 #include "url/mojo/url.mojom.h"
16 19
17 namespace mojo { 20 namespace mojo {
18 21
19 template <> 22 template <>
20 struct EnumTraits<blink::mojom::PresentationErrorType, 23 struct EnumTraits<blink::mojom::PresentationErrorType,
21 content::PresentationErrorType> { 24 content::PresentationErrorType> {
22 static blink::mojom::PresentationErrorType ToMojom( 25 static blink::mojom::PresentationErrorType ToMojom(
23 content::PresentationErrorType input) { 26 content::PresentationErrorType input) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 static const GURL& url(const content::PresentationSessionInfo& session_info) { 147 static const GURL& url(const content::PresentationSessionInfo& session_info) {
145 return session_info.presentation_url; 148 return session_info.presentation_url;
146 } 149 }
147 150
148 static const std::string& id( 151 static const std::string& id(
149 const content::PresentationSessionInfo& session_info) { 152 const content::PresentationSessionInfo& session_info) {
150 return session_info.presentation_id; 153 return session_info.presentation_id;
151 } 154 }
152 155
153 static bool Read(blink::mojom::PresentationSessionInfoDataView data, 156 static bool Read(blink::mojom::PresentationSessionInfoDataView data,
154 content::PresentationSessionInfo* out) { 157 content::PresentationSessionInfo* out);
155 if (!data.ReadUrl(&(out->presentation_url)))
156 return false;
157
158 if (!data.ReadId(&(out->presentation_id)))
159 return false;
160
161 if (out->presentation_id.empty() ||
162 !base::IsStringASCII(out->presentation_id) ||
163 out->presentation_id.length() >
164 content::PresentationSessionInfo::kMaxIdLength) {
165 return false;
166 }
167
168 return true;
169 }
170 }; 158 };
171 159
172 template <> 160 template <>
173 struct StructTraits<blink::mojom::PresentationErrorDataView, 161 struct StructTraits<blink::mojom::PresentationErrorDataView,
174 content::PresentationError> { 162 content::PresentationError> {
175 static content::PresentationErrorType error_type( 163 static content::PresentationErrorType error_type(
176 const content::PresentationError& error) { 164 const content::PresentationError& error) {
177 return error.error_type; 165 return error.error_type;
178 } 166 }
179 167
180 static const std::string& message(const content::PresentationError& error) { 168 static const std::string& message(const content::PresentationError& error) {
181 return error.message; 169 return error.message;
182 } 170 }
183 171
184 static bool Read(blink::mojom::PresentationErrorDataView data, 172 static bool Read(blink::mojom::PresentationErrorDataView data,
185 content::PresentationError* out) { 173 content::PresentationError* out);
186 if (!data.ReadErrorType(&(out->error_type))) 174 };
187 return false;
188 175
189 if (!data.ReadMessage(&(out->message))) 176 template <>
190 return false; 177 struct UnionTraits<blink::mojom::PresentationConnectionMessageDataView,
178 content::PresentationConnectionMessage> {
179 static blink::mojom::PresentationConnectionMessageDataView::Tag GetTag(
180 const content::PresentationConnectionMessage& message) {
181 return message.is_binary()
182 ? blink::mojom::PresentationConnectionMessageDataView::Tag::DATA
183 : blink::mojom::PresentationConnectionMessageDataView::Tag::
184 MESSAGE;
185 }
191 186
192 if (!base::IsStringUTF8(out->message) || 187 static const std::string& message(
193 out->message.length() > content::PresentationError::kMaxMessageLength) 188 const content::PresentationConnectionMessage& message) {
194 return false; 189 DCHECK(!message.is_binary());
190 return message.message.value();
191 }
195 192
196 return true; 193 static const std::vector<uint8_t>& data(
194 const content::PresentationConnectionMessage& message) {
195 DCHECK(message.is_binary());
196 return message.data.value();
197 } 197 }
198
199 static bool Read(blink::mojom::PresentationConnectionMessageDataView data,
200 content::PresentationConnectionMessage* out);
198 }; 201 };
199 202
200 } // namespace mojo 203 } // namespace mojo
201 204
202 #endif // CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ 205 #endif // CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698