| 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..eece52fc5f898b21b49d84b41e5340aaa1c9fd03
|
| --- /dev/null
|
| +++ b/content/renderer/media/webcontentdecryptionmoduleresult_helper.cc
|
| @@ -0,0 +1,118 @@
|
| +// 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/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;
|
| + }
|
| +}
|
| +
|
| +WebContentDecryptionModuleResultHelper::WebContentDecryptionModuleResultHelper()
|
| + : next_available_result_index_(1) {
|
| +}
|
| +
|
| +WebContentDecryptionModuleResultHelper::
|
| + ~WebContentDecryptionModuleResultHelper() {
|
| + // Release any WebContentDecryptionModuleResult objects that are left. Their
|
| + // index will have been passed down via a CdmPromise, but it uses a WeakPtr.
|
| + DLOG_IF(WARNING, outstanding_results_.size() > 0)
|
| + << "Clearing " << outstanding_results_.size() << " results";
|
| + for (ResultMap::iterator it = outstanding_results_.begin();
|
| + it != outstanding_results_.end();
|
| + ++it) {
|
| + it->second.completeWithError(
|
| + blink::WebContentDecryptionModuleExceptionInvalidStateError,
|
| + 0,
|
| + "Outstanding request being cancelled.");
|
| + }
|
| + outstanding_results_.clear();
|
| +}
|
| +
|
| +uint32 WebContentDecryptionModuleResultHelper::AddResult(
|
| + blink::WebContentDecryptionModuleResult result) {
|
| + uint32 result_index = next_available_result_index_++;
|
| + outstanding_results_.insert(std::make_pair(result_index, result));
|
| + return result_index;
|
| +}
|
| +
|
| +void WebContentDecryptionModuleResultHelper::Complete(uint32 result_index) {
|
| + ResultMap::iterator it = outstanding_results_.find(result_index);
|
| + if (it == outstanding_results_.end())
|
| + return;
|
| +
|
| + blink::WebContentDecryptionModuleResult& result = it->second;
|
| + result.complete();
|
| + outstanding_results_.erase(it);
|
| +}
|
| +
|
| +void WebContentDecryptionModuleResultHelper::CompleteWithSession(
|
| + uint32 result_index,
|
| + blink::WebContentDecryptionModuleResult::SessionStatus status) {
|
| + ResultMap::iterator it = outstanding_results_.find(result_index);
|
| + if (it == outstanding_results_.end())
|
| + return;
|
| +
|
| + blink::WebContentDecryptionModuleResult& result = it->second;
|
| + result.completeWithSession(status);
|
| + outstanding_results_.erase(it);
|
| +}
|
| +
|
| +void WebContentDecryptionModuleResultHelper::CompleteWithKeyIds(
|
| + uint32 result_index,
|
| + const media::KeyIdsVector& key_ids) {
|
| + ResultMap::iterator it = outstanding_results_.find(result_index);
|
| + if (it == outstanding_results_.end())
|
| + return;
|
| +
|
| + // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to handle
|
| + // the set of keys.
|
| + blink::WebContentDecryptionModuleResult& result = it->second;
|
| + result.completeWithError(
|
| + blink::WebContentDecryptionModuleExceptionNotSupportedError,
|
| + 0,
|
| + "Not implemented.");
|
| + outstanding_results_.erase(it);
|
| +}
|
| +
|
| +void WebContentDecryptionModuleResultHelper::CompleteWithError(
|
| + uint32 result_index,
|
| + media::MediaKeys::Exception exception_code,
|
| + uint32 system_code,
|
| + const std::string& error_message) {
|
| + ResultMap::iterator it = outstanding_results_.find(result_index);
|
| + if (it == outstanding_results_.end())
|
| + return;
|
| +
|
| + blink::WebContentDecryptionModuleResult& result = it->second;
|
| + result.completeWithError(ConvertException(exception_code),
|
| + system_code,
|
| + blink::WebString::fromUTF8(error_message));
|
| + outstanding_results_.erase(it);
|
| +}
|
| +
|
| +} // namespace content
|
|
|