[ServiceWorker] Implement WebServiceWorkerContextClient::openWindow().
[chromium-blink-merge.git] / content / renderer / media / crypto / proxy_media_keys.h
blobbbd17e58e7e66eabcbc7f46d1739cf8438cbd6d1
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 CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "media/base/cdm_context.h"
15 #include "media/base/cdm_promise.h"
16 #include "media/base/cdm_promise_adapter.h"
17 #include "media/base/media_keys.h"
19 class GURL;
21 namespace content {
23 class RendererCdmManager;
25 // A MediaKeys proxy that wraps the EME part of RendererCdmManager.
26 class ProxyMediaKeys : public media::MediaKeys, public media::CdmContext {
27 public:
28 static scoped_ptr<ProxyMediaKeys> Create(
29 const std::string& key_system,
30 const GURL& security_origin,
31 RendererCdmManager* manager,
32 const media::SessionMessageCB& session_message_cb,
33 const media::SessionClosedCB& session_closed_cb,
34 const media::SessionErrorCB& session_error_cb,
35 const media::SessionKeysChangeCB& session_keys_change_cb,
36 const media::SessionExpirationUpdateCB& session_expiration_update_cb);
38 ~ProxyMediaKeys() override;
40 // MediaKeys implementation.
41 void SetServerCertificate(
42 const uint8* certificate_data,
43 int certificate_data_length,
44 scoped_ptr<media::SimpleCdmPromise> promise) override;
45 void CreateSessionAndGenerateRequest(
46 SessionType session_type,
47 const std::string& init_data_type,
48 const uint8* init_data,
49 int init_data_length,
50 scoped_ptr<media::NewSessionCdmPromise> promise) override;
51 void LoadSession(SessionType session_type,
52 const std::string& session_id,
53 scoped_ptr<media::NewSessionCdmPromise> promise) override;
54 void UpdateSession(const std::string& session_id,
55 const uint8* response,
56 int response_length,
57 scoped_ptr<media::SimpleCdmPromise> promise) override;
58 void CloseSession(const std::string& session_id,
59 scoped_ptr<media::SimpleCdmPromise> promise) override;
60 void RemoveSession(const std::string& session_id,
61 scoped_ptr<media::SimpleCdmPromise> promise) override;
62 media::CdmContext* GetCdmContext() override;
64 // media::CdmContext implementation.
65 media::Decryptor* GetDecryptor() override;
66 int GetCdmId() const override;
68 // Callbacks.
69 void OnSessionMessage(const std::string& session_id,
70 media::MediaKeys::MessageType message_type,
71 const std::vector<uint8>& message,
72 const GURL& legacy_destination_url);
73 void OnSessionClosed(const std::string& session_id);
74 void OnLegacySessionError(const std::string& session_id,
75 media::MediaKeys::Exception exception,
76 uint32 system_code,
77 const std::string& error_message);
78 void OnSessionKeysChange(const std::string& session_id,
79 bool has_additional_usable_key,
80 media::CdmKeysInfo keys_info);
81 void OnSessionExpirationUpdate(const std::string& session_id,
82 const base::Time& new_expiry_time);
84 void OnPromiseResolved(uint32_t promise_id);
85 void OnPromiseResolvedWithSession(uint32_t promise_id,
86 const std::string& session_id);
87 void OnPromiseRejected(uint32_t promise_id,
88 media::MediaKeys::Exception exception,
89 uint32_t system_code,
90 const std::string& error_message);
92 private:
93 ProxyMediaKeys(
94 RendererCdmManager* manager,
95 const media::SessionMessageCB& session_message_cb,
96 const media::SessionClosedCB& session_closed_cb,
97 const media::SessionErrorCB& session_error_cb,
98 const media::SessionKeysChangeCB& session_keys_change_cb,
99 const media::SessionExpirationUpdateCB& session_expiration_update_cb);
101 void InitializeCdm(const std::string& key_system,
102 const GURL& security_origin);
104 RendererCdmManager* manager_;
105 int cdm_id_;
107 media::SessionMessageCB session_message_cb_;
108 media::SessionClosedCB session_closed_cb_;
109 media::SessionErrorCB session_error_cb_;
110 media::SessionKeysChangeCB session_keys_change_cb_;
111 media::SessionExpirationUpdateCB session_expiration_update_cb_;
113 media::CdmPromiseAdapter cdm_promise_adapter_;
115 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys);
118 } // namespace content
120 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_