Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / media / mojo / services / mojo_cdm.h
blob4c29577139ce5a4e7f9f5d1c3f4ac72ec4ad586d
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.
5 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_H_
8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "media/base/media_keys.h"
11 #include "media/mojo/interfaces/content_decryption_module.mojom.h"
12 #include "media/mojo/services/mojo_type_trait.h"
14 namespace mojo {
15 class ServiceProvider;
18 namespace media {
20 // A MediaKeys that proxies to a mojo::ContentDecryptionModule. That
21 // mojo::ContentDecryptionModule proxies back to the MojoCdm via the
22 // mojo::ContentDecryptionModuleClient interface.
23 class MojoCdm : public MediaKeys, public mojo::ContentDecryptionModuleClient {
24 public:
25 // |media_renderer_provider| is a ServiceProvider from a connected
26 // Application that is hosting a mojo::MediaRenderer.
27 MojoCdm(mojo::ContentDecryptionModulePtr remote_cdm,
28 const SessionMessageCB& session_message_cb,
29 const SessionClosedCB& session_closed_cb,
30 const LegacySessionErrorCB& legacy_session_error_cb,
31 const SessionKeysChangeCB& session_keys_change_cb,
32 const SessionExpirationUpdateCB& session_expiration_update_cb);
33 ~MojoCdm() final;
35 // MediaKeys implementation.
36 void SetServerCertificate(const uint8_t* certificate_data,
37 int certificate_data_length,
38 scoped_ptr<SimpleCdmPromise> promise) final;
39 void CreateSessionAndGenerateRequest(
40 SessionType session_type,
41 EmeInitDataType init_data_type,
42 const uint8_t* init_data,
43 int init_data_length,
44 scoped_ptr<NewSessionCdmPromise> promise) final;
45 void LoadSession(SessionType session_type,
46 const std::string& session_id,
47 scoped_ptr<NewSessionCdmPromise> promise) final;
48 void UpdateSession(const std::string& session_id,
49 const uint8_t* response,
50 int response_length,
51 scoped_ptr<SimpleCdmPromise> promise) final;
52 void CloseSession(const std::string& session_id,
53 scoped_ptr<SimpleCdmPromise> promise) final;
54 void RemoveSession(const std::string& session_id,
55 scoped_ptr<SimpleCdmPromise> promise) final;
56 CdmContext* GetCdmContext() final;
58 private:
59 // mojo::ContentDecryptionModuleClient implementation.
60 void OnSessionMessage(const mojo::String& session_id,
61 mojo::CdmMessageType message_type,
62 mojo::Array<uint8_t> message,
63 const mojo::String& legacy_destination_url) final;
64 void OnSessionClosed(const mojo::String& session_id) final;
65 void OnLegacySessionError(const mojo::String& session_id,
66 mojo::CdmException exception,
67 uint32_t system_code,
68 const mojo::String& error_message) final;
69 void OnSessionKeysChange(
70 const mojo::String& session_id,
71 bool has_additional_usable_key,
72 mojo::Array<mojo::CdmKeyInformationPtr> keys_info) final;
73 void OnSessionExpirationUpdate(const mojo::String& session_id,
74 double new_expiry_time_sec) final;
76 // Callbacks to handle CDM promises.
77 // We have to inline this method, since MS VS 2013 compiler fails to compile
78 // it when this method is not inlined. It fails with error C2244
79 // "unable to match function definition to an existing declaration".
80 template <typename... T>
81 void OnPromiseResult(scoped_ptr<CdmPromiseTemplate<T...>> promise,
82 mojo::CdmPromiseResultPtr result,
83 typename MojoTypeTrait<T>::MojoType... args) {
84 if (result->success)
85 promise->resolve(args.template To<T>()...); // See ISO C++03 14.2/4.
86 else
87 RejectPromise(promise.Pass(), result.Pass());
90 mojo::ContentDecryptionModulePtr remote_cdm_;
91 mojo::Binding<ContentDecryptionModuleClient> binding_;
93 // Callbacks for firing session events.
94 SessionMessageCB session_message_cb_;
95 SessionClosedCB session_closed_cb_;
96 LegacySessionErrorCB legacy_session_error_cb_;
97 SessionKeysChangeCB session_keys_change_cb_;
98 SessionExpirationUpdateCB session_expiration_update_cb_;
100 base::WeakPtrFactory<MojoCdm> weak_factory_;
102 DISALLOW_COPY_AND_ASSIGN(MojoCdm);
105 } // namespace media
107 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_H_