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 char kVoucherFilename
[] = "plugin.vch";
22 PepperFlashDRMRendererHost::PepperFlashDRMRendererHost(
23 content::RendererPpapiHost
* host
,
26 : ResourceHost(host
->GetPpapiHost(), instance
, resource
),
27 renderer_ppapi_host_(host
),
28 weak_factory_(this) {}
30 PepperFlashDRMRendererHost::~PepperFlashDRMRendererHost() {}
32 int32_t PepperFlashDRMRendererHost::OnResourceMessageReceived(
33 const IPC::Message
& msg
,
34 ppapi::host::HostMessageContext
* context
) {
35 PPAPI_BEGIN_MESSAGE_MAP(PepperFlashDRMRendererHost
, msg
)
36 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FlashDRM_GetVoucherFile
,
38 PPAPI_END_MESSAGE_MAP()
39 return PP_ERROR_FAILED
;
42 int32_t PepperFlashDRMRendererHost::OnGetVoucherFile(
43 ppapi::host::HostMessageContext
* context
) {
44 content::PepperPluginInstance
* plugin_instance
=
45 renderer_ppapi_host_
->GetPluginInstance(pp_instance());
47 return PP_ERROR_FAILED
;
49 base::FilePath plugin_dir
= plugin_instance
->GetModulePath().DirName();
50 DCHECK(!plugin_dir
.empty());
51 base::FilePath voucher_file
= plugin_dir
.AppendASCII(kVoucherFilename
);
53 int renderer_pending_host_id
=
54 plugin_instance
->MakePendingFileRefRendererHost(voucher_file
);
55 if (renderer_pending_host_id
== 0)
56 return PP_ERROR_FAILED
;
58 std::vector
<IPC::Message
> create_msgs
;
59 create_msgs
.push_back(PpapiHostMsg_FileRef_CreateForRawFS(voucher_file
));
61 renderer_ppapi_host_
->CreateBrowserResourceHosts(
64 base::Bind(&PepperFlashDRMRendererHost::DidCreateFileRefHosts
,
65 weak_factory_
.GetWeakPtr(),
66 context
->MakeReplyMessageContext(),
68 renderer_pending_host_id
));
69 return PP_OK_COMPLETIONPENDING
;
72 void PepperFlashDRMRendererHost::DidCreateFileRefHosts(
73 const ppapi::host::ReplyMessageContext
& reply_context
,
74 const base::FilePath
& external_path
,
75 int renderer_pending_host_id
,
76 const std::vector
<int>& browser_pending_host_ids
) {
77 DCHECK_EQ(1U, browser_pending_host_ids
.size());
78 int browser_pending_host_id
= browser_pending_host_ids
[0];
80 ppapi::FileRefCreateInfo create_info
=
81 ppapi::MakeExternalFileRefCreateInfo(external_path
,
83 browser_pending_host_id
,
84 renderer_pending_host_id
);
85 host()->SendReply(reply_context
,
86 PpapiPluginMsg_FlashDRM_GetVoucherFileReply(create_info
));