pepper_flash_drm_host.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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 "chrome/browser/renderer_host/pepper/pepper_flash_drm_host.h"
6
7#include "base/bind.h"
8#include "base/compiler_specific.h"
9#include "base/logging.h"
10#include "content/public/browser/browser_ppapi_host.h"
11#include "ppapi/c/pp_errors.h"
12#include "ppapi/host/dispatch_host_message.h"
13#include "ppapi/host/host_message_context.h"
14#include "ppapi/host/ppapi_host.h"
15#include "ppapi/proxy/ppapi_messages.h"
16
17using content::BrowserPpapiHost;
18
19namespace chrome {
20
21PepperFlashDRMHost::PepperFlashDRMHost(BrowserPpapiHost* host,
22                                       PP_Instance instance,
23                                       PP_Resource resource)
24    : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource),
25      weak_factory_(this){
26  int render_process_id, unused;
27  host->GetRenderViewIDsForInstance(instance, &render_process_id, &unused);
28  fetcher_ = new DeviceIDFetcher(render_process_id);
29}
30
31PepperFlashDRMHost::~PepperFlashDRMHost() {
32}
33
34int32_t PepperFlashDRMHost::OnResourceMessageReceived(
35    const IPC::Message& msg,
36    ppapi::host::HostMessageContext* context) {
37  IPC_BEGIN_MESSAGE_MAP(PepperFlashDRMHost, msg)
38    PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FlashDRM_GetDeviceID,
39                                        OnHostMsgGetDeviceID)
40  IPC_END_MESSAGE_MAP()
41  return PP_ERROR_FAILED;
42}
43
44int32_t PepperFlashDRMHost::OnHostMsgGetDeviceID(
45    ppapi::host::HostMessageContext* context) {
46  if (!fetcher_->Start(base::Bind(&PepperFlashDRMHost::GotDeviceID,
47                                  weak_factory_.GetWeakPtr(),
48                                  context->MakeReplyMessageContext()))) {
49    return PP_ERROR_INPROGRESS;
50  }
51  return PP_OK_COMPLETIONPENDING;
52}
53
54void PepperFlashDRMHost::GotDeviceID(
55    ppapi::host::ReplyMessageContext reply_context,
56    const std::string& id) {
57  reply_context.params.set_result(
58      id.empty() ? PP_ERROR_FAILED : PP_OK);
59  host()->SendReply(reply_context,
60                    PpapiPluginMsg_FlashDRM_GetDeviceIDReply(id));
61}
62
63}  // namespace chrome
64