• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/renderer/pepper/pepper_flash_font_file_host.h"
6 
7 #include "build/build_config.h"
8 #include "content/public/renderer/renderer_ppapi_host.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/host/dispatch_host_message.h"
11 #include "ppapi/host/host_message_context.h"
12 #include "ppapi/host/ppapi_host.h"
13 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/proxy/serialized_structs.h"
15 
16 #if defined(OS_LINUX) || defined(OS_OPENBSD)
17 #include "content/public/common/child_process_sandbox_support_linux.h"
18 #endif
19 
PepperFlashFontFileHost(content::RendererPpapiHost * host,PP_Instance instance,PP_Resource resource,const ppapi::proxy::SerializedFontDescription & description,PP_PrivateFontCharset charset)20 PepperFlashFontFileHost::PepperFlashFontFileHost(
21     content::RendererPpapiHost* host,
22     PP_Instance instance,
23     PP_Resource resource,
24     const ppapi::proxy::SerializedFontDescription& description,
25     PP_PrivateFontCharset charset)
26     : ResourceHost(host->GetPpapiHost(), instance, resource),
27       renderer_ppapi_host_(host),
28       fd_(-1) {
29 #if defined(OS_LINUX) || defined(OS_OPENBSD)
30   fd_ = content::MatchFontWithFallback(
31       description.face.c_str(), description.weight >=
32           PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD,
33       description.italic, charset);
34 #endif  // defined(OS_LINUX) || defined(OS_OPENBSD)
35 }
36 
~PepperFlashFontFileHost()37 PepperFlashFontFileHost::~PepperFlashFontFileHost() {
38 }
39 
OnResourceMessageReceived(const IPC::Message & msg,ppapi::host::HostMessageContext * context)40 int32_t PepperFlashFontFileHost::OnResourceMessageReceived(
41     const IPC::Message& msg,
42     ppapi::host::HostMessageContext* context) {
43   IPC_BEGIN_MESSAGE_MAP(PepperFlashFontFileHost, msg)
44     PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FlashFontFile_GetFontTable,
45                                       OnGetFontTable)
46   IPC_END_MESSAGE_MAP()
47   return PP_ERROR_FAILED;
48 }
49 
OnGetFontTable(ppapi::host::HostMessageContext * context,uint32_t table)50 int32_t PepperFlashFontFileHost::OnGetFontTable(
51     ppapi::host::HostMessageContext* context,
52     uint32_t table) {
53   std::string contents;
54   int32_t result = PP_ERROR_FAILED;
55 #if defined(OS_LINUX) || defined(OS_OPENBSD)
56   if (fd_ != -1) {
57     size_t length = 0;
58     if (content::GetFontTable(fd_, table, 0 /* offset */, NULL, &length)) {
59       contents.resize(length);
60       uint8_t* contents_ptr =
61           reinterpret_cast<uint8_t*>(const_cast<char*>(contents.c_str()));
62       if (content::GetFontTable(fd_, table, 0 /* offset */,
63                                 contents_ptr, &length)) {
64         result = PP_OK;
65       } else {
66         contents.clear();
67       }
68     }
69   }
70 #endif  // defined(OS_LINUX) || defined(OS_OPENBSD)
71 
72   context->reply_msg = PpapiPluginMsg_FlashFontFile_GetFontTableReply(contents);
73   return result;
74 }
75