| OLD | NEW |
| 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" | |
| 14 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" | 16 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" |
| 15 #include "url/mojo/url.mojom.h" | 17 #include "url/mojo/url.mojom.h" |
| 16 | 18 |
| 17 namespace mojo { | 19 namespace mojo { |
| 18 | 20 |
| 19 template <> | 21 template <> |
| 20 struct EnumTraits<blink::mojom::PresentationErrorType, | 22 struct EnumTraits<blink::mojom::PresentationErrorType, |
| 21 content::PresentationErrorType> { | 23 content::PresentationErrorType> { |
| 22 static blink::mojom::PresentationErrorType ToMojom( | 24 static blink::mojom::PresentationErrorType ToMojom( |
| 23 content::PresentationErrorType input) { | 25 content::PresentationErrorType input) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 static const GURL& url(const content::PresentationSessionInfo& session_info) { | 146 static const GURL& url(const content::PresentationSessionInfo& session_info) { |
| 145 return session_info.presentation_url; | 147 return session_info.presentation_url; |
| 146 } | 148 } |
| 147 | 149 |
| 148 static const std::string& id( | 150 static const std::string& id( |
| 149 const content::PresentationSessionInfo& session_info) { | 151 const content::PresentationSessionInfo& session_info) { |
| 150 return session_info.presentation_id; | 152 return session_info.presentation_id; |
| 151 } | 153 } |
| 152 | 154 |
| 153 static bool Read(blink::mojom::PresentationSessionInfoDataView data, | 155 static bool Read(blink::mojom::PresentationSessionInfoDataView data, |
| 154 content::PresentationSessionInfo* out) { | 156 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 }; | 157 }; |
| 171 | 158 |
| 172 template <> | 159 template <> |
| 173 struct StructTraits<blink::mojom::PresentationErrorDataView, | 160 struct StructTraits<blink::mojom::PresentationErrorDataView, |
| 174 content::PresentationError> { | 161 content::PresentationError> { |
| 175 static content::PresentationErrorType error_type( | 162 static content::PresentationErrorType error_type( |
| 176 const content::PresentationError& error) { | 163 const content::PresentationError& error) { |
| 177 return error.error_type; | 164 return error.error_type; |
| 178 } | 165 } |
| 179 | 166 |
| 180 static const std::string& message(const content::PresentationError& error) { | 167 static const std::string& message(const content::PresentationError& error) { |
| 181 return error.message; | 168 return error.message; |
| 182 } | 169 } |
| 183 | 170 |
| 184 static bool Read(blink::mojom::PresentationErrorDataView data, | 171 static bool Read(blink::mojom::PresentationErrorDataView data, |
| 185 content::PresentationError* out) { | 172 content::PresentationError* out); |
| 186 if (!data.ReadErrorType(&(out->error_type))) | 173 }; |
| 187 return false; | |
| 188 | 174 |
| 189 if (!data.ReadMessage(&(out->message))) | 175 template <> |
| 190 return false; | 176 struct UnionTraits<blink::mojom::PresentationConnectionMessageDataView, |
| 177 content::PresentationConnectionMessage> { |
| 178 static blink::mojom::PresentationConnectionMessageDataView::Tag GetTag( |
| 179 const content::PresentationConnectionMessage& message) { |
| 180 return message.is_binary() |
| 181 ? blink::mojom::PresentationConnectionMessageDataView::Tag::DATA |
| 182 : blink::mojom::PresentationConnectionMessageDataView::Tag:: |
| 183 MESSAGE; |
| 184 } |
| 191 | 185 |
| 192 if (!base::IsStringUTF8(out->message) || | 186 static const std::string& message( |
| 193 out->message.length() > content::PresentationError::kMaxMessageLength) | 187 const content::PresentationConnectionMessage& message) { |
| 194 return false; | 188 DCHECK(!message.is_binary()); |
| 189 return message.message.value(); |
| 190 } |
| 195 | 191 |
| 196 return true; | 192 static const std::vector<uint8_t>& data( |
| 193 const content::PresentationConnectionMessage& message) { |
| 194 DCHECK(message.is_binary()); |
| 195 return message.data.value(); |
| 197 } | 196 } |
| 197 |
| 198 static bool Read(blink::mojom::PresentationConnectionMessageDataView data, |
| 199 content::PresentationConnectionMessage* out); |
| 198 }; | 200 }; |
| 199 | 201 |
| 200 } // namespace mojo | 202 } // namespace mojo |
| 201 | 203 |
| 202 #endif // CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ | 204 #endif // CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ |
| OLD | NEW |