Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 std::string decrypted_data; |
| 37 int32_t request_id; | 38 PP_DecryptedBlockInfo decrypted_block_info; |
| 38 std::string data; | |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 void CallOnMain(pp::CompletionCallback cb) { | 41 void CallOnMain(pp::CompletionCallback cb) { |
| 42 pp::Module::Get()->core()->CallOnMainThread(0, cb, PP_OK); | 42 pp::Module::Get()->core()->CallOnMainThread(0, cb, PP_OK); |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 | 47 |
| 48 // A wrapper class for abstracting away PPAPI interaction and threading for a | 48 // A wrapper class for abstracting away PPAPI interaction and threading for a |
| 49 // Content Decryption Module (CDM). | 49 // Content Decryption Module (CDM). |
| 50 class CDMWrapper : public pp::Instance, | 50 class CDMWrapper : public pp::Instance, |
| 51 public pp::ContentDecryptor_Private { | 51 public pp::ContentDecryptor_Private { |
| 52 public: | 52 public: |
| 53 CDMWrapper(PP_Instance instance, pp::Module* module); | 53 CDMWrapper(PP_Instance instance, pp::Module* module); |
| 54 virtual ~CDMWrapper() {} | 54 virtual ~CDMWrapper() {} |
| 55 | 55 |
| 56 // PPP_ContentDecryptor_Private methods | 56 // PPP_ContentDecryptor_Private methods |
| 57 virtual bool GenerateKeyRequest(const std::string& key_system, | 57 virtual bool GenerateKeyRequest(const std::string& key_system, |
| 58 pp::VarArrayBuffer init_data) OVERRIDE; | 58 pp::VarArrayBuffer init_data) OVERRIDE; |
| 59 virtual bool AddKey(const std::string& session_id, | 59 virtual bool AddKey(const std::string& session_id, |
| 60 pp::VarArrayBuffer key) OVERRIDE; | 60 pp::VarArrayBuffer key, |
| 61 pp::VarArrayBuffer init_data) OVERRIDE; | |
| 61 virtual bool CancelKeyRequest(const std::string& session_id) OVERRIDE; | 62 virtual bool CancelKeyRequest(const std::string& session_id) OVERRIDE; |
| 62 virtual bool Decrypt(pp::Buffer_Dev encrypted_buffer, | 63 virtual bool Decrypt( |
| 63 int32_t request_id) OVERRIDE; | 64 pp::Buffer_Dev encrypted_buffer, |
| 65 const PP_EncryptedBlockInfo* encrypted_block_info) OVERRIDE; | |
| 64 | 66 |
| 65 virtual bool DecryptAndDecode(pp::Buffer_Dev encrypted_buffer, | 67 virtual bool DecryptAndDecode( |
| 66 int32_t request_id) OVERRIDE { | 68 pp::Buffer_Dev encrypted_buffer, |
| 69 const PP_EncryptedBlockInfo* encrypted_block_info) OVERRIDE { | |
| 67 return false; | 70 return false; |
| 68 } | 71 } |
| 69 | 72 |
| 70 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 73 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
| 71 return true; | 74 return true; |
| 72 } | 75 } |
| 73 | 76 |
| 74 private: | 77 private: |
| 75 PP_Resource StringToBufferResource(const std::string& str); | 78 PP_Resource StringToBufferResource(const std::string& str); |
| 76 | 79 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 102 decryptor_message.session_id = "0"; | 105 decryptor_message.session_id = "0"; |
| 103 decryptor_message.default_url = "http://www.google.com"; | 106 decryptor_message.default_url = "http://www.google.com"; |
| 104 decryptor_message.message_data = "GenerateKeyRequest"; | 107 decryptor_message.message_data = "GenerateKeyRequest"; |
| 105 | 108 |
| 106 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyMessage, | 109 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyMessage, |
| 107 decryptor_message)); | 110 decryptor_message)); |
| 108 return true; | 111 return true; |
| 109 } | 112 } |
| 110 | 113 |
| 111 bool CDMWrapper::AddKey(const std::string& session_id, | 114 bool CDMWrapper::AddKey(const std::string& session_id, |
| 112 pp::VarArrayBuffer key) { | 115 pp::VarArrayBuffer key, |
| 116 pp::VarArrayBuffer init_data) { | |
| 113 const std::string key_string(reinterpret_cast<char*>(key.Map()), | 117 const std::string key_string(reinterpret_cast<char*>(key.Map()), |
| 114 key.ByteLength()); | 118 key.ByteLength()); |
| 119 const std::string init_data_string(reinterpret_cast<char*>(init_data.Map()), | |
| 120 init_data.ByteLength()); | |
| 115 | 121 |
| 116 PP_DCHECK(!session_id.empty() && !key_string.empty()); | 122 PP_DCHECK(!session_id.empty() && !key_string.empty()); |
| 117 | 123 |
| 118 DecryptorMessage decryptor_message; | 124 DecryptorMessage decryptor_message; |
| 119 decryptor_message.key_system = "AddKey"; | 125 decryptor_message.key_system = "AddKey"; |
| 120 decryptor_message.session_id = "0"; | 126 decryptor_message.session_id = "0"; |
| 121 decryptor_message.default_url = "http://www.google.com"; | 127 decryptor_message.default_url = "http://www.google.com"; |
| 122 decryptor_message.message_data = "AddKey"; | 128 decryptor_message.message_data = "AddKey"; |
| 123 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyAdded, | 129 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyAdded, |
| 124 decryptor_message)); | 130 decryptor_message)); |
| 125 return true; | 131 return true; |
| 126 } | 132 } |
| 127 | 133 |
| 128 bool CDMWrapper::CancelKeyRequest(const std::string& session_id) { | 134 bool CDMWrapper::CancelKeyRequest(const std::string& session_id) { |
| 129 // TODO(tomfinegan): cancel pending key request in CDM. | 135 // TODO(tomfinegan): cancel pending key request in CDM. |
| 130 | 136 |
| 131 PP_DCHECK(!session_id.empty()); | 137 PP_DCHECK(!session_id.empty()); |
| 132 | 138 |
| 133 DecryptorMessage decryptor_message; | 139 DecryptorMessage decryptor_message; |
| 134 decryptor_message.key_system = "CancelKeyRequest"; | 140 decryptor_message.key_system = "CancelKeyRequest"; |
| 135 decryptor_message.session_id = "0"; | 141 decryptor_message.session_id = "0"; |
| 136 decryptor_message.default_url = "http://www.google.com"; | 142 decryptor_message.default_url = "http://www.google.com"; |
| 137 decryptor_message.message_data = "CancelKeyRequest"; | 143 decryptor_message.message_data = "CancelKeyRequest"; |
| 138 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyMessage, | 144 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::KeyMessage, |
| 139 decryptor_message)); | 145 decryptor_message)); |
| 140 return true; | 146 return true; |
| 141 } | 147 } |
| 142 | 148 |
| 143 bool CDMWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer, | 149 bool CDMWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer, |
| 144 int32_t request_id) { | 150 const PP_EncryptedBlockInfo* encrypted_block_info) { |
| 145 PP_DCHECK(!encrypted_buffer.is_null()); | 151 PP_DCHECK(!encrypted_buffer.is_null()); |
| 152 PP_DCHECK(encrypted_block_info); | |
| 146 | 153 |
| 147 DecryptedBlock decrypted_block; | 154 DecryptedBlock decrypted_block; |
|
ddorwin
2012/08/21 17:30:28
Set encrypted_block_info on DecryptedBlock.
Tom Finegan
2012/08/21 22:57:39
Done.
| |
| 148 decrypted_block.request_id = request_id; | 155 decrypted_block.decrypted_data = "Pretend I'm decrypted data!"; |
| 149 decrypted_block.data = "Pretend I'm decrypted data!"; | |
| 150 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::DeliverBlock, | 156 CallOnMain(callback_factory_.NewCallback(&CDMWrapper::DeliverBlock, |
| 151 decrypted_block)); | 157 decrypted_block)); |
| 152 return true; | 158 return true; |
| 153 } | 159 } |
| 154 | 160 |
| 155 PP_Resource CDMWrapper::StringToBufferResource(const std::string& str) { | 161 PP_Resource CDMWrapper::StringToBufferResource(const std::string& str) { |
| 156 if (str.empty()) | 162 if (str.empty()) |
| 157 return 0; | 163 return 0; |
| 158 | 164 |
| 159 pp::Buffer_Dev buffer(this, str.size()); | 165 pp::Buffer_Dev buffer(this, str.size()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 const DecryptorMessage& decryptor_message) { | 200 const DecryptorMessage& decryptor_message) { |
| 195 pp::ContentDecryptor_Private::KeyError(decryptor_message.key_system, | 201 pp::ContentDecryptor_Private::KeyError(decryptor_message.key_system, |
| 196 decryptor_message.session_id, | 202 decryptor_message.session_id, |
| 197 decryptor_message.media_error, | 203 decryptor_message.media_error, |
| 198 decryptor_message.system_code); | 204 decryptor_message.system_code); |
| 199 } | 205 } |
| 200 | 206 |
| 201 void CDMWrapper::DeliverBlock(int32_t result, | 207 void CDMWrapper::DeliverBlock(int32_t result, |
| 202 const DecryptedBlock& decrypted_block) { | 208 const DecryptedBlock& decrypted_block) { |
| 203 pp::Buffer_Dev decrypted_buffer( | 209 pp::Buffer_Dev decrypted_buffer( |
| 204 StringToBufferResource(decrypted_block.data)); | 210 StringToBufferResource(decrypted_block.decrypted_data)); |
| 205 pp::ContentDecryptor_Private::DeliverBlock(decrypted_buffer, | 211 pp::ContentDecryptor_Private::DeliverBlock( |
| 206 decrypted_block.request_id); | 212 decrypted_buffer, |
| 213 &decrypted_block.decrypted_block_info); | |
| 207 } | 214 } |
| 208 | 215 |
| 209 // This object is the global object representing this plugin library as long | 216 // This object is the global object representing this plugin library as long |
| 210 // as it is loaded. | 217 // as it is loaded. |
| 211 class MyModule : public pp::Module { | 218 class MyModule : public pp::Module { |
| 212 public: | 219 public: |
| 213 MyModule() : pp::Module() {} | 220 MyModule() : pp::Module() {} |
| 214 virtual ~MyModule() {} | 221 virtual ~MyModule() {} |
| 215 | 222 |
| 216 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 223 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| 217 return new CDMWrapper(instance, this); | 224 return new CDMWrapper(instance, this); |
| 218 } | 225 } |
| 219 }; | 226 }; |
| 220 | 227 |
| 221 namespace pp { | 228 namespace pp { |
| 222 | 229 |
| 223 // Factory function for your specialization of the Module object. | 230 // Factory function for your specialization of the Module object. |
| 224 Module* CreateModule() { | 231 Module* CreateModule() { |
| 225 return new MyModule(); | 232 return new MyModule(); |
| 226 } | 233 } |
| 227 | 234 |
| 228 } // namespace pp | 235 } // namespace pp |
| OLD | NEW |