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 "content/public/common/presentation_session.h" | |
| 12 #include "mojo/common/common_custom_types_struct_traits.h" | |
| 13 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" | |
| 14 #include "url/mojo/url.mojom.h" | |
| 15 | |
| 16 namespace mojo { | |
| 17 | |
| 18 template <> | |
| 19 struct EnumTraits<blink::mojom::PresentationErrorType, | |
| 20 content::PresentationErrorType> { | |
| 21 static blink::mojom::PresentationErrorType ToMojom( | |
| 22 content::PresentationErrorType input) { | |
| 23 switch (input) { | |
| 24 case content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS: | |
| 25 return blink::mojom::PresentationErrorType::NO_AVAILABLE_SCREENS; | |
| 26 case content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED: | |
| 27 return blink::mojom::PresentationErrorType::SESSION_REQUEST_CANCELLED; | |
| 28 case content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND: | |
| 29 return blink::mojom::PresentationErrorType::NO_PRESENTATION_FOUND; | |
| 30 case content::PRESENTATION_ERROR_UNKNOWN: | |
| 31 return blink::mojom::PresentationErrorType::UNKNOWN; | |
| 32 } | |
| 33 NOTREACHED() << "Unknown content::PresentationErrorType " | |
| 34 << static_cast<int>(input); | |
| 35 return blink::mojom::PresentationErrorType::UNKNOWN; | |
| 36 } | |
| 37 | |
| 38 static bool FromMojom(blink::mojom::PresentationErrorType input, | |
| 39 content::PresentationErrorType* output) { | |
| 40 switch (input) { | |
| 41 case blink::mojom::PresentationErrorType::NO_AVAILABLE_SCREENS: | |
| 42 *output = content::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS; | |
| 43 return true; | |
| 44 case blink::mojom::PresentationErrorType::SESSION_REQUEST_CANCELLED: | |
| 45 *output = content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED; | |
| 46 return true; | |
| 47 case blink::mojom::PresentationErrorType::NO_PRESENTATION_FOUND: | |
| 48 *output = content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND; | |
| 49 return true; | |
| 50 case blink::mojom::PresentationErrorType::UNKNOWN: | |
| 51 *output = content::PRESENTATION_ERROR_UNKNOWN; | |
| 52 return true; | |
| 53 } | |
| 54 return false; | |
| 55 } | |
| 56 }; | |
| 57 | |
| 58 template <> | |
| 59 struct EnumTraits<blink::mojom::PresentationConnectionState, | |
| 60 content::PresentationConnectionState> { | |
| 61 static blink::mojom::PresentationConnectionState ToMojom( | |
| 62 content::PresentationConnectionState input) { | |
| 63 switch (input) { | |
| 64 case content::PRESENTATION_CONNECTION_STATE_CONNECTING: | |
| 65 return blink::mojom::PresentationConnectionState::CONNECTING; | |
| 66 case content::PRESENTATION_CONNECTION_STATE_CONNECTED: | |
| 67 return blink::mojom::PresentationConnectionState::CONNECTED; | |
| 68 case content::PRESENTATION_CONNECTION_STATE_CLOSED: | |
| 69 return blink::mojom::PresentationConnectionState::CLOSED; | |
| 70 case content::PRESENTATION_CONNECTION_STATE_TERMINATED: | |
| 71 return blink::mojom::PresentationConnectionState::TERMINATED; | |
| 72 } | |
| 73 NOTREACHED() << "Unknown content::PresentationConnectionState " | |
| 74 << static_cast<int>(input); | |
| 75 return blink::mojom::PresentationConnectionState::CONNECTING; | |
|
nasko
2017/01/25 17:58:16
This is different than the code before, which retu
mark a. foltz
2017/01/27 22:41:08
No, changed to TERMINATED to keep behavior consist
| |
| 76 } | |
| 77 | |
| 78 static bool FromMojom(blink::mojom::PresentationConnectionState input, | |
| 79 content::PresentationConnectionState* output) { | |
| 80 switch (input) { | |
| 81 case blink::mojom::PresentationConnectionState::CONNECTING: | |
| 82 *output = content::PRESENTATION_CONNECTION_STATE_CONNECTING; | |
| 83 return true; | |
| 84 case blink::mojom::PresentationConnectionState::CONNECTED: | |
| 85 *output = content::PRESENTATION_CONNECTION_STATE_CONNECTED; | |
| 86 return true; | |
| 87 case blink::mojom::PresentationConnectionState::CLOSED: | |
| 88 *output = content::PRESENTATION_CONNECTION_STATE_CLOSED; | |
| 89 return true; | |
| 90 case blink::mojom::PresentationConnectionState::TERMINATED: | |
| 91 *output = content::PRESENTATION_CONNECTION_STATE_TERMINATED; | |
| 92 return true; | |
| 93 } | |
| 94 return false; | |
| 95 } | |
| 96 }; | |
| 97 | |
| 98 template <> | |
| 99 struct EnumTraits<blink::mojom::PresentationConnectionCloseReason, | |
| 100 content::PresentationConnectionCloseReason> { | |
| 101 static blink::mojom::PresentationConnectionCloseReason ToMojom( | |
| 102 content::PresentationConnectionCloseReason input) { | |
| 103 switch (input) { | |
| 104 case content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR: | |
| 105 return blink::mojom::PresentationConnectionCloseReason:: | |
| 106 CONNECTION_ERROR; | |
| 107 case content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED: | |
| 108 return blink::mojom::PresentationConnectionCloseReason::CLOSED; | |
| 109 case content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY: | |
| 110 return blink::mojom::PresentationConnectionCloseReason::WENT_AWAY; | |
| 111 } | |
| 112 NOTREACHED() << "Unknown content::PresentationConnectionCloseReason " | |
| 113 << static_cast<int>(input); | |
| 114 return blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR; | |
| 115 } | |
| 116 | |
| 117 static bool FromMojom(blink::mojom::PresentationConnectionCloseReason input, | |
| 118 content::PresentationConnectionCloseReason* output) { | |
| 119 switch (input) { | |
| 120 case blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR: | |
| 121 *output = | |
| 122 content::PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR; | |
| 123 return true; | |
| 124 case blink::mojom::PresentationConnectionCloseReason::CLOSED: | |
| 125 *output = content::PRESENTATION_CONNECTION_CLOSE_REASON_CLOSED; | |
| 126 return true; | |
| 127 case blink::mojom::PresentationConnectionCloseReason::WENT_AWAY: | |
| 128 *output = content::PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY; | |
| 129 return true; | |
| 130 } | |
| 131 return false; | |
| 132 } | |
| 133 }; | |
| 134 | |
| 135 // TODO(mfoltz): Add some validations? | |
|
nasko
2017/01/25 17:58:16
Do we expect this to be resolved in this CL with s
mark a. foltz
2017/01/27 22:41:08
Added validations for the error message and presen
| |
| 136 | |
| 137 template <> | |
| 138 struct StructTraits<blink::mojom::PresentationSessionInfoDataView, | |
| 139 content::PresentationSessionInfo> { | |
| 140 static const GURL& url(const content::PresentationSessionInfo& session_info) { | |
| 141 return session_info.presentation_url; | |
| 142 } | |
| 143 | |
| 144 static const std::string& id( | |
| 145 const content::PresentationSessionInfo& session_info) { | |
| 146 return session_info.presentation_id; | |
| 147 } | |
| 148 | |
| 149 static bool Read(blink::mojom::PresentationSessionInfoDataView data, | |
| 150 content::PresentationSessionInfo* out) { | |
| 151 if (!data.ReadUrl(&(out->presentation_url))) | |
| 152 return false; | |
| 153 | |
| 154 if (!data.ReadId(&(out->presentation_id))) | |
| 155 return false; | |
| 156 | |
| 157 return true; | |
| 158 } | |
| 159 }; | |
| 160 | |
| 161 template <> | |
| 162 struct StructTraits<blink::mojom::PresentationErrorDataView, | |
| 163 content::PresentationError> { | |
| 164 static content::PresentationErrorType error_type( | |
| 165 const content::PresentationError& error) { | |
| 166 return error.error_type; | |
| 167 } | |
| 168 | |
| 169 static const std::string& message(const content::PresentationError& error) { | |
| 170 return error.message; | |
| 171 } | |
| 172 | |
| 173 static bool Read(blink::mojom::PresentationErrorDataView data, | |
| 174 content::PresentationError* out) { | |
| 175 if (!data.ReadErrorType(&(out->error_type))) | |
| 176 return false; | |
| 177 | |
| 178 if (!data.ReadMessage(&(out->message))) | |
| 179 return false; | |
| 180 | |
| 181 return true; | |
| 182 } | |
| 183 }; | |
| 184 | |
| 185 } // namespace mojo | |
| 186 | |
| 187 #endif // CONTENT_COMMON_PRESENTATION_PRESENTATION_STRUCT_TRAITS_H_ | |
| OLD | NEW |