Update V8 to version 4.2.36 (based on d0f3e5302c8d89fee4995b86a2b83c9ecf5d1e7a).
[chromium-blink-merge.git] / chrome / renderer / pepper / pepper_flash_font_file_host.cc
blob305b6ec56c071a19cb859a0267819a1af980993b
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_font_file_host.h"
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"
16 #if defined(OS_LINUX) || defined(OS_OPENBSD)
17 #include "content/public/common/child_process_sandbox_support_linux.h"
18 #endif
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 #if defined(OS_LINUX) || defined(OS_OPENBSD)
28 fd_.reset(content::MatchFontWithFallback(
29 description.face.c_str(),
30 description.weight >= PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD,
31 description.italic,
32 charset,
33 PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT));
34 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
37 PepperFlashFontFileHost::~PepperFlashFontFileHost() {}
39 int32_t PepperFlashFontFileHost::OnResourceMessageReceived(
40 const IPC::Message& msg,
41 ppapi::host::HostMessageContext* context) {
42 PPAPI_BEGIN_MESSAGE_MAP(PepperFlashFontFileHost, msg)
43 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FlashFontFile_GetFontTable,
44 OnGetFontTable)
45 PPAPI_END_MESSAGE_MAP()
46 return PP_ERROR_FAILED;
49 int32_t PepperFlashFontFileHost::OnGetFontTable(
50 ppapi::host::HostMessageContext* context,
51 uint32_t table) {
52 std::string contents;
53 int32_t result = PP_ERROR_FAILED;
54 #if defined(OS_LINUX) || defined(OS_OPENBSD)
55 int fd = fd_.get();
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(
63 fd, table, 0 /* offset */, contents_ptr, &length)) {
64 result = PP_OK;
65 } else {
66 contents.clear();
70 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
72 context->reply_msg = PpapiPluginMsg_FlashFontFile_GetFontTableReply(contents);
73 return result;