OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 #include "content/renderer/media/webcontentdecryptionmoduleresult_helper.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "third_party/WebKit/public/platform/WebString.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 static blink::WebContentDecryptionModuleException ConvertException( |
| 13 media::MediaKeys::Exception exception_code) { |
| 14 switch (exception_code) { |
| 15 case media::MediaKeys::NOT_SUPPORTED_ERROR: |
| 16 return blink::WebContentDecryptionModuleExceptionNotSupportedError; |
| 17 case media::MediaKeys::INVALID_STATE_ERROR: |
| 18 return blink::WebContentDecryptionModuleExceptionInvalidStateError; |
| 19 case media::MediaKeys::INVALID_ACCESS_ERROR: |
| 20 return blink::WebContentDecryptionModuleExceptionInvalidAccessError; |
| 21 case media::MediaKeys::QUOTA_EXCEEDED_ERROR: |
| 22 return blink::WebContentDecryptionModuleExceptionQuotaExceededError; |
| 23 case media::MediaKeys::UNKNOWN_ERROR: |
| 24 return blink::WebContentDecryptionModuleExceptionUnknownError; |
| 25 case media::MediaKeys::CLIENT_ERROR: |
| 26 return blink::WebContentDecryptionModuleExceptionClientError; |
| 27 case media::MediaKeys::OUTPUT_ERROR: |
| 28 return blink::WebContentDecryptionModuleExceptionOutputError; |
| 29 default: |
| 30 NOTREACHED(); |
| 31 return blink::WebContentDecryptionModuleExceptionUnknownError; |
| 32 } |
| 33 } |
| 34 |
| 35 WebContentDecryptionModuleResultHelper::WebContentDecryptionModuleResultHelper() |
| 36 : next_available_result_index_(1) { |
| 37 } |
| 38 |
| 39 WebContentDecryptionModuleResultHelper:: |
| 40 ~WebContentDecryptionModuleResultHelper() { |
| 41 // Release any WebContentDecryptionModuleResult objects that are left. Their |
| 42 // index will have been passed down via a CdmPromise, but it uses a WeakPtr. |
| 43 DLOG_IF(WARNING, outstanding_results_.size() > 0) |
| 44 << "Clearing " << outstanding_results_.size() << " results"; |
| 45 for (ResultMap::iterator it = outstanding_results_.begin(); |
| 46 it != outstanding_results_.end(); |
| 47 ++it) { |
| 48 it->second.completeWithError( |
| 49 blink::WebContentDecryptionModuleExceptionInvalidStateError, |
| 50 0, |
| 51 "Outstanding request being cancelled."); |
| 52 } |
| 53 outstanding_results_.clear(); |
| 54 } |
| 55 |
| 56 uint32 WebContentDecryptionModuleResultHelper::AddResult( |
| 57 blink::WebContentDecryptionModuleResult result) { |
| 58 uint32 result_index = next_available_result_index_++; |
| 59 outstanding_results_.insert(std::make_pair(result_index, result)); |
| 60 return result_index; |
| 61 } |
| 62 |
| 63 void WebContentDecryptionModuleResultHelper::Complete(uint32 result_index) { |
| 64 ResultMap::iterator it = outstanding_results_.find(result_index); |
| 65 if (it == outstanding_results_.end()) |
| 66 return; |
| 67 |
| 68 blink::WebContentDecryptionModuleResult& result = it->second; |
| 69 result.complete(); |
| 70 outstanding_results_.erase(it); |
| 71 } |
| 72 |
| 73 void WebContentDecryptionModuleResultHelper::CompleteWithSession( |
| 74 uint32 result_index, |
| 75 blink::WebContentDecryptionModuleResult::SessionStatus status) { |
| 76 ResultMap::iterator it = outstanding_results_.find(result_index); |
| 77 if (it == outstanding_results_.end()) |
| 78 return; |
| 79 |
| 80 blink::WebContentDecryptionModuleResult& result = it->second; |
| 81 result.completeWithSession(status); |
| 82 outstanding_results_.erase(it); |
| 83 } |
| 84 |
| 85 void WebContentDecryptionModuleResultHelper::CompleteWithKeyIds( |
| 86 uint32 result_index, |
| 87 const media::KeyIdsVector& key_ids) { |
| 88 ResultMap::iterator it = outstanding_results_.find(result_index); |
| 89 if (it == outstanding_results_.end()) |
| 90 return; |
| 91 |
| 92 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to handle |
| 93 // the set of keys. |
| 94 blink::WebContentDecryptionModuleResult& result = it->second; |
| 95 result.completeWithError( |
| 96 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| 97 0, |
| 98 "Not implemented."); |
| 99 outstanding_results_.erase(it); |
| 100 } |
| 101 |
| 102 void WebContentDecryptionModuleResultHelper::CompleteWithError( |
| 103 uint32 result_index, |
| 104 media::MediaKeys::Exception exception_code, |
| 105 uint32 system_code, |
| 106 const std::string& error_message) { |
| 107 ResultMap::iterator it = outstanding_results_.find(result_index); |
| 108 if (it == outstanding_results_.end()) |
| 109 return; |
| 110 |
| 111 blink::WebContentDecryptionModuleResult& result = it->second; |
| 112 result.completeWithError(ConvertException(exception_code), |
| 113 system_code, |
| 114 blink::WebString::fromUTF8(error_message)); |
| 115 outstanding_results_.erase(it); |
| 116 } |
| 117 |
| 118 } // namespace content |
OLD | NEW |