Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: webkit/media/crypto/ppapi/cdm_wrapper.cc

Issue 10854209: Modify the PPAPI CDM interface to pass more info. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/thunk/ppb_instance_api.h ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cstring> // For std::memcpy. 5 #include <cstring> // For std::memcpy.
6 6
7 #include "base/compiler_specific.h" // For OVERRIDE. 7 #include "base/compiler_specific.h" // For OVERRIDE.
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/pp_stdint.h" 9 #include "ppapi/c/pp_stdint.h"
10 #include "ppapi/c/private/pp_content_decryptor.h"
10 #include "ppapi/cpp/completion_callback.h" 11 #include "ppapi/cpp/completion_callback.h"
11 #include "ppapi/cpp/core.h" 12 #include "ppapi/cpp/core.h"
12 #include "ppapi/cpp/instance.h" 13 #include "ppapi/cpp/instance.h"
13 #include "ppapi/cpp/logging.h" 14 #include "ppapi/cpp/logging.h"
14 #include "ppapi/cpp/module.h" 15 #include "ppapi/cpp/module.h"
15 #include "ppapi/cpp/pass_ref.h" 16 #include "ppapi/cpp/pass_ref.h"
16 #include "ppapi/cpp/resource.h" 17 #include "ppapi/cpp/resource.h"
17 #include "ppapi/cpp/var.h" 18 #include "ppapi/cpp/var.h"
18 #include "ppapi/cpp/var_array_buffer.h" 19 #include "ppapi/cpp/var_array_buffer.h"
19 #include "ppapi/cpp/dev/buffer_dev.h" 20 #include "ppapi/cpp/dev/buffer_dev.h"
20 #include "ppapi/cpp/private/content_decryptor_private.h" 21 #include "ppapi/cpp/private/content_decryptor_private.h"
21 #include "ppapi/utility/completion_callback_factory.h" 22 #include "ppapi/utility/completion_callback_factory.h"
22 23
23 namespace { 24 namespace {
24 25
25 struct DecryptorMessage { 26 struct DecryptorMessage {
26 DecryptorMessage() : media_error(0), system_code(0) {} 27 DecryptorMessage() : media_error(0), system_code(0) {}
27 std::string key_system; 28 std::string key_system;
28 std::string session_id; 29 std::string session_id;
29 std::string default_url; 30 std::string default_url;
30 std::string message_data; 31 std::string message_data;
31 int32_t media_error; 32 int32_t media_error;
32 int32_t system_code; 33 int32_t system_code;
33 }; 34 };
34 35
35 struct DecryptedBlock { 36 struct DecryptedBlock {
36 DecryptedBlock() : request_id(0) {} 37 DecryptedBlock() {
37 int32_t request_id; 38 std::memset(reinterpret_cast<void*>(&decrypted_block_info),
38 std::string data; 39 0,
40 sizeof(decrypted_block_info));
41 }
42 std::string decrypted_data;
43 PP_DecryptedBlockInfo decrypted_block_info;
39 }; 44 };
40 45
46 bool IsMainThread() {
47 return pp::Module::Get()->core()->IsMainThread();
48 }
49
41 void CallOnMain(pp::CompletionCallback cb) { 50 void CallOnMain(pp::CompletionCallback cb) {
42 pp::Module::Get()->core()->CallOnMainThread(0, cb, PP_OK); 51 // TODO(tomfinegan): This is only necessary because PPAPI doesn't allow calls
52 // off the main thread yet. Remove this once the change lands.
53 if (IsMainThread())
54 cb.Run(PP_OK);
55 else
56 pp::Module::Get()->core()->CallOnMainThread(0, cb, PP_OK);
43 } 57 }
44 58
45 } // namespace 59 } // namespace
46 60
47 61
48 // A wrapper class for abstracting away PPAPI interaction and threading for a 62 // A wrapper class for abstracting away PPAPI interaction and threading for a
49 // Content Decryption Module (CDM). 63 // Content Decryption Module (CDM).
50 class CDMWrapper : public pp::Instance, 64 class CDMWrapper : public pp::Instance,
51 public pp::ContentDecryptor_Private { 65 public pp::ContentDecryptor_Private {
52 public: 66 public:
53 CDMWrapper(PP_Instance instance, pp::Module* module); 67 CDMWrapper(PP_Instance instance, pp::Module* module);
54 virtual ~CDMWrapper() {} 68 virtual ~CDMWrapper() {}
55 69
56 // PPP_ContentDecryptor_Private methods 70 // PPP_ContentDecryptor_Private methods
57 virtual bool GenerateKeyRequest(const std::string& key_system, 71 virtual bool GenerateKeyRequest(const std::string& key_system,
58 pp::VarArrayBuffer init_data) OVERRIDE; 72 pp::VarArrayBuffer init_data) OVERRIDE;
59 virtual bool AddKey(const std::string& session_id, 73 virtual bool AddKey(const std::string& session_id,
60 pp::VarArrayBuffer key) OVERRIDE; 74 pp::VarArrayBuffer key,
75 pp::VarArrayBuffer init_data) OVERRIDE;
61 virtual bool CancelKeyRequest(const std::string& session_id) OVERRIDE; 76 virtual bool CancelKeyRequest(const std::string& session_id) OVERRIDE;
62 virtual bool Decrypt(pp::Buffer_Dev encrypted_buffer, 77 virtual bool Decrypt(
63 int32_t request_id) OVERRIDE; 78 pp::Buffer_Dev encrypted_buffer,
79 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
64 80
65 virtual bool DecryptAndDecode(pp::Buffer_Dev encrypted_buffer, 81 virtual bool DecryptAndDecode(
66 int32_t request_id) OVERRIDE { 82 pp::Buffer_Dev encrypted_buffer,
83 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE {
67 return false; 84 return false;
68 } 85 }
69 86
70 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { 87 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
71 return true; 88 return true;
72 } 89 }
73 90
74 private: 91 private:
75 PP_Resource StringToBufferResource(const std::string& str); 92 PP_Resource StringToBufferResource(const std::string& str);
76 93
(...skipping 25 matching lines...) Expand all
102 decryptor_message.session_id = "0"; 119 decryptor_message.session_id = "0";
103 decryptor_message.default_url = "http://www.google.com"; 120 decryptor_message.default_url = "http://www.google.com";
104 decryptor_message.message_data = "GenerateKeyRequest"; 121 decryptor_message.message_data = "GenerateKeyRequest";
105 122
106 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyMessage, 123 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyMessage,
107 decryptor_message)); 124 decryptor_message));
108 return true; 125 return true;
109 } 126 }
110 127
111 bool CDMWrapper::AddKey(const std::string& session_id, 128 bool CDMWrapper::AddKey(const std::string& session_id,
112 pp::VarArrayBuffer key) { 129 pp::VarArrayBuffer key,
130 pp::VarArrayBuffer init_data) {
113 const std::string key_string(reinterpret_cast<char*>(key.Map()), 131 const std::string key_string(reinterpret_cast<char*>(key.Map()),
114 key.ByteLength()); 132 key.ByteLength());
133 const std::string init_data_string(reinterpret_cast<char*>(init_data.Map()),
134 init_data.ByteLength());
115 135
116 PP_DCHECK(!session_id.empty() && !key_string.empty()); 136 PP_DCHECK(!session_id.empty() && !key_string.empty());
117 137
118 DecryptorMessage decryptor_message; 138 DecryptorMessage decryptor_message;
119 decryptor_message.key_system = "AddKey"; 139 decryptor_message.key_system = "AddKey";
120 decryptor_message.session_id = "0"; 140 decryptor_message.session_id = "0";
121 decryptor_message.default_url = "http://www.google.com"; 141 decryptor_message.default_url = "http://www.google.com";
122 decryptor_message.message_data = "AddKey"; 142 decryptor_message.message_data = "AddKey";
123 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyAdded, 143 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyAdded,
124 decryptor_message)); 144 decryptor_message));
125 return true; 145 return true;
126 } 146 }
127 147
128 bool CDMWrapper::CancelKeyRequest(const std::string& session_id) { 148 bool CDMWrapper::CancelKeyRequest(const std::string& session_id) {
129 // TODO(tomfinegan): cancel pending key request in CDM. 149 // TODO(tomfinegan): cancel pending key request in CDM.
130 150
131 PP_DCHECK(!session_id.empty()); 151 PP_DCHECK(!session_id.empty());
132 152
133 DecryptorMessage decryptor_message; 153 DecryptorMessage decryptor_message;
134 decryptor_message.key_system = "CancelKeyRequest"; 154 decryptor_message.key_system = "CancelKeyRequest";
135 decryptor_message.session_id = "0"; 155 decryptor_message.session_id = "0";
136 decryptor_message.default_url = "http://www.google.com"; 156 decryptor_message.default_url = "http://www.google.com";
137 decryptor_message.message_data = "CancelKeyRequest"; 157 decryptor_message.message_data = "CancelKeyRequest";
158
138 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyMessage, 159 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyMessage,
139 decryptor_message)); 160 decryptor_message));
140 return true; 161 return true;
141 } 162 }
142 163
143 bool CDMWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer, 164 bool CDMWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer,
144 int32_t request_id) { 165 const PP_EncryptedBlockInfo& encrypted_block_info) {
145 PP_DCHECK(!encrypted_buffer.is_null()); 166 PP_DCHECK(!encrypted_buffer.is_null());
146 167
147 DecryptedBlock decrypted_block; 168 DecryptedBlock decrypted_block;
148 decrypted_block.request_id = request_id; 169 decrypted_block.decrypted_data = "Pretend I'm decrypted data!";
149 decrypted_block.data = "Pretend I'm decrypted data!"; 170 decrypted_block.decrypted_block_info.result = PP_DECRYPTRESULT_SUCCESS;
171 decrypted_block.decrypted_block_info.tracking_info =
172 encrypted_block_info.tracking_info;
173
174 // TODO(tomfinegan): This would end up copying a lot of data in the real
175 // implementation if we continue passing std::strings around. It *might* not
176 // be such a big deal w/a real CDM. We may be able to simply pass a pointer
177 // into the CDM. Otherwise we could look into using std::tr1::shared_ptr
178 // instead of passing a giant std::string filled with encrypted data.
150 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::DeliverBlock, 179 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::DeliverBlock,
151 decrypted_block)); 180 decrypted_block));
152 return true; 181 return true;
153 } 182 }
154 183
155 PP_Resource CDMWrapper::StringToBufferResource(const std::string& str) { 184 PP_Resource CDMWrapper::StringToBufferResource(const std::string& str) {
156 if (str.empty()) 185 if (str.empty())
157 return 0; 186 return 0;
158 187
159 pp::Buffer_Dev buffer(this, str.size()); 188 pp::Buffer_Dev buffer(this, str.size());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 const DecryptorMessage& decryptor_message) { 223 const DecryptorMessage& decryptor_message) {
195 pp::ContentDecryptor_Private::KeyError(decryptor_message.key_system, 224 pp::ContentDecryptor_Private::KeyError(decryptor_message.key_system,
196 decryptor_message.session_id, 225 decryptor_message.session_id,
197 decryptor_message.media_error, 226 decryptor_message.media_error,
198 decryptor_message.system_code); 227 decryptor_message.system_code);
199 } 228 }
200 229
201 void CDMWrapper::DeliverBlock(int32_t result, 230 void CDMWrapper::DeliverBlock(int32_t result,
202 const DecryptedBlock& decrypted_block) { 231 const DecryptedBlock& decrypted_block) {
203 pp::Buffer_Dev decrypted_buffer( 232 pp::Buffer_Dev decrypted_buffer(
204 StringToBufferResource(decrypted_block.data)); 233 StringToBufferResource(decrypted_block.decrypted_data));
205 pp::ContentDecryptor_Private::DeliverBlock(decrypted_buffer, 234 pp::ContentDecryptor_Private::DeliverBlock(
206 decrypted_block.request_id); 235 decrypted_buffer,
236 decrypted_block.decrypted_block_info);
207 } 237 }
208 238
209 // This object is the global object representing this plugin library as long 239 // This object is the global object representing this plugin library as long
210 // as it is loaded. 240 // as it is loaded.
211 class MyModule : public pp::Module { 241 class MyModule : public pp::Module {
212 public: 242 public:
213 MyModule() : pp::Module() {} 243 MyModule() : pp::Module() {}
214 virtual ~MyModule() {} 244 virtual ~MyModule() {}
215 245
216 virtual pp::Instance* CreateInstance(PP_Instance instance) { 246 virtual pp::Instance* CreateInstance(PP_Instance instance) {
217 return new CDMWrapper(instance, this); 247 return new CDMWrapper(instance, this);
218 } 248 }
219 }; 249 };
220 250
221 namespace pp { 251 namespace pp {
222 252
223 // Factory function for your specialization of the Module object. 253 // Factory function for your specialization of the Module object.
224 Module* CreateModule() { 254 Module* CreateModule() {
225 return new MyModule(); 255 return new MyModule();
226 } 256 }
227 257
228 } // namespace pp 258 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/thunk/ppb_instance_api.h ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698