Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: content/renderer/renderer_sandbox_support_linux.cc

Issue 6981001: Make the Pepper proxy support in-process font rendering. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "content/renderer/renderer_sandbox_support_linux.h"
6
7 #include <sys/stat.h>
8
9 #include "base/eintr_wrapper.h"
10 #include "base/global_descriptors_posix.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/pickle.h"
13 #include "content/common/chrome_descriptors.h"
14 #include "content/common/sandbox_methods_linux.h"
15 #include "content/common/unix_domain_socket_posix.h"
16
17 #include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebFontRenderSt yle.h"
18
19 static int GetSandboxFD() {
20 return kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor;
21 }
22
23 namespace renderer_sandbox_support {
24
25 std::string getFontFamilyForCharacters(const uint16_t* utf16,
26 size_t num_utf16,
27 const char* preferred_locale) {
28 Pickle request;
29 request.WriteInt(LinuxSandbox::METHOD_GET_FONT_FAMILY_FOR_CHARS);
30 request.WriteInt(num_utf16);
31 for (size_t i = 0; i < num_utf16; ++i)
32 request.WriteUInt32(utf16[i]);
33 request.WriteString(preferred_locale);
34
35 uint8_t buf[512];
36 const ssize_t n = UnixDomainSocket::SendRecvMsg(GetSandboxFD(), buf,
37 sizeof(buf), NULL, request);
38
39 std::string family_name;
40 if (n != -1) {
41 Pickle reply(reinterpret_cast<char*>(buf), n);
42 void* pickle_iter = NULL;
43 reply.ReadString(&pickle_iter, &family_name);
44 }
45
46 return family_name;
47 }
48
49 void getRenderStyleForStrike(const char* family, int sizeAndStyle,
50 WebKit::WebFontRenderStyle* out) {
51 Pickle request;
52 request.WriteInt(LinuxSandbox::METHOD_GET_STYLE_FOR_STRIKE);
53 request.WriteString(family);
54 request.WriteInt(sizeAndStyle);
55
56 uint8_t buf[512];
57 const ssize_t n = UnixDomainSocket::SendRecvMsg(GetSandboxFD(), buf,
58 sizeof(buf), NULL, request);
59
60 out->setDefaults();
61 if (n == -1) {
62 return;
63 }
64
65 Pickle reply(reinterpret_cast<char*>(buf), n);
66 void* pickle_iter = NULL;
67 int useBitmaps, useAutoHint, useHinting, hintStyle, useAntiAlias, useSubpixel;
68 if (reply.ReadInt(&pickle_iter, &useBitmaps) &&
69 reply.ReadInt(&pickle_iter, &useAutoHint) &&
70 reply.ReadInt(&pickle_iter, &useHinting) &&
71 reply.ReadInt(&pickle_iter, &hintStyle) &&
72 reply.ReadInt(&pickle_iter, &useAntiAlias) &&
73 reply.ReadInt(&pickle_iter, &useSubpixel)) {
74 out->useBitmaps = useBitmaps;
75 out->useAutoHint = useAutoHint;
76 out->useHinting = useHinting;
77 out->hintStyle = hintStyle;
78 out->useAntiAlias = useAntiAlias;
79 out->useSubpixel = useSubpixel;
80 }
81 }
82
83 int MakeSharedMemorySegmentViaIPC(size_t length, bool executable) {
84 Pickle request;
85 request.WriteInt(LinuxSandbox::METHOD_MAKE_SHARED_MEMORY_SEGMENT);
86 request.WriteUInt32(length);
87 uint8_t reply_buf[10];
88 int result_fd;
89 ssize_t result = UnixDomainSocket::SendRecvMsg(GetSandboxFD(),
90 reply_buf, sizeof(reply_buf),
91 &result_fd, request);
92 if (result == -1)
93 return -1;
94 return result_fd;
95 }
96
97 int MatchFontWithFallback(const std::string& face, bool bold,
98 bool italic, int charset) {
99 Pickle request;
100 request.WriteInt(LinuxSandbox::METHOD_MATCH_WITH_FALLBACK);
101 request.WriteString(face);
102 request.WriteBool(bold);
103 request.WriteBool(italic);
104 request.WriteUInt32(charset);
105 uint8_t reply_buf[64];
106 int fd = -1;
107 UnixDomainSocket::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf),
108 &fd, request);
109 return fd;
110 }
111
112 bool GetFontTable(int fd, uint32_t table, uint8_t* output,
113 size_t* output_length) {
114 if (table == 0) {
115 struct stat st;
116 if (fstat(fd, &st) < 0)
117 return false;
118 size_t length = st.st_size;
119 if (!output) {
120 *output_length = length;
121 return true;
122 }
123 if (*output_length < length)
124 return false;
125 *output_length = length;
126 ssize_t n = HANDLE_EINTR(pread(fd, output, length, 0));
127 if (n != static_cast<ssize_t>(length))
128 return false;
129 return true;
130 }
131
132 unsigned num_tables;
133 uint8_t num_tables_buf[2];
134
135 ssize_t n = HANDLE_EINTR(pread(fd, &num_tables_buf, sizeof(num_tables_buf),
136 4 /* skip the font type */));
137 if (n != sizeof(num_tables_buf))
138 return false;
139
140 num_tables = static_cast<unsigned>(num_tables_buf[0]) << 8 |
141 num_tables_buf[1];
142
143 // The size in bytes of an entry in the table directory.
144 static const unsigned kTableEntrySize = 16;
145 scoped_array<uint8_t> table_entries(
146 new uint8_t[num_tables * kTableEntrySize]);
147 n = HANDLE_EINTR(pread(fd, table_entries.get(), num_tables * kTableEntrySize,
148 12 /* skip the SFNT header */));
149 if (n != static_cast<ssize_t>(num_tables * kTableEntrySize))
150 return false;
151
152 size_t offset;
153 size_t length = 0;
154 for (unsigned i = 0; i < num_tables; i++) {
155 const uint8_t* entry = table_entries.get() + i * kTableEntrySize;
156 if (memcmp(entry, &table, sizeof(table)) == 0) {
157 offset = static_cast<size_t>(entry[8]) << 24 |
158 static_cast<size_t>(entry[9]) << 16 |
159 static_cast<size_t>(entry[10]) << 8 |
160 static_cast<size_t>(entry[11]);
161 length = static_cast<size_t>(entry[12]) << 24 |
162 static_cast<size_t>(entry[13]) << 16 |
163 static_cast<size_t>(entry[14]) << 8 |
164 static_cast<size_t>(entry[15]);
165
166 break;
167 }
168 }
169
170 if (!length)
171 return false;
172
173 if (!output) {
174 *output_length = length;
175 return true;
176 }
177
178 if (*output_length < length)
179 return false;
180
181 *output_length = length;
182 n = HANDLE_EINTR(pread(fd, output, length, offset));
183 if (n != static_cast<ssize_t>(length))
184 return false;
185
186 return true;
187 }
188
189 } // namespace render_sandbox_support
OLDNEW
« no previous file with comments | « content/renderer/renderer_sandbox_support_linux.h ('k') | content/renderer/renderer_webkitclient_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698