[Android] Added UMA for search by image context menu.
[chromium-blink-merge.git] / chrome / renderer / pepper / pepper_flash_font_file_host.cc
blob524c2276c6d43df3301ecdeffc7e58af17289cd4
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 namespace chrome {
22 PepperFlashFontFileHost::PepperFlashFontFileHost(
23 content::RendererPpapiHost* host,
24 PP_Instance instance,
25 PP_Resource resource,
26 const ppapi::proxy::SerializedFontDescription& description,
27 PP_PrivateFontCharset charset)
28 : ResourceHost(host->GetPpapiHost(), instance, resource),
29 renderer_ppapi_host_(host),
30 fd_(-1) {
31 #if defined(OS_LINUX) || defined(OS_OPENBSD)
32 fd_ = content::MatchFontWithFallback(
33 description.face.c_str(), description.weight >=
34 PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD,
35 description.italic, charset);
36 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
39 PepperFlashFontFileHost::~PepperFlashFontFileHost() {
42 int32_t PepperFlashFontFileHost::OnResourceMessageReceived(
43 const IPC::Message& msg,
44 ppapi::host::HostMessageContext* context) {
45 IPC_BEGIN_MESSAGE_MAP(PepperFlashFontFileHost, msg)
46 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FlashFontFile_GetFontTable,
47 OnGetFontTable)
48 IPC_END_MESSAGE_MAP()
49 return PP_ERROR_FAILED;
52 int32_t PepperFlashFontFileHost::OnGetFontTable(
53 ppapi::host::HostMessageContext* context,
54 uint32_t table) {
55 std::string contents;
56 int32_t result = PP_ERROR_FAILED;
57 #if defined(OS_LINUX) || defined(OS_OPENBSD)
58 if (fd_ != -1) {
59 size_t length = 0;
60 if (content::GetFontTable(fd_, table, 0 /* offset */, NULL, &length)) {
61 contents.resize(length);
62 uint8_t* contents_ptr =
63 reinterpret_cast<uint8_t*>(const_cast<char*>(contents.c_str()));
64 if (content::GetFontTable(fd_, table, 0 /* offset */,
65 contents_ptr, &length)) {
66 result = PP_OK;
67 } else {
68 contents.clear();
72 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
74 context->reply_msg = PpapiPluginMsg_FlashFontFile_GetFontTableReply(contents);
75 return result;
78 } // namespace chrome