Chromium Code Reviews| Index: webkit/plugins/ppapi/ppapi_plugin_instance.cc |
| diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc |
| index 96694f6df0d1d5718fb23653b0e023cb9746ace9..cfc11b95f5e6df61c077c6f7b6fa8de506eb839f 100644 |
| --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc |
| +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc |
| @@ -114,6 +114,7 @@ using ppapi::thunk::PPB_Graphics2D_API; |
| using ppapi::thunk::PPB_Graphics3D_API; |
| using ppapi::thunk::PPB_ImageData_API; |
| using ppapi::Var; |
| +using ppapi::ArrayBufferVar; |
|
xhwang
2012/08/15 00:27:57
It looks like these are alphabetically ordered, w/
Tom Finegan
2012/08/16 03:10:48
Yeah, wasn't sure what to do-- ArrayBufferVar next
|
| using ppapi::ViewData; |
| using WebKit::WebBindings; |
| using WebKit::WebCanvas; |
| @@ -294,6 +295,28 @@ scoped_array<const char*> StringVectorToArgArray( |
| return array.Pass(); |
| } |
| +// Creates a PP_Resource containing a PPB_Buffer_Impl, copies |data| into the |
| +// buffer resource, and returns it. Returns a PP_Resource equal to 0 on |
|
xhwang
2012/08/15 00:27:57
Returns an invalid PP_Resource (with a 0 ID) on fa
Tom Finegan
2012/08/16 03:10:48
Done.
|
| +// failure. |
| +PP_Resource MakeBufferResource(PP_Instance instance, |
| + const base::StringPiece& data) { |
| + if (data.empty()) |
| + return 0; |
| + |
| + ScopedPPResource resource(PPB_Buffer_Impl::Create(instance, data.size())); |
| + if (!resource.get()) |
| + return 0; |
| + |
| + EnterResourceNoLock<PPB_Buffer_API> enter(resource, true); |
| + if (enter.failed()) |
| + return 0; |
| + |
| + BufferAutoMapper mapper(enter.object()); |
| + memcpy(mapper.data(), data.data(), data.size()); |
| + |
| + return resource.get(); |
| +} |
| + |
| } // namespace |
| // static |
| @@ -323,6 +346,7 @@ PluginInstance::PluginInstance( |
| has_webkit_focus_(false), |
| has_content_area_focus_(false), |
| find_identifier_(-1), |
| + plugin_decryption_interface_(NULL), |
| plugin_find_interface_(NULL), |
| plugin_input_event_interface_(NULL), |
| plugin_messaging_interface_(NULL), |
| @@ -965,6 +989,16 @@ void PluginInstance::StopFind() { |
| plugin_find_interface_->StopFind(pp_instance()); |
| } |
| +bool PluginInstance::LoadContentDecryptorInterface() { |
| + if (!plugin_decryption_interface_) { |
| + plugin_decryption_interface_ = |
| + static_cast<const PPP_ContentDecryptor_Private*>( |
| + module_->GetPluginInterface( |
| + PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE)); |
| + } |
| + return !!plugin_decryption_interface_; |
| +} |
| + |
| bool PluginInstance::LoadFindInterface() { |
| if (!plugin_find_interface_) { |
| plugin_find_interface_ = |
| @@ -1282,6 +1316,74 @@ void PluginInstance::RotateView(WebPlugin::RotationType type) { |
| // NOTE: plugin instance may have been deleted. |
| } |
| +bool PluginInstance::GenerateKeyRequest(const std::string& key_system, |
| + const std::string& init_data) { |
| + if (!LoadContentDecryptorInterface()) |
| + return false; |
| + if (key_system.empty()) |
| + return false; |
| + PP_Var init_data_array = |
| + PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
| + init_data.size(), init_data.data()); |
| + return PP_ToBool(plugin_decryption_interface_->GenerateKeyRequest( |
| + pp_instance(), |
| + StringVar::StringToPPVar(key_system), |
| + init_data_array)); |
| +} |
| + |
| +bool PluginInstance::AddKey(const std::string& session_id, |
| + const std::string& key) { |
| + if (!LoadContentDecryptorInterface()) |
| + return false; |
| + StringVar session_id_var(session_id); |
| + PP_Var key_array = |
| + PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(key.size(), |
| + key.data()); |
| + return PP_ToBool(plugin_decryption_interface_->AddKey( |
| + pp_instance(), |
| + session_id_var.GetPPVar(), |
| + key_array)); |
| +} |
| + |
| +bool PluginInstance::CancelKeyRequest(const std::string& session_id) { |
| + if (!LoadContentDecryptorInterface()) |
| + return false; |
| + StringVar session_id_var(session_id); |
| + return PP_ToBool(plugin_decryption_interface_->CancelKeyRequest( |
| + pp_instance(), |
| + session_id_var.GetPPVar())); |
| +} |
| + |
| +bool PluginInstance::Decrypt(const base::StringPiece& encrypted_block, |
| + const DecryptedDataCB& callback) { |
| + if (!LoadContentDecryptorInterface()) |
| + return false; |
| + ScopedPPResource encrypted_resource(MakeBufferResource(pp_instance(), |
| + encrypted_block)); |
| + if (!encrypted_resource.get()) |
| + return false; |
| + // TODO(tomfinegan): Store callback and ID in a map, and pass ID to decryptor. |
| + return PP_ToBool(plugin_decryption_interface_->Decrypt(pp_instance(), |
| + encrypted_resource, |
| + 0)); |
| +} |
| + |
| +bool PluginInstance::DecryptAndDecode(const base::StringPiece& encrypted_block, |
| + const DecryptedDataCB& callback) { |
| + if (!LoadContentDecryptorInterface()) |
| + return false; |
| + ScopedPPResource encrypted_resource(ScopedPPResource::PassRef(), |
| + MakeBufferResource(pp_instance(), |
| + encrypted_block)); |
| + if (!encrypted_resource.get()) |
| + return false; |
| + // TODO(tomfinegan): Store callback and ID in a map, and pass ID to decryptor. |
| + return PP_ToBool(plugin_decryption_interface_->DecryptAndDecode( |
| + pp_instance(), |
| + encrypted_resource, |
| + 0)); |
| +} |
| + |
| bool PluginInstance::FlashIsFullscreenOrPending() { |
| return fullscreen_container_ != NULL; |
| } |
| @@ -1890,6 +1992,105 @@ PP_Var PluginInstance::GetFontFamilies(PP_Instance instance) { |
| return PP_MakeUndefined(); |
| } |
| +void PluginInstance::NeedKey(PP_Instance instance, |
| + PP_Var key_system_var, |
| + PP_Var session_id_var, |
| + PP_Var init_data_var) { |
| + StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
| + StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| + StringVar* init_data_string = StringVar::FromPPVar(init_data_var); |
| + |
| + if (!key_system_string || !session_id_string || !init_data_string) |
| + return; |
| +} |
| + |
| +void PluginInstance::KeyAdded(PP_Instance instance, |
| + PP_Var key_system_var, |
| + PP_Var session_id_var) { |
| + StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
| + StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| + |
| + if (!key_system_string || !session_id_string) { |
| + // TODO(tomfinegan): KeyError here? |
|
xhwang
2012/08/15 00:27:57
The CDMWrapper should check this. Here we probably
Tom Finegan
2012/08/16 03:10:48
No DCHECKs-- per dmichael we're supposed to treat
|
| + return; |
| + } |
| + |
| + // TODO(tomfinegan): send the data to media stack. |
| +} |
| + |
| +void PluginInstance::KeyMessage(PP_Instance instance, |
| + PP_Var key_system_var, |
| + PP_Var session_id_var, |
| + PP_Resource message_resource, |
| + PP_Var default_url_var) { |
| + StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
| + StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| + StringVar* default_url_string = StringVar::FromPPVar(default_url_var); |
| + |
| + if (!key_system_string || !session_id_string || !default_url_string) { |
| + // TODO(tomfinegan): KeyError here? |
|
xhwang
2012/08/15 00:27:57
ditto.
Tom Finegan
2012/08/16 03:10:48
Done/removed checks.
|
| + return; |
| + } |
| + |
| + EnterResourceNoLock<PPB_Buffer_API> enter(message_resource, true); |
| + if (enter.failed()) { |
| + // TODO(tomfinegan): KeyError here? |
|
xhwang
2012/08/15 00:27:57
Can this happen if we implemented everything corre
Tom Finegan
2012/08/16 03:10:48
Initial question: presumably yes, at the very leas
|
| + return; |
| + } |
| + |
| + BufferAutoMapper mapper(enter.object()); |
| + if (!mapper.data() || !mapper.size()) { |
| + // TODO(tomfinegan): KeyError here? |
|
xhwang
2012/08/15 00:27:57
ditto here and below.
Tom Finegan
2012/08/16 03:10:48
Done/removed checks.
|
| + return; |
| + } |
| + |
| + std::string message(reinterpret_cast<char*>(mapper.data()), mapper.size()); |
| + if (message.empty()) { |
| + // TODO(tomfinegan): KeyError here? |
| + return; |
| + } |
| + |
| + // TODO(tomfinegan): send the data to media stack. |
| +} |
| + |
| +void PluginInstance::KeyError(PP_Instance instance, |
| + PP_Var key_system_var, |
| + PP_Var session_id_var, |
| + int32_t media_error, |
| + int32_t system_code) { |
| + StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
| + StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| + |
| + if (!key_system_string || !session_id_string) |
| + return; |
| + |
| + // TODO(tomfinegan): send the data to media stack. |
| +} |
| + |
| +void PluginInstance::DeliverBlock(PP_Instance instance, |
| + PP_Resource decrypted_block, |
| + int32_t request_id) { |
| + // TODO(tomfinegan): Determine where |decrypted_block| goes, and what |
| + // callback actually is (callback will likely be the result of some |
| + // base::Bind usage in the media stack. Hash this out with xhwang. |
|
xhwang
2012/08/15 00:27:57
You can simplify this to:
TODO(xhwang): Pass the d
Tom Finegan
2012/08/16 03:10:48
Done.
|
| + // |
| +} |
| + |
| +void PluginInstance::DeliverFrame(PP_Instance instance, |
| + PP_Resource decrypted_frame, |
| + int32_t request_id) { |
| + // TODO(tomfinegan): To be implemented after completion of v0.1 of the |
| + // EME/CDM work. |
|
xhwang
2012/08/15 00:27:57
Add NOTREACHED();
Tom Finegan
2012/08/16 03:10:48
dmichael said not to use things that can bring dow
|
| +} |
| + |
| +void PluginInstance::DeliverSamples(PP_Instance instance, |
| + PP_Resource decrypted_samples, |
| + int32_t request_id) { |
| + // TODO(tomfinegan): To be implemented after completion of v0.1 of the |
| + // EME/CDM work. |
|
xhwang
2012/08/15 00:27:57
Add NOTREACHED();
Tom Finegan
2012/08/16 03:10:48
Ditto.
|
| +} |
| + |
| + |
| void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, |
| int32_t total, |
| PP_Bool final_result) { |