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..2d1b48ea34e27d344d200dba0a8d7a0af2fb2f60 |
--- /dev/null |
+++ b/content/renderer/media/webcontentdecryptionmoduleresult_helper.cc |
@@ -0,0 +1,143 @@ |
+// 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 "media/base/cdm_promise.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; |
+ } |
+} |
+ |
+class WebSimpleCdmPromise : public media::SimpleCdmPromise { |
ddorwin
2014/09/23 18:57:31
Can we eliminate a lot of duplication using templa
jrummell
2014/09/23 22:36:35
Done.
|
+ public: |
+ WebSimpleCdmPromise(blink::WebContentDecryptionModuleResult result) |
+ : media::SimpleCdmPromise( |
+ base::Bind(&WebSimpleCdmPromise::OnResolve, base::Unretained(this)), |
+ base::Bind(&WebSimpleCdmPromise::OnReject, base::Unretained(this))), |
+ webCDMResult_(result) {} |
+ |
+ private: |
+ void OnResolve() { webCDMResult_.complete(); } |
+ |
+ 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)); |
+ } |
+ |
+ blink::WebContentDecryptionModuleResult webCDMResult_; |
+}; |
+ |
+class WebNewSessionCdmPromise : public media::NewSessionCdmPromise { |
+ public: |
+ WebNewSessionCdmPromise(blink::WebContentDecryptionModuleResult result, |
+ const NewSessionCreatedCB& new_session_created_cb, |
+ std::string uma_name) |
+ : media::NewSessionCdmPromise( |
+ base::Bind(&WebNewSessionCdmPromise::OnResolve, |
+ base::Unretained(this)), |
+ base::Bind(&WebNewSessionCdmPromise::OnReject, |
+ base::Unretained(this)), |
+ uma_name), |
+ webCDMResult_(result), |
+ new_session_created_cb_(new_session_created_cb) {} |
+ |
+ private: |
+ void OnResolve(const std::string& web_session_id) { |
+ blink::WebContentDecryptionModuleResult::SessionStatus status = |
+ new_session_created_cb_.Run(web_session_id); |
+ webCDMResult_.completeWithSession(status); |
+ } |
+ |
+ 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)); |
+ } |
+ |
+ blink::WebContentDecryptionModuleResult webCDMResult_; |
+ NewSessionCreatedCB new_session_created_cb_; |
+}; |
+ |
+class WebKeyIdsPromise : public media::KeyIdsPromise { |
+ public: |
+ WebKeyIdsPromise(blink::WebContentDecryptionModuleResult result) |
+ : media::KeyIdsPromise( |
+ base::Bind(&WebKeyIdsPromise::OnResolve, base::Unretained(this)), |
+ base::Bind(&WebKeyIdsPromise::OnReject, base::Unretained(this))), |
+ webCDMResult_(result) {} |
+ |
+ private: |
+ void OnResolve(const media::KeyIdsVector& key_ids) { |
+ // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to |
+ // handle the set of keys. |
+ webCDMResult_.completeWithError( |
+ blink::WebContentDecryptionModuleExceptionNotSupportedError, |
+ 0, |
+ "Not implemented."); |
+ } |
+ |
+ 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)); |
+ } |
+ |
+ blink::WebContentDecryptionModuleResult webCDMResult_; |
+}; |
+ |
+scoped_ptr<media::SimpleCdmPromise> |
+WebContentDecryptionModuleResultHelper::CreateSimpleCdmPromise( |
+ blink::WebContentDecryptionModuleResult result) { |
+ return make_scoped_ptr<media::SimpleCdmPromise>( |
+ new WebSimpleCdmPromise(result)); |
+} |
+ |
+scoped_ptr<media::NewSessionCdmPromise> |
+WebContentDecryptionModuleResultHelper::CreateNewSessionCdmPromise( |
+ blink::WebContentDecryptionModuleResult result, |
+ const NewSessionCreatedCB& new_session_created_cb, |
+ std::string uma_name) { |
+ return make_scoped_ptr<media::NewSessionCdmPromise>( |
+ new WebNewSessionCdmPromise(result, new_session_created_cb, uma_name)); |
+} |
+ |
+scoped_ptr<media::KeyIdsPromise> |
+WebContentDecryptionModuleResultHelper::CreateKeyIdsPromise( |
+ blink::WebContentDecryptionModuleResult result) { |
+ return make_scoped_ptr<media::KeyIdsPromise>(new WebKeyIdsPromise(result)); |
+} |
+ |
+} // namespace content |