Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ | |
| 6 #define CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/strings/string_util.h" | |
| 12 #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" | |
| 15 #include "url/mojo/url.mojom.h" | |
| 16 | |
| 17 namespace mojo { | |
| 18 | |
| 19 template <> | |
| 20 struct EnumTraits<blink::mojom::PresentationErrorType, | |
| 21 content::PresentationErrorType> { | |
| 22 static blink::mojom::PresentationErrorType ToMojom( | |
| 23 content::PresentationErrorType input) { | |
| 24 switch (input) { | |
| 25 case content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS: | |
| 26 return blink::mojom::PresentationErrorType::NO_AVAILABLE_SCREENS; | |
| 27 case content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED: | |
| 28 return blink::mojom::PresentationErrorType::SESSION_REQUEST_CANCELLED; | |
| 29 case content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND: | |
| 30 return blink::mojom::PresentationErrorType::NO_PRESENTATION_FOUND; | |
| 31 case content::PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS: | |
| 32 return blink::mojom::PresentationErrorType::PREVIOUS_START_IN_PROGRESS; | |
| 33 case content::PRESENTATION_ERROR_UNKNOWN: | |
| 34 return blink::mojom::PresentationErrorType::UNKNOWN; | |
| 35 } | |
| 36 NOTREACHED() << "Unknown content::PresentationErrorType " | |
| 37 << static_cast<int>(input); | |
| 38 return blink::mojom::PresentationErrorType::UNKNOWN; | |
| 39 } | |
| 40 | |
| 41 static bool FromMojom(blink::mojom::PresentationErrorType input, | |
| 42 content::PresentationErrorType* output) { | |
| 43 switch (input) { | |
| 44 case blink::mojom::PresentationErrorType::NO_AVAILABLE_SCREENS: | |
| 45 *output = content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS; | |
| 46 return true; | |
| 47 case blink::mojom::PresentationErrorType::SESSION_REQUEST_CANCELLED: | |
| 48 *output = content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED; | |
| 49 return true; | |
| 50 case blink::mojom::PresentationErrorType::NO_PRESENTATION_FOUND: | |
| 51 *output = content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND; | |
| 52 return true; | |
| 53 case blink::mojom::PresentationErrorType::PREVIOUS_START_IN_PROGRESS: | |
| 54 *output = content::PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS; | |
| 55 return true; | |
| 56 case blink::mojom::PresentationErrorType::UNKNOWN: | |
| 57 *output = content::PRESENTATION_ERROR_UNKNOWN; | |
| 58 return true; | |
| 59 } | |
| 60 return false; | |
| 61 } | |
| 62 }; | |
| 63 | |
| 64 template <> | |
| 65 struct EnumTraits<blink::mojom::PresentationConnectionState, | |
| 66 content::PresentationConnectionState> { | |
| 67 static blink::mojom::PresentationConnectionState ToMojom( | |
| 68 content::PresentationConnectionState input) { | |
| 69 switch (input) { | |
| 70 case content::PRESENTATION_CONNECTION_STATE_CONNECTING: | |
| 71 return blink::mojom::PresentationConnectionState::CONNECTING; | |
| 72 case content::PRESENTATION_CONNECTION_STATE_CONNECTED: | |
| 73 return blink::mojom::PresentationConnectionState::CONNECTED; | |
| 74 case content::PRESENTATION_CONNECTION_STATE_CLOSED: | |
| 75 return blink::mojom::PresentationConnectionState::CLOSED; | |
| 76 case content::PRESENTATION_CONNECTION_STATE_TERMINATED: | |
| 77 return blink::mojom::PresentationConnectionState::TERMINATED; | |
| 78 } | |
| 79 NOTREACHED() << "Unknown content::PresentationConnectionState " | |
| 80 << static_cast<int>(input); | |
| 81 return blink::mojom::PresentationConnectionState::TERMINATED; | |
| 82 } | |
| 83 | |
| 84 static bool FromMojom(blink::mojom::PresentationConnectionState input, | |
| 85 content::PresentationConnectionState* output) { | |
| 86 switch (input) { | |
| 87 case blink::mojom::PresentationConnectionState::CONNECTING: | |
| 88 *output = content::PRESENTATION_CONNECTION_STATE_CONNECTING; | |
| 89 return true; | |
| 90 case blink::mojom::PresentationConnectionState::CONNECTED: | |
| 91 *output = content::PRESENTATION_CONNECTION_STATE_CONNECTED; | |
| 92 return true; | |
| 93 case blink::mojom::PresentationConnectionState::CLOSED: | |
| 94 *output = content::PRESENTATION_CONNECTION_STATE_CLOSED; | |
| 95 return true; | |
| 96 case blink::mojom::PresentationConnectionState::TERMINATED: | |
| 97 *output = content::PRESENTATION_CONNECTION_STATE_TERMINATED; | |
| 98 return true; | |
| 99 } | |
| 100 return false; | |
| 101 } | |
| 102 }; | |
| 103 | |
| 104 template <> | |
| 105 struct EnumTraits<blink::mojom::PresentationConnectionCloseReason, | |
| 106 content::PresentationConnectionCloseReason> { | |
| 107 static blink::mojom::PresentationConnectionCloseReason ToMojom( | |
| 108 content::PresentationConnectionCloseReason input) { | |
| 109 switch (input) { | |
| 110 case content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR: | |
| 111 return blink::mojom::PresentationConnectionCloseReason:: | |
| 112 CONNECTION_ERROR; | |
| 113 case content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED: | |
| 114 return blink::mojom::PresentationConnectionCloseReason::CLOSED; | |
| 115 case content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY: | |
| 116 return blink::mojom::PresentationConnectionCloseReason::WENT_AWAY; | |
| 117 } | |
| 118 NOTREACHED() << "Unknown content::PresentationConnectionCloseReason " | |
| 119 << static_cast<int>(input); | |
| 120 return blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR; | |
| 121 } | |
| 122 | |
| 123 static bool FromMojom(blink::mojom::PresentationConnectionCloseReason input, | |
| 124 content::PresentationConnectionCloseReason* output) { | |
| 125 switch (input) { | |
| 126 case blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR: | |
| 127 *output = | |
| 128 content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR; | |
| 129 return true; | |
| 130 case blink::mojom::PresentationConnectionCloseReason::CLOSED: | |
| 131 *output = content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED; | |
| 132 return true; | |
| 133 case blink::mojom::PresentationConnectionCloseReason::WENT_AWAY: | |
| 134 *output = content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; | |
| 135 return true; | |
| 136 } | |
| 137 return false; | |
| 138 } | |
| 139 }; | |
| 140 | |
| 141 template <> | |
| 142 struct StructTraits<blink::mojom::PresentationSessionInfoDataView, | |
| 143 content::PresentationSessionInfo> { | |
| 144 static const GURL& url(const content::PresentationSessionInfo& session_info) { | |
| 145 return session_info.presentation_url; | |
| 146 } | |
| 147 | |
| 148 static const std::string& id( | |
| 149 const content::PresentationSessionInfo& session_info) { | |
| 150 return session_info.presentation_id; | |
| 151 } | |
| 152 | |
| 153 static bool Read(blink::mojom::PresentationSessionInfoDataView data, | |
| 154 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() > | |
|
Zhiqiang Zhang (Slow)
2017/02/01 14:55:41
The failure cause is here. I got the presentation_
| |
| 164 content::PresentationSessionInfo::kMaxIdLength) { | |
| 165 return false; | |
| 166 } | |
| 167 | |
| 168 return true; | |
| 169 } | |
| 170 }; | |
| 171 | |
| 172 template <> | |
| 173 struct StructTraits<blink::mojom::PresentationErrorDataView, | |
| 174 content::PresentationError> { | |
| 175 static content::PresentationErrorType error_type( | |
| 176 const content::PresentationError& error) { | |
| 177 return error.error_type; | |
| 178 } | |
| 179 | |
| 180 static const std::string& message(const content::PresentationError& error) { | |
| 181 return error.message; | |
| 182 } | |
| 183 | |
| 184 static bool Read(blink::mojom::PresentationErrorDataView data, | |
| 185 content::PresentationError* out) { | |
| 186 if (!data.ReadErrorType(&(out->error_type))) | |
| 187 return false; | |
| 188 | |
| 189 if (!data.ReadMessage(&(out->message))) | |
| 190 return false; | |
| 191 | |
| 192 if (!base::IsStringUTF8(out->message) || | |
| 193 out->message.length() > content::PresentationError::kMaxMessageLength) | |
| 194 return false; | |
| 195 | |
| 196 return true; | |
| 197 } | |
| 198 }; | |
| 199 | |
| 200 } // namespace mojo | |
| 201 | |
| 202 #endif // CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ | |
| OLD | NEW |