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

Side by Side Diff: media/blink/webcontentdecryptionmodulesession_impl.cc

Issue 2469353003: Skip base::string16 if not necessary for WebString <-> ASCII conversion (Closed)
Patch Set: minor fix Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « media/blink/key_system_config_selector.cc ('k') | media/blink/webencryptedmediaclient_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 NOTREACHED(); 161 NOTREACHED();
162 error_message->assign("Initialization data type is not supported."); 162 error_message->assign("Initialization data type is not supported.");
163 return false; 163 return false;
164 } 164 }
165 165
166 static bool SanitizeSessionId(const blink::WebString& session_id, 166 static bool SanitizeSessionId(const blink::WebString& session_id,
167 std::string* sanitized_session_id) { 167 std::string* sanitized_session_id) {
168 // The user agent should thoroughly validate the sessionId value before 168 // The user agent should thoroughly validate the sessionId value before
169 // passing it to the CDM. At a minimum, this should include checking that 169 // passing it to the CDM. At a minimum, this should include checking that
170 // the length and value (e.g. alphanumeric) are reasonable. 170 // the length and value (e.g. alphanumeric) are reasonable.
171 if (!base::IsStringASCII(session_id)) 171 if (!session_id.containsOnlyASCII())
172 return false; 172 return false;
173 173
174 sanitized_session_id->assign( 174 sanitized_session_id->assign(session_id.ascii());
175 base::UTF16ToASCII(base::StringPiece16(session_id)));
176 if (sanitized_session_id->length() > limits::kMaxSessionIdLength) 175 if (sanitized_session_id->length() > limits::kMaxSessionIdLength)
177 return false; 176 return false;
178 177
179 for (const char c : *sanitized_session_id) { 178 for (const char c : *sanitized_session_id) {
180 if (!base::IsAsciiAlpha(c) && !base::IsAsciiDigit(c)) 179 if (!base::IsAsciiAlpha(c) && !base::IsAsciiDigit(c))
181 return false; 180 return false;
182 } 181 }
183 182
184 return true; 183 return true;
185 } 184 }
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 464
466 DCHECK(session_id_.empty()) << "Session ID may not be changed once set."; 465 DCHECK(session_id_.empty()) << "Session ID may not be changed once set.";
467 session_id_ = session_id; 466 session_id_ = session_id;
468 *status = 467 *status =
469 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr()) 468 adapter_->RegisterSession(session_id_, weak_ptr_factory_.GetWeakPtr())
470 ? SessionInitStatus::NEW_SESSION 469 ? SessionInitStatus::NEW_SESSION
471 : SessionInitStatus::SESSION_ALREADY_EXISTS; 470 : SessionInitStatus::SESSION_ALREADY_EXISTS;
472 } 471 }
473 472
474 } // namespace media 473 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/key_system_config_selector.cc ('k') | media/blink/webencryptedmediaclient_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698