Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / renderer / media / crypto / encrypted_media_player_support_impl.h
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 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_ENCRYPTED_MEDIA_PLAYER_SUPPORT_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_ENCRYPTED_MEDIA_PLAYER_SUPPORT_IMPL_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/weak_ptr.h"
12 #include "content/renderer/media/crypto/proxy_decryptor.h"
13 #include "media/blink/encrypted_media_player_support.h"
14
15 namespace blink {
16 class WebMediaPlayerClient;
17 }
18
19 namespace content {
20
21 class WebContentDecryptionModuleImpl;
22
23 class EncryptedMediaPlayerSupportImpl
24     : public media::EncryptedMediaPlayerSupport,
25       public base::SupportsWeakPtr<EncryptedMediaPlayerSupportImpl> {
26  public:
27   static scoped_ptr<EncryptedMediaPlayerSupport> Create(
28       blink::WebMediaPlayerClient* client);
29
30   virtual ~EncryptedMediaPlayerSupportImpl();
31
32   // EncryptedMediaPlayerSupport implementation.
33   virtual blink::WebMediaPlayer::MediaKeyException GenerateKeyRequest(
34       blink::WebLocalFrame* frame,
35       const blink::WebString& key_system,
36       const unsigned char* init_data,
37       unsigned init_data_length)  OVERRIDE;
38
39   virtual blink::WebMediaPlayer::MediaKeyException AddKey(
40       const blink::WebString& key_system,
41       const unsigned char* key,
42       unsigned key_length,
43       const unsigned char* init_data,
44       unsigned init_data_length,
45       const blink::WebString& session_id) OVERRIDE;
46
47   virtual blink::WebMediaPlayer::MediaKeyException CancelKeyRequest(
48       const blink::WebString& key_system,
49       const blink::WebString& session_id) OVERRIDE;
50
51   virtual void SetInitialContentDecryptionModule(
52       blink::WebContentDecryptionModule* initial_cdm) OVERRIDE;
53
54   virtual void SetContentDecryptionModule(
55       blink::WebContentDecryptionModule* cdm) OVERRIDE;
56   virtual void SetContentDecryptionModule(
57       blink::WebContentDecryptionModule* cdm,
58       blink::WebContentDecryptionModuleResult result) OVERRIDE;
59
60   virtual media::SetDecryptorReadyCB CreateSetDecryptorReadyCB() OVERRIDE;
61   virtual media::Demuxer::NeedKeyCB CreateNeedKeyCB() OVERRIDE;
62
63   virtual void OnPipelineDecryptError() OVERRIDE;
64
65  private:
66   explicit EncryptedMediaPlayerSupportImpl(blink::WebMediaPlayerClient* client);
67
68   // Requests that this object notifies when a decryptor is ready through the
69   // |decryptor_ready_cb| provided.
70   // If |decryptor_ready_cb| is null, the existing callback will be fired with
71   // NULL immediately and reset.
72   void SetDecryptorReadyCB(const media::DecryptorReadyCB& decryptor_ready_cb);
73
74   blink::WebMediaPlayer::MediaKeyException GenerateKeyRequestInternal(
75       blink::WebLocalFrame* frame,
76       const std::string& key_system,
77       const unsigned char* init_data,
78       unsigned init_data_length);
79
80   blink::WebMediaPlayer::MediaKeyException AddKeyInternal(
81       const std::string& key_system,
82       const unsigned char* key,
83       unsigned key_length,
84       const unsigned char* init_data,
85       unsigned init_data_length,
86       const std::string& session_id);
87
88   blink::WebMediaPlayer::MediaKeyException CancelKeyRequestInternal(
89     const std::string& key_system,
90     const std::string& session_id);
91
92   void OnNeedKey(const std::string& type,
93                  const std::vector<uint8>& init_data);
94
95   void OnKeyAdded(const std::string& session_id);
96   void OnKeyError(const std::string& session_id,
97                   media::MediaKeys::KeyError error_code,
98                   uint32 system_code);
99   void OnKeyMessage(const std::string& session_id,
100                     const std::vector<uint8>& message,
101                     const GURL& destination_url);
102
103   void ContentDecryptionModuleAttached(
104       blink::WebContentDecryptionModuleResult result,
105       bool success);
106
107   blink::WebMediaPlayerClient* client_;
108
109   // The currently selected key system. Empty string means that no key system
110   // has been selected.
111   std::string current_key_system_;
112
113   // Temporary for EME v0.1. In the future the init data type should be passed
114   // through GenerateKeyRequest() directly from WebKit.
115   std::string init_data_type_;
116
117   // Manages decryption keys and decrypts encrypted frames.
118   scoped_ptr<ProxyDecryptor> proxy_decryptor_;
119
120   // Non-owned pointer to the CDM. Updated via calls to
121   // setContentDecryptionModule().
122   WebContentDecryptionModuleImpl* web_cdm_;
123
124   media::DecryptorReadyCB decryptor_ready_cb_;
125
126   DISALLOW_COPY_AND_ASSIGN(EncryptedMediaPlayerSupportImpl);
127 };
128 }
129
130 #endif  // CONTENT_RENDERER_MEDIA_CRYPTO_ENCRYPTED_MEDIA_PLAYER_SUPPORT_IMPL_H_