During App Launcher install, install V2 App if instructed to do so via environment...
[chromium-blink-merge.git] / content / common / font_config_ipc_linux.cc
blob8dd45a8c574e60c16b4efce68b8ed26ca68e8b3e
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 "content/common/font_config_ipc_linux.h"
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <sys/socket.h>
10 #include <sys/uio.h>
11 #include <unistd.h>
13 #include "base/pickle.h"
14 #include "base/posix/unix_domain_socket_linux.h"
16 namespace content {
18 FontConfigIPC::FontConfigIPC(int fd)
19 : fd_(fd) {
22 FontConfigIPC::~FontConfigIPC() {
23 close(fd_);
26 bool FontConfigIPC::Match(std::string* result_family,
27 unsigned* result_filefaceid,
28 bool filefaceid_valid, unsigned filefaceid,
29 const std::string& family,
30 const void* characters, size_t characters_bytes,
31 bool* is_bold, bool* is_italic) {
32 if (family.length() > kMaxFontFamilyLength)
33 return false;
35 Pickle request;
36 request.WriteInt(METHOD_MATCH);
37 request.WriteBool(filefaceid_valid);
38 if (filefaceid_valid)
39 request.WriteUInt32(filefaceid);
41 request.WriteBool(is_bold && *is_bold);
42 request.WriteBool(is_bold && *is_italic);
44 request.WriteUInt32(characters_bytes);
45 if (characters_bytes)
46 request.WriteBytes(characters, characters_bytes);
48 request.WriteString(family);
50 uint8_t reply_buf[512];
51 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
52 sizeof(reply_buf), NULL,
53 request);
54 if (r == -1)
55 return false;
57 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
58 PickleIterator iter(reply);
59 bool result;
60 if (!reply.ReadBool(&iter, &result))
61 return false;
62 if (!result)
63 return false;
65 uint32_t reply_filefaceid;
66 std::string reply_family;
67 bool resulting_bold, resulting_italic;
68 if (!reply.ReadUInt32(&iter, &reply_filefaceid) ||
69 !reply.ReadString(&iter, &reply_family) ||
70 !reply.ReadBool(&iter, &resulting_bold) ||
71 !reply.ReadBool(&iter, &resulting_italic)) {
72 return false;
75 if (result_filefaceid)
76 *result_filefaceid = reply_filefaceid;
77 if (result_family)
78 *result_family = reply_family;
80 if (is_bold)
81 *is_bold = resulting_bold;
82 if (is_italic)
83 *is_italic = resulting_italic;
85 return true;
88 int FontConfigIPC::Open(unsigned filefaceid) {
89 Pickle request;
90 request.WriteInt(METHOD_OPEN);
91 request.WriteUInt32(filefaceid);
93 int result_fd = -1;
94 uint8_t reply_buf[256];
95 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
96 sizeof(reply_buf),
97 &result_fd, request);
99 if (r == -1)
100 return -1;
102 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
103 bool result;
104 PickleIterator iter(reply);
105 if (!reply.ReadBool(&iter, &result) ||
106 !result) {
107 if (result_fd)
108 close(result_fd);
109 return -1;
112 return result_fd;
115 } // namespace content