pepper_flash_drm_host.cc revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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#if defined(OS_WIN) 8#include <Windows.h> 9#endif 10 11#include "base/bind.h" 12#include "base/compiler_specific.h" 13#include "base/logging.h" 14#include "content/public/browser/browser_ppapi_host.h" 15#include "content/public/browser/child_process_security_policy.h" 16#include "content/public/common/pepper_plugin_info.h" 17#include "ppapi/c/pp_errors.h" 18#include "ppapi/host/dispatch_host_message.h" 19#include "ppapi/host/host_message_context.h" 20#include "ppapi/host/ppapi_host.h" 21#include "ppapi/proxy/ppapi_messages.h" 22 23using content::BrowserPpapiHost; 24 25namespace chrome { 26 27namespace { 28const base::FilePath::CharType kVoucherFilename[] = 29 FILE_PATH_LITERAL("plugin.vch"); 30} 31 32PepperFlashDRMHost::PepperFlashDRMHost(BrowserPpapiHost* host, 33 PP_Instance instance, 34 PP_Resource resource) 35 : ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource), 36 weak_factory_(this){ 37 // Grant permissions to read the flash voucher file. 38 int render_process_id, unused; 39 bool success = 40 host->GetRenderViewIDsForInstance(instance, &render_process_id, &unused); 41 base::FilePath plugin_dir = host->GetPluginPath().DirName(); 42 DCHECK(!plugin_dir.empty() && success); 43 base::FilePath voucher_file = plugin_dir.Append( 44 base::FilePath(kVoucherFilename)); 45 content::ChildProcessSecurityPolicy::GetInstance()->GrantReadFile( 46 render_process_id, voucher_file); 47 48 // Init the DeviceIDFetcher. 49 fetcher_ = new DeviceIDFetcher(render_process_id); 50} 51 52PepperFlashDRMHost::~PepperFlashDRMHost() { 53} 54 55int32_t PepperFlashDRMHost::OnResourceMessageReceived( 56 const IPC::Message& msg, 57 ppapi::host::HostMessageContext* context) { 58 IPC_BEGIN_MESSAGE_MAP(PepperFlashDRMHost, msg) 59 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FlashDRM_GetDeviceID, 60 OnHostMsgGetDeviceID) 61 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FlashDRM_GetHmonitor, 62 OnHostMsgGetHmonitor) 63 IPC_END_MESSAGE_MAP() 64 return PP_ERROR_FAILED; 65} 66 67int32_t PepperFlashDRMHost::OnHostMsgGetDeviceID( 68 ppapi::host::HostMessageContext* context) { 69 if (!fetcher_->Start(base::Bind(&PepperFlashDRMHost::GotDeviceID, 70 weak_factory_.GetWeakPtr(), 71 context->MakeReplyMessageContext()))) { 72 return PP_ERROR_INPROGRESS; 73 } 74 return PP_OK_COMPLETIONPENDING; 75} 76 77int32_t PepperFlashDRMHost::OnHostMsgGetHmonitor( 78 ppapi::host::HostMessageContext* context) { 79#if defined(OS_WIN) 80 // TODO(cpu): Get the real HMONITOR. See bug 249135. 81 POINT pt = {1,1}; 82 HMONITOR monitor = ::MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY); 83 int64_t monitor_id = reinterpret_cast<int64_t>(monitor); 84 context->reply_msg = PpapiPluginMsg_FlashDRM_GetHmonitorReply(monitor_id); 85 return PP_OK; 86#else 87 return PP_ERROR_FAILED; 88#endif 89} 90 91void PepperFlashDRMHost::GotDeviceID( 92 ppapi::host::ReplyMessageContext reply_context, 93 const std::string& id) { 94 reply_context.params.set_result( 95 id.empty() ? PP_ERROR_FAILED : PP_OK); 96 host()->SendReply(reply_context, 97 PpapiPluginMsg_FlashDRM_GetDeviceIDReply(id)); 98} 99 100} // namespace chrome 101