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

Unified Diff: content/common/presentation/presentation_struct_traits.cc

Issue 2706463002: [Presentation API] Mojo typemap for content::PresentationConnectionMessage (Closed)
Patch Set: Remove TODO Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
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..9aa473f651c5540b020dd4329da89fef6d789852
--- /dev/null
+++ b/content/common/presentation/presentation_struct_traits.cc
@@ -0,0 +1,66 @@
+// 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) ||
+ 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) ||
dcheng 2017/02/28 06:45:27 I think Mojo requires that strings are utf-8. +yzs
yzshen1 2017/02/28 18:22:07 We don't enforce it during validation at the momen
+ 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()) {
+ // out->message = std::string();
dcheng 2017/02/28 06:45:27 Nit: remove commented out code here and below
mark a. foltz 2017/02/28 18:35:21 Done.
+ if (!data.ReadMessage(&(out->message)) ||
+ out->message->length() >
+ content::kMaxPresentationConnectionMessageSize) {
+ return false;
+ }
+ } else {
+ // out->data = std::vector<uint8_t>();
+ if (!data.ReadData(&(out->data)) ||
+ out->data->size() > content::kMaxPresentationConnectionMessageSize) {
+ return false;
+ }
+ }
+ return true;
+}
+}

Powered by Google App Engine
This is Rietveld 408576698