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

Side by Side Diff: chrome/browser/renderer_host/render_sandbox_host_linux.cc

Issue 132007: Linux: plumb fontconfig call out to the sandbox host. (Closed)
Patch Set: ... Created 11 years, 5 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
« no previous file with comments | « base/message_pump_glib.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" 5 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <sys/uio.h> 9 #include <sys/uio.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
11 #include <sys/poll.h> 11 #include <sys/poll.h>
12 12
13 #include "base/eintr_wrapper.h" 13 #include "base/eintr_wrapper.h"
14 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/message_loop.h" 16 #include "base/message_loop.h"
17 #include "base/pickle.h" 17 #include "base/pickle.h"
18 #include "base/string_util.h"
18 #include "base/unix_domain_socket_posix.h" 19 #include "base/unix_domain_socket_posix.h"
20 #include "chrome/common/sandbox_methods_linux.h"
21 #include "webkit/api/public/gtk/WebFontInfo.h"
19 22
20 #include "SkFontHost_fontconfig_direct.h" 23 #include "SkFontHost_fontconfig_direct.h"
21 #include "SkFontHost_fontconfig_ipc.h" 24 #include "SkFontHost_fontconfig_ipc.h"
22 25
26 using WebKit::WebFontInfo;
27 using WebKit::WebString;
28 using WebKit::WebUChar;
29
23 // http://code.google.com/p/chromium/wiki/LinuxSandboxIPC 30 // http://code.google.com/p/chromium/wiki/LinuxSandboxIPC
24 31
25 // BEWARE: code in this file run across *processes* (not just threads). 32 // BEWARE: code in this file run across *processes* (not just threads).
26 33
27 // This code runs in a child process 34 // This code runs in a child process
28 class SandboxIPCProcess { 35 class SandboxIPCProcess {
29 public: 36 public:
30 // lifeline_fd: this is the read end of a pipe which the browser process 37 // lifeline_fd: this is the read end of a pipe which the browser process
31 // holds the other end of. If the browser process dies, it's descriptors are 38 // holds the other end of. If the browser process dies, it's descriptors are
32 // closed and we will noticed an EOF on the pipe. That's our signal to exit. 39 // closed and we will noticed an EOF on the pipe. That's our signal to exit.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void* iter = NULL; 101 void* iter = NULL;
95 102
96 int kind; 103 int kind;
97 if (!pickle.ReadInt(&iter, &kind)) 104 if (!pickle.ReadInt(&iter, &kind))
98 goto error; 105 goto error;
99 106
100 if (kind == FontConfigIPC::METHOD_MATCH) { 107 if (kind == FontConfigIPC::METHOD_MATCH) {
101 HandleFontMatchRequest(fd, pickle, iter, fds); 108 HandleFontMatchRequest(fd, pickle, iter, fds);
102 } else if (kind == FontConfigIPC::METHOD_OPEN) { 109 } else if (kind == FontConfigIPC::METHOD_OPEN) {
103 HandleFontOpenRequest(fd, pickle, iter, fds); 110 HandleFontOpenRequest(fd, pickle, iter, fds);
111 } else if (kind == LinuxSandbox::METHOD_GET_FONT_FAMILY_FOR_CHARS) {
112 HandleGetFontFamilyForChars(fd, pickle, iter, fds);
104 } 113 }
105 114
106 error: 115 error:
107 for (std::vector<int>::const_iterator 116 for (std::vector<int>::const_iterator
108 i = fds.begin(); i != fds.end(); ++i) { 117 i = fds.begin(); i != fds.end(); ++i) {
109 close(*i); 118 close(*i);
110 } 119 }
111 } 120 }
112 121
113 void HandleFontMatchRequest(int fd, Pickle& pickle, void* iter, 122 void HandleFontMatchRequest(int fd, Pickle& pickle, void* iter,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 Pickle reply; 168 Pickle reply;
160 if (result_fd == -1) { 169 if (result_fd == -1) {
161 reply.WriteBool(false); 170 reply.WriteBool(false);
162 } else { 171 } else {
163 reply.WriteBool(true); 172 reply.WriteBool(true);
164 } 173 }
165 174
166 SendRendererReply(fds, reply, result_fd); 175 SendRendererReply(fds, reply, result_fd);
167 } 176 }
168 177
178 void HandleGetFontFamilyForChars(int fd, Pickle& pickle, void* iter,
179 std::vector<int>& fds) {
180 // The other side of this call is
181 // chrome/renderer/renderer_sandbox_support_linux.cc
182
183 int num_chars;
184 if (!pickle.ReadInt(&iter, &num_chars))
185 return;
186
187 // We don't want a corrupt renderer asking too much of us, it might
188 // overflow later in the code.
189 static const int kMaxChars = 4096;
190 if (num_chars < 1 || num_chars > kMaxChars) {
191 LOG(WARNING) << "HandleGetFontFamilyForChars: too many chars: "
192 << num_chars;
193 return;
194 }
195
196 scoped_array<WebUChar> chars(new WebUChar[num_chars]);
197
198 for (int i = 0; i < num_chars; ++i) {
199 uint32_t c;
200 if (!pickle.ReadUInt32(&iter, &c)) {
201 return;
202 }
203
204 chars[i] = c;
205 }
206
207 const WebString family = WebFontInfo::familyForChars(chars.get(), num_chars) ;
208 const std::string family_utf8 = UTF16ToUTF8(family);
209
210 Pickle reply;
211 reply.WriteString(family_utf8);
212 SendRendererReply(fds, reply, -1);
213 }
214
169 void SendRendererReply(const std::vector<int>& fds, const Pickle& reply, 215 void SendRendererReply(const std::vector<int>& fds, const Pickle& reply,
170 int reply_fd) { 216 int reply_fd) {
171 struct msghdr msg; 217 struct msghdr msg;
172 memset(&msg, 0, sizeof(msg)); 218 memset(&msg, 0, sizeof(msg));
173 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()}; 219 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()};
174 msg.msg_iov = &iov; 220 msg.msg_iov = &iov;
175 msg.msg_iovlen = 1; 221 msg.msg_iovlen = 1;
176 222
177 char control_buffer[CMSG_SPACE(sizeof(int))]; 223 char control_buffer[CMSG_SPACE(sizeof(int))];
178 224
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 SandboxIPCProcess handler(child_lifeline_fd, browser_socket); 265 SandboxIPCProcess handler(child_lifeline_fd, browser_socket);
220 handler.Run(); 266 handler.Run();
221 _exit(0); 267 _exit(0);
222 } 268 }
223 } 269 }
224 270
225 RenderSandboxHostLinux::~RenderSandboxHostLinux() { 271 RenderSandboxHostLinux::~RenderSandboxHostLinux() {
226 HANDLE_EINTR(close(renderer_socket_)); 272 HANDLE_EINTR(close(renderer_socket_));
227 HANDLE_EINTR(close(childs_lifeline_fd_)); 273 HANDLE_EINTR(close(childs_lifeline_fd_));
228 } 274 }
OLDNEW
« no previous file with comments | « base/message_pump_glib.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698