Chromium Code Reviews| Index: content/common/presentation/presentation_struct_traits.cc |
| diff --git a/content/common/presentation/presentation_struct_traits.cc b/content/common/presentation/presentation_struct_traits.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d6e2bbfd92747840d85978b0b5cb4195c0b48bd3 |
| --- /dev/null |
| +++ b/content/common/presentation/presentation_struct_traits.cc |
| @@ -0,0 +1,64 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/common/presentation/presentation_struct_traits.h" |
| + |
| +#include "url/mojo/url_gurl_struct_traits.h" |
| + |
| +namespace mojo { |
| + |
| +bool StructTraits<blink::mojom::PresentationSessionInfoDataView, |
| + content::PresentationSessionInfo>:: |
| + Read(blink::mojom::PresentationSessionInfoDataView data, |
| + content::PresentationSessionInfo* out) { |
| + if (!data.ReadUrl(&(out->presentation_url)) || |
| + !data.ReadId(&(out->presentation_id))) { |
| + return false; |
| + } |
| + |
| + if (out->presentation_id.empty() || |
| + !base::IsStringASCII(out->presentation_id) || |
|
dcheng
2017/03/01 00:55:50
It seems pretty unusual to do this: no other struc
mark a. foltz
2017/03/03 21:03:21
To avoid invalid ids from a compromised renderer p
|
| + out->presentation_id.length() > |
| + content::PresentationSessionInfo::kMaxIdLength) { |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +bool StructTraits<blink::mojom::PresentationErrorDataView, |
| + content::PresentationError>:: |
| + Read(blink::mojom::PresentationErrorDataView data, |
| + content::PresentationError* out) { |
| + if (!data.ReadErrorType(&(out->error_type)) || |
| + !data.ReadMessage(&(out->message))) { |
| + return false; |
| + } |
| + |
| + if (!base::IsStringUTF8(out->message) || |
| + out->message.length() > content::PresentationError::kMaxMessageLength) { |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +bool UnionTraits<blink::mojom::PresentationConnectionMessageDataView, |
| + content::PresentationConnectionMessage>:: |
| + Read(blink::mojom::PresentationConnectionMessageDataView data, |
| + content::PresentationConnectionMessage* out) { |
| + if (data.is_message()) { |
| + if (!data.ReadMessage(&(out->message)) || |
| + out->message->length() > |
| + content::kMaxPresentationConnectionMessageSize) { |
| + return false; |
| + } |
| + } else { |
| + if (!data.ReadData(&(out->data)) || |
| + out->data->size() > content::kMaxPresentationConnectionMessageSize) { |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| +} |