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.
5 #include "chrome/renderer/pepper/pepper_flash_drm_renderer_host.h"
7 #include "base/files/file_path.h"
8 #include "content/public/renderer/pepper_plugin_instance.h"
9 #include "content/public/renderer/renderer_ppapi_host.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/host/dispatch_host_message.h"
12 #include "ppapi/host/host_message_context.h"
13 #include "ppapi/host/ppapi_host.h"
14 #include "ppapi/proxy/ppapi_messages.h"
16 // TODO(raymes): This is duplicated from pepper_flash_drm_host.cc but once
17 // FileRef is refactored to the browser, it won't need to be.
19 const base::FilePath::CharType kVoucherFilename
[] =
20 FILE_PATH_LITERAL("plugin.vch");
23 PepperFlashDRMRendererHost::PepperFlashDRMRendererHost(
24 content::RendererPpapiHost
* host
,
27 : ResourceHost(host
->GetPpapiHost(), instance
, resource
),
28 renderer_ppapi_host_(host
),
32 PepperFlashDRMRendererHost::~PepperFlashDRMRendererHost() {
35 int32_t PepperFlashDRMRendererHost::OnResourceMessageReceived(
36 const IPC::Message
& msg
,
37 ppapi::host::HostMessageContext
* context
) {
38 IPC_BEGIN_MESSAGE_MAP(PepperFlashDRMRendererHost
, msg
)
39 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FlashDRM_GetVoucherFile
,
42 return PP_ERROR_FAILED
;
45 int32_t PepperFlashDRMRendererHost::OnGetVoucherFile(
46 ppapi::host::HostMessageContext
* context
) {
47 content::PepperPluginInstance
* plugin_instance
=
48 renderer_ppapi_host_
->GetPluginInstance(pp_instance());
50 return PP_ERROR_FAILED
;
52 base::FilePath plugin_dir
= plugin_instance
->GetModulePath().DirName();
53 DCHECK(!plugin_dir
.empty());
54 base::FilePath voucher_file
= plugin_dir
.Append(
55 base::FilePath(kVoucherFilename
));
57 int renderer_pending_host_id
=
58 plugin_instance
->MakePendingFileRefRendererHost(voucher_file
);
59 if (renderer_pending_host_id
== 0)
60 return PP_ERROR_FAILED
;
62 std::vector
<IPC::Message
> create_msgs
;
63 create_msgs
.push_back(PpapiHostMsg_FileRef_CreateExternal(voucher_file
));
65 renderer_ppapi_host_
->CreateBrowserResourceHosts(
68 base::Bind(&PepperFlashDRMRendererHost::DidCreateFileRefHosts
,
69 weak_factory_
.GetWeakPtr(),
70 context
->MakeReplyMessageContext(),
72 renderer_pending_host_id
));
73 return PP_OK_COMPLETIONPENDING
;
76 void PepperFlashDRMRendererHost::DidCreateFileRefHosts(
77 const ppapi::host::ReplyMessageContext
& reply_context
,
78 const base::FilePath
& external_path
,
79 int renderer_pending_host_id
,
80 const std::vector
<int>& browser_pending_host_ids
) {
81 DCHECK(browser_pending_host_ids
.size() == 1);
83 int browser_pending_host_id
= 0;
84 if (browser_pending_host_ids
.size() == 1)
85 browser_pending_host_id
= browser_pending_host_ids
[0];
87 ppapi::FileRefCreateInfo create_info
=
88 ppapi::MakeExternalFileRefCreateInfo(external_path
,
90 browser_pending_host_id
,
91 renderer_pending_host_id
);
92 host()->SendReply(reply_context
,
93 PpapiPluginMsg_FlashDRM_GetVoucherFileReply(create_info
));