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

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

Issue 2794004: Add a font API to Pepper and implement on Linux based on agl's ... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 6 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
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "chrome/renderer/renderer_sandbox_support_linux.h" 5 #include "chrome/renderer/renderer_sandbox_support_linux.h"
6 6
7 #include <sys/stat.h>
8
9 #include "base/eintr_wrapper.h"
7 #include "base/global_descriptors_posix.h" 10 #include "base/global_descriptors_posix.h"
8 #include "base/pickle.h" 11 #include "base/pickle.h"
12 #include "base/scoped_ptr.h"
9 #include "base/unix_domain_socket_posix.h" 13 #include "base/unix_domain_socket_posix.h"
10 #include "chrome/common/chrome_descriptors.h" 14 #include "chrome/common/chrome_descriptors.h"
11 #include "chrome/common/sandbox_methods_linux.h" 15 #include "chrome/common/sandbox_methods_linux.h"
12 16
13 #include "third_party/WebKit/WebKit/chromium/public/linux/WebFontRenderStyle.h" 17 #include "third_party/WebKit/WebKit/chromium/public/linux/WebFontRenderStyle.h"
14 18
15 static int GetSandboxFD() { 19 static int GetSandboxFD() {
16 return kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor; 20 return kSandboxIPCChannel + base::GlobalDescriptors::kBaseDescriptor;
17 } 21 }
18 22
19 namespace renderer_sandbox_support { 23 namespace renderer_sandbox_support {
20 24
21 std::string getFontFamilyForCharacters(const uint16_t* utf16, size_t num_utf16) { 25 std::string getFontFamilyForCharacters(const uint16_t* utf16,
26 size_t num_utf16) {
22 Pickle request; 27 Pickle request;
23 request.WriteInt(LinuxSandbox::METHOD_GET_FONT_FAMILY_FOR_CHARS); 28 request.WriteInt(LinuxSandbox::METHOD_GET_FONT_FAMILY_FOR_CHARS);
24 request.WriteInt(num_utf16); 29 request.WriteInt(num_utf16);
25 for (size_t i = 0; i < num_utf16; ++i) 30 for (size_t i = 0; i < num_utf16; ++i)
26 request.WriteUInt32(utf16[i]); 31 request.WriteUInt32(utf16[i]);
27 32
28 uint8_t buf[512]; 33 uint8_t buf[512];
29 const ssize_t n = base::SendRecvMsg(GetSandboxFD(), buf, sizeof(buf), NULL, 34 const ssize_t n = base::SendRecvMsg(GetSandboxFD(), buf, sizeof(buf), NULL,
30 request); 35 request);
31 36
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 uint8_t reply_buf[10]; 85 uint8_t reply_buf[10];
81 int result_fd; 86 int result_fd;
82 ssize_t result = base::SendRecvMsg(GetSandboxFD(), 87 ssize_t result = base::SendRecvMsg(GetSandboxFD(),
83 reply_buf, sizeof(reply_buf), 88 reply_buf, sizeof(reply_buf),
84 &result_fd, request); 89 &result_fd, request);
85 if (result == -1) 90 if (result == -1)
86 return -1; 91 return -1;
87 return result_fd; 92 return result_fd;
88 } 93 }
89 94
95 int MatchFontWithFallback(const std::string& face, bool bold,
96 bool italic, NPCharset charset) {
97 Pickle request;
98 request.WriteInt(LinuxSandbox::METHOD_MATCH_WITH_FALLBACK);
99 request.WriteString(face);
100 request.WriteBool(bold);
101 request.WriteBool(italic);
102 request.WriteUInt32(charset);
103 uint8_t reply_buf[64];
104 int fd = -1;
105 base::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf),
106 &fd, request);
107 return fd;
108 }
109
110 bool GetFontTable(int fd, uint32_t table, uint8_t* output,
111 size_t* output_length) {
112 if (table == 0) {
113 struct stat st;
114 if (fstat(fd, &st) < 0)
115 return false;
116 size_t length = st.st_size;
117 if (!output) {
118 *output_length = length;
119 return true;
120 }
121 if (*output_length < length)
122 return false;
123 *output_length = length;
124 ssize_t n = HANDLE_EINTR(pread(fd, output, length, 0));
125 if (n != static_cast<ssize_t>(length))
126 return false;
127 return true;
128 }
129
130 unsigned num_tables;
131 uint8_t num_tables_buf[2];
132
133 ssize_t n = HANDLE_EINTR(pread(fd, &num_tables_buf, sizeof(num_tables_buf),
134 4 /* skip the font type */));
135 if (n != sizeof(num_tables_buf))
136 return false;
137
138 num_tables = static_cast<unsigned>(num_tables_buf[0]) << 8 |
139 num_tables_buf[1];
140
141 // The size in bytes of an entry in the table directory.
142 static const unsigned kTableEntrySize = 16;
143 scoped_array<uint8_t> table_entries(
144 new uint8_t[num_tables * kTableEntrySize]);
145 n = HANDLE_EINTR(pread(fd, table_entries.get(), num_tables * kTableEntrySize,
146 12 /* skip the SFNT header */));
147 if (n != static_cast<ssize_t>(num_tables * kTableEntrySize))
148 return false;
149
150 size_t offset;
151 size_t length = 0;
152 for (unsigned i = 0; i < num_tables; i++) {
153 const uint8_t* entry = table_entries.get() + i * kTableEntrySize;
154 if (memcmp(entry, &table, sizeof(table)) == 0) {
155 offset = static_cast<size_t>(entry[8]) << 24 |
156 static_cast<size_t>(entry[9]) << 16 |
157 static_cast<size_t>(entry[10]) << 8 |
158 static_cast<size_t>(entry[11]);
159 length = static_cast<size_t>(entry[12]) << 24 |
160 static_cast<size_t>(entry[13]) << 16 |
161 static_cast<size_t>(entry[14]) << 8 |
162 static_cast<size_t>(entry[15]);
163
164 break;
165 }
166 }
167
168 if (!length)
169 return false;
170
171 if (!output) {
172 *output_length = length;
173 return true;
174 }
175
176 if (*output_length < length)
177 return false;
178
179 *output_length = length;
180 n = HANDLE_EINTR(pread(fd, output, length, offset));
181 if (n != static_cast<ssize_t>(length))
182 return false;
183
184 return true;
185 }
186
90 } // namespace render_sandbox_support 187 } // namespace render_sandbox_support
OLDNEW
« no previous file with comments | « chrome/renderer/renderer_sandbox_support_linux.h ('k') | chrome/renderer/webplugin_delegate_pepper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698