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

Side by Side Diff: ppapi/examples/content_decryption_module/content_decryption_module.cc

Issue 10545036: Add PPAPI decryptor interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased on origin/master and fixed a minor conflict Created 8 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/string_piece.h"
6 #include "ppapi/c/dev/ppb_buffer_dev.h"
7 #include "ppapi/c/dev/ppb_console_dev.h"
8 #include "ppapi/c/dev/ppb_content_decryption_module_dev.h"
9 #include "ppapi/cpp/instance.h"
10 #include "ppapi/cpp/module.h"
11 #include "ppapi/cpp/resource.h"
12 #include "ppapi/cpp/dev/buffer_dev.h"
13 #include "ppapi/cpp/dev/content_decryption_module_dev.h"
14 #include "ppapi/shared_impl/var.h"
15
16 class CDMInstance : public pp::Instance,
17 public pp::ContentDecryptionModule_Dev {
18 public:
19 explicit CDMInstance(PP_Instance instance, pp::Module* module);
20 virtual ~CDMInstance() {}
21
22 // PPP_ContentDecryptionModule_Dev methods
23 virtual bool GenerateKeyRequest(PP_Var key_system,
24 PP_Resource init_data);
25
26 virtual bool AddKey(PP_Var session_id,
27 PP_Resource key) {
28 return false;
29 }
30
31 virtual bool CancelKeyRequest(PP_Var session_id) {
32 return false;
33 }
34
35 virtual bool Decrypt(PP_Resource encrypted_block,
36 PP_CompletionCallback callback);
37
38 virtual bool DecryptAndDecode(PP_Resource encrypted_block,
39 PP_CompletionCallback callback) {
40 return false;
41 }
42
43 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
44 return true;
45 }
46
47 private:
48 // Browser interfaces.
49 const PPB_Buffer_Dev* buffer_if_;
50 const PPB_Console_Dev* console_if_;
51 const PPB_ContentDecryptionModule_Dev* browser_cdm_if_;
52 };
53
54 // This object is the global object representing this plugin library as long
55 // as it is loaded.
56 class MyModule : public pp::Module {
57 public:
58 MyModule() : pp::Module() {}
59 virtual ~MyModule() {}
60
61 // Override CreateInstance to create your customized Instance object.
62 virtual pp::Instance* CreateInstance(PP_Instance instance) {
63 return new CDMInstance(instance, this);
64 }
65 };
66
67 CDMInstance::CDMInstance(PP_Instance instance,
68 pp::Module* module)
69 : pp::Instance(instance),
70 pp::ContentDecryptionModule_Dev(this) {
71 console_if_ = static_cast<const PPB_Console_Dev*>(
72 module->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE));
73 assert(console_if_);
74 browser_cdm_if_ = static_cast<const PPB_ContentDecryptionModule_Dev*>(
75 module->GetBrowserInterface(PPB_CONTENTDECRYPTIONMODULE_DEV_INTERFACE));
76 assert(browser_cdm_if_);
77 buffer_if_ = static_cast<const PPB_Buffer_Dev*>(
78 module->GetBrowserInterface(PPB_BUFFER_DEV_INTERFACE));
79 assert(buffer_if_);
80 }
81
82 bool CDMInstance::GenerateKeyRequest(PP_Var key_system_var,
83 PP_Resource init_data) {
84 using ppapi::StringVar;
85
86 // Extract the key system string from |key_system_var|.
87 StringVar* key_system_string_var = StringVar::FromPPVar(key_system_var);
88 base::StringPiece key_system = key_system_string_var->value();
89
90 if (init_data) {
91 // TODO(tomfinegan): Is init_data always required, or will it be key_system
92 // specific?
93 pp::Buffer_Dev init_buffer(init_data);
94 if (!buffer_if_->IsBuffer(init_buffer.pp_resource()) ||
95 !init_buffer.data()) {
96 return false;
97 }
98 }
99 // Do something with the init data buffer from |init_data|.
100
101 return false;
102 }
103
104 bool CDMInstance::Decrypt(PP_Resource encrypted_block,
105 PP_CompletionCallback callback) {
106 pp::Buffer_Dev block_buffer(encrypted_block);
107 if (!buffer_if_->IsBuffer(block_buffer.pp_resource()) ||
108 !block_buffer.data()) {
109 return false;
110 }
111
112 const base::StringPiece kDummyDecryptedData = "Pretend I'm decrypted data!";
113 pp::Buffer_Dev decrypted_buffer(this, kDummyDecryptedData.size());
114 if (!buffer_if_->IsBuffer(decrypted_buffer.pp_resource()) ||
115 !decrypted_buffer.data()) {
116 return false;
117 }
118
119 memcpy(decrypted_buffer.data(), kDummyDecryptedData.data(),
120 kDummyDecryptedData.size());
121
122 PP_Resource decrypted_resource = decrypted_buffer.detach();
123 browser_cdm_if_->DeliverBlock(pp_instance(), decrypted_resource, callback);
124 return true;
125 }
126
127 namespace pp {
128
129 // Factory function for your specialization of the Module object.
130 Module* CreateModule() {
131 return new MyModule();
132 }
133
134 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698