Chromium Code Reviews| Index: content/renderer/media/webcontentdecryptionmoduleresult_helper.cc |
| diff --git a/content/renderer/media/webcontentdecryptionmoduleresult_helper.cc b/content/renderer/media/webcontentdecryptionmoduleresult_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cd0396c634243d7863ad78b5f19d2db471842286 |
| --- /dev/null |
| +++ b/content/renderer/media/webcontentdecryptionmoduleresult_helper.cc |
| @@ -0,0 +1,127 @@ |
| +// Copyright 2014 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/renderer/media/webcontentdecryptionmoduleresult_helper.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "third_party/WebKit/public/platform/WebString.h" |
| + |
| +namespace content { |
| + |
| +static blink::WebContentDecryptionModuleException ConvertException( |
| + media::MediaKeys::Exception exception_code) { |
| + switch (exception_code) { |
| + case media::MediaKeys::NOT_SUPPORTED_ERROR: |
| + return blink::WebContentDecryptionModuleExceptionNotSupportedError; |
| + case media::MediaKeys::INVALID_STATE_ERROR: |
| + return blink::WebContentDecryptionModuleExceptionInvalidStateError; |
| + case media::MediaKeys::INVALID_ACCESS_ERROR: |
| + return blink::WebContentDecryptionModuleExceptionInvalidAccessError; |
| + case media::MediaKeys::QUOTA_EXCEEDED_ERROR: |
| + return blink::WebContentDecryptionModuleExceptionQuotaExceededError; |
| + case media::MediaKeys::UNKNOWN_ERROR: |
| + return blink::WebContentDecryptionModuleExceptionUnknownError; |
| + case media::MediaKeys::CLIENT_ERROR: |
| + return blink::WebContentDecryptionModuleExceptionClientError; |
| + case media::MediaKeys::OUTPUT_ERROR: |
| + return blink::WebContentDecryptionModuleExceptionOutputError; |
| + default: |
| + NOTREACHED(); |
| + return blink::WebContentDecryptionModuleExceptionUnknownError; |
| + } |
| +} |
| + |
| +template <typename T> |
| +BlinkCdmPromiseTemplate<T>::BlinkCdmPromiseTemplate( |
| + blink::WebContentDecryptionModuleResult result) |
| + : media::CdmPromiseTemplate<T>( |
| + base::Bind(&BlinkCdmPromiseTemplate::OnResolve, |
| + base::Unretained(this)), |
| + base::Bind(&BlinkCdmPromiseTemplate::OnReject, |
| + base::Unretained(this))), |
| + webCDMResult_(result) { |
| +} |
| + |
| +template <typename T> |
| +BlinkCdmPromiseTemplate<T>::BlinkCdmPromiseTemplate( |
| + blink::WebContentDecryptionModuleResult result, |
| + const std::string& uma_name) |
| + : media::CdmPromiseTemplate<T>( |
| + base::Bind(&BlinkCdmPromiseTemplate::OnResolve, |
| + base::Unretained(this)), |
| + base::Bind(&BlinkCdmPromiseTemplate::OnReject, |
| + base::Unretained(this)), |
| + uma_name), |
| + webCDMResult_(result) { |
| +} |
| + |
| +template <> |
| +void BlinkCdmPromiseTemplate<std::string>::OnResolve( |
| + const std::string& result) { |
| + // This must be overridden in a subclass. |
|
ddorwin
2014/09/23 23:14:21
Will it link if you leave this out?
Actually, how
jrummell
2014/09/24 00:49:32
Linking fails if I leave it out. Testing with the
|
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +template <> |
| +void BlinkCdmPromiseTemplate<media::KeyIdsVector>::OnResolve( |
| + const media::KeyIdsVector& result) { |
| + // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to |
| + // handle the set of keys. |
| + webCDMResult_.completeWithError( |
|
ddorwin
2014/09/23 23:14:21
nit: This is a bit simpler if you just call OnReje
jrummell
2014/09/24 00:49:32
Fits on one line now.
|
| + blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| + 0, |
| + "Not implemented."); |
| +} |
| + |
| +template <typename T> |
| +void BlinkCdmPromiseTemplate<T>::OnReject( |
| + media::MediaKeys::Exception exception_code, |
| + uint32 system_code, |
| + const std::string& error_message) { |
| + webCDMResult_.completeWithError(ConvertException(exception_code), |
| + system_code, |
| + blink::WebString::fromUTF8(error_message)); |
| +} |
| + |
| +BlinkCdmPromiseTemplate<void>::BlinkCdmPromiseTemplate( |
| + blink::WebContentDecryptionModuleResult result) |
| + : media::CdmPromiseTemplate<void>( |
| + base::Bind(&BlinkCdmPromiseTemplate::OnResolve, |
| + base::Unretained(this)), |
| + base::Bind(&BlinkCdmPromiseTemplate::OnReject, |
| + base::Unretained(this))), |
| + webCDMResult_(result) { |
| +} |
| + |
| +BlinkCdmPromiseTemplate<void>::BlinkCdmPromiseTemplate( |
| + blink::WebContentDecryptionModuleResult result, |
| + const std::string& uma_name) |
| + : media::CdmPromiseTemplate<void>( |
| + base::Bind(&BlinkCdmPromiseTemplate::OnResolve, |
| + base::Unretained(this)), |
| + base::Bind(&BlinkCdmPromiseTemplate::OnReject, |
| + base::Unretained(this)), |
| + uma_name), |
| + webCDMResult_(result) { |
| +} |
| + |
| +void BlinkCdmPromiseTemplate<void>::OnResolve() { |
| + webCDMResult_.complete(); |
| +} |
| + |
| +void BlinkCdmPromiseTemplate<void>::OnReject( |
| + media::MediaKeys::Exception exception_code, |
| + uint32 system_code, |
| + const std::string& error_message) { |
| + webCDMResult_.completeWithError(ConvertException(exception_code), |
| + system_code, |
| + blink::WebString::fromUTF8(error_message)); |
| +} |
| + |
| +// Explicit template instantiation for the templates needed. |
| +template class BlinkCdmPromiseTemplate<std::string>; |
| +template class BlinkCdmPromiseTemplate<media::KeyIdsVector>; |
| + |
| +} // namespace content |