OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "webcontentdecryptionmodulesession_impl.h" | 5 #include "webcontentdecryptionmodulesession_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 | 159 |
160 static bool SanitizeSessionId(const blink::WebString& session_id, | 160 static bool SanitizeSessionId(const blink::WebString& session_id, |
161 std::string* sanitized_session_id) { | 161 std::string* sanitized_session_id) { |
162 // The user agent should thoroughly validate the sessionId value before | 162 // The user agent should thoroughly validate the sessionId value before |
163 // passing it to the CDM. At a minimum, this should include checking that | 163 // passing it to the CDM. At a minimum, this should include checking that |
164 // the length and value (e.g. alphanumeric) are reasonable. | 164 // the length and value (e.g. alphanumeric) are reasonable. |
165 if (!base::IsStringASCII(session_id)) | 165 if (!base::IsStringASCII(session_id)) |
166 return false; | 166 return false; |
167 | 167 |
168 sanitized_session_id->assign(base::UTF16ToASCII(session_id)); | 168 sanitized_session_id->assign( |
| 169 base::UTF16ToASCII(base::StringPiece16(session_id))); |
169 if (sanitized_session_id->length() > limits::kMaxSessionIdLength) | 170 if (sanitized_session_id->length() > limits::kMaxSessionIdLength) |
170 return false; | 171 return false; |
171 | 172 |
172 for (const char c : *sanitized_session_id) { | 173 for (const char c : *sanitized_session_id) { |
173 if (!base::IsAsciiAlpha(c) && !base::IsAsciiDigit(c)) | 174 if (!base::IsAsciiAlpha(c) && !base::IsAsciiDigit(c)) |
174 return false; | 175 return false; |
175 } | 176 } |
176 | 177 |
177 return true; | 178 return true; |
178 } | 179 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 return blink::WebContentDecryptionModuleResult::SessionNotFound; | 417 return blink::WebContentDecryptionModuleResult::SessionNotFound; |
417 | 418 |
418 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; | 419 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; |
419 session_id_ = session_id; | 420 session_id_ = session_id; |
420 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) | 421 return adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) |
421 ? blink::WebContentDecryptionModuleResult::NewSession | 422 ? blink::WebContentDecryptionModuleResult::NewSession |
422 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; | 423 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; |
423 } | 424 } |
424 | 425 |
425 } // namespace media | 426 } // namespace media |
OLD | NEW |