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/bind.h" | |
8 #include "base/logging.h" | |
9 #include "media/base/cdm_promise.h" | |
10 #include "third_party/WebKit/public/platform/WebString.h" | |
11 | |
12 namespace content { | |
13 | |
14 static blink::WebContentDecryptionModuleException ConvertException( | |
15 media::MediaKeys::Exception exception_code) { | |
16 switch (exception_code) { | |
17 case media::MediaKeys::NOT_SUPPORTED_ERROR: | |
18 return blink::WebContentDecryptionModuleExceptionNotSupportedError; | |
19 case media::MediaKeys::INVALID_STATE_ERROR: | |
20 return blink::WebContentDecryptionModuleExceptionInvalidStateError; | |
21 case media::MediaKeys::INVALID_ACCESS_ERROR: | |
22 return blink::WebContentDecryptionModuleExceptionInvalidAccessError; | |
23 case media::MediaKeys::QUOTA_EXCEEDED_ERROR: | |
24 return blink::WebContentDecryptionModuleExceptionQuotaExceededError; | |
25 case media::MediaKeys::UNKNOWN_ERROR: | |
26 return blink::WebContentDecryptionModuleExceptionUnknownError; | |
27 case media::MediaKeys::CLIENT_ERROR: | |
28 return blink::WebContentDecryptionModuleExceptionClientError; | |
29 case media::MediaKeys::OUTPUT_ERROR: | |
30 return blink::WebContentDecryptionModuleExceptionOutputError; | |
31 default: | |
32 NOTREACHED(); | |
33 return blink::WebContentDecryptionModuleExceptionUnknownError; | |
34 } | |
35 } | |
36 | |
37 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.
| |
38 public: | |
39 WebSimpleCdmPromise(blink::WebContentDecryptionModuleResult result) | |
40 : media::SimpleCdmPromise( | |
41 base::Bind(&WebSimpleCdmPromise::OnResolve, base::Unretained(this)), | |
42 base::Bind(&WebSimpleCdmPromise::OnReject, base::Unretained(this))), | |
43 webCDMResult_(result) {} | |
44 | |
45 private: | |
46 void OnResolve() { webCDMResult_.complete(); } | |
47 | |
48 void OnReject(media::MediaKeys::Exception exception_code, | |
49 uint32 system_code, | |
50 const std::string& error_message) { | |
51 webCDMResult_.completeWithError(ConvertException(exception_code), | |
52 system_code, | |
53 blink::WebString::fromUTF8(error_message)); | |
54 } | |
55 | |
56 blink::WebContentDecryptionModuleResult webCDMResult_; | |
57 }; | |
58 | |
59 class WebNewSessionCdmPromise : public media::NewSessionCdmPromise { | |
60 public: | |
61 WebNewSessionCdmPromise(blink::WebContentDecryptionModuleResult result, | |
62 const NewSessionCreatedCB& new_session_created_cb, | |
63 std::string uma_name) | |
64 : media::NewSessionCdmPromise( | |
65 base::Bind(&WebNewSessionCdmPromise::OnResolve, | |
66 base::Unretained(this)), | |
67 base::Bind(&WebNewSessionCdmPromise::OnReject, | |
68 base::Unretained(this)), | |
69 uma_name), | |
70 webCDMResult_(result), | |
71 new_session_created_cb_(new_session_created_cb) {} | |
72 | |
73 private: | |
74 void OnResolve(const std::string& web_session_id) { | |
75 blink::WebContentDecryptionModuleResult::SessionStatus status = | |
76 new_session_created_cb_.Run(web_session_id); | |
77 webCDMResult_.completeWithSession(status); | |
78 } | |
79 | |
80 void OnReject(media::MediaKeys::Exception exception_code, | |
81 uint32 system_code, | |
82 const std::string& error_message) { | |
83 webCDMResult_.completeWithError(ConvertException(exception_code), | |
84 system_code, | |
85 blink::WebString::fromUTF8(error_message)); | |
86 } | |
87 | |
88 blink::WebContentDecryptionModuleResult webCDMResult_; | |
89 NewSessionCreatedCB new_session_created_cb_; | |
90 }; | |
91 | |
92 class WebKeyIdsPromise : public media::KeyIdsPromise { | |
93 public: | |
94 WebKeyIdsPromise(blink::WebContentDecryptionModuleResult result) | |
95 : media::KeyIdsPromise( | |
96 base::Bind(&WebKeyIdsPromise::OnResolve, base::Unretained(this)), | |
97 base::Bind(&WebKeyIdsPromise::OnReject, base::Unretained(this))), | |
98 webCDMResult_(result) {} | |
99 | |
100 private: | |
101 void OnResolve(const media::KeyIdsVector& key_ids) { | |
102 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to | |
103 // handle the set of keys. | |
104 webCDMResult_.completeWithError( | |
105 blink::WebContentDecryptionModuleExceptionNotSupportedError, | |
106 0, | |
107 "Not implemented."); | |
108 } | |
109 | |
110 void OnReject(media::MediaKeys::Exception exception_code, | |
111 uint32 system_code, | |
112 const std::string& error_message) { | |
113 webCDMResult_.completeWithError(ConvertException(exception_code), | |
114 system_code, | |
115 blink::WebString::fromUTF8(error_message)); | |
116 } | |
117 | |
118 blink::WebContentDecryptionModuleResult webCDMResult_; | |
119 }; | |
120 | |
121 scoped_ptr<media::SimpleCdmPromise> | |
122 WebContentDecryptionModuleResultHelper::CreateSimpleCdmPromise( | |
123 blink::WebContentDecryptionModuleResult result) { | |
124 return make_scoped_ptr<media::SimpleCdmPromise>( | |
125 new WebSimpleCdmPromise(result)); | |
126 } | |
127 | |
128 scoped_ptr<media::NewSessionCdmPromise> | |
129 WebContentDecryptionModuleResultHelper::CreateNewSessionCdmPromise( | |
130 blink::WebContentDecryptionModuleResult result, | |
131 const NewSessionCreatedCB& new_session_created_cb, | |
132 std::string uma_name) { | |
133 return make_scoped_ptr<media::NewSessionCdmPromise>( | |
134 new WebNewSessionCdmPromise(result, new_session_created_cb, uma_name)); | |
135 } | |
136 | |
137 scoped_ptr<media::KeyIdsPromise> | |
138 WebContentDecryptionModuleResultHelper::CreateKeyIdsPromise( | |
139 blink::WebContentDecryptionModuleResult result) { | |
140 return make_scoped_ptr<media::KeyIdsPromise>(new WebKeyIdsPromise(result)); | |
141 } | |
142 | |
143 } // namespace content | |
OLD | NEW |