OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/renderer_host/sandbox_ipc_linux.h" | 5 #include "content/browser/renderer_host/sandbox_ipc_linux.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <sys/poll.h> | 8 #include <sys/poll.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 NOTREACHED() << "Sandbox host message is larger than kMaxFontFamilyLength"; | 137 NOTREACHED() << "Sandbox host message is larger than kMaxFontFamilyLength"; |
138 return; | 138 return; |
139 } | 139 } |
140 if (fds.empty()) | 140 if (fds.empty()) |
141 return; | 141 return; |
142 | 142 |
143 Pickle pickle(buf, len); | 143 Pickle pickle(buf, len); |
144 PickleIterator iter(pickle); | 144 PickleIterator iter(pickle); |
145 | 145 |
146 int kind; | 146 int kind; |
147 if (!pickle.ReadInt(&iter, &kind)) | 147 if (!iter.ReadInt(&kind)) |
148 return; | 148 return; |
149 | 149 |
150 if (kind == FontConfigIPC::METHOD_MATCH) { | 150 if (kind == FontConfigIPC::METHOD_MATCH) { |
151 HandleFontMatchRequest(fd, pickle, iter, fds.get()); | 151 HandleFontMatchRequest(fd, iter, fds.get()); |
152 } else if (kind == FontConfigIPC::METHOD_OPEN) { | 152 } else if (kind == FontConfigIPC::METHOD_OPEN) { |
153 HandleFontOpenRequest(fd, pickle, iter, fds.get()); | 153 HandleFontOpenRequest(fd, iter, fds.get()); |
154 } else if (kind == LinuxSandbox::METHOD_GET_FALLBACK_FONT_FOR_CHAR) { | 154 } else if (kind == LinuxSandbox::METHOD_GET_FALLBACK_FONT_FOR_CHAR) { |
155 HandleGetFallbackFontForChar(fd, pickle, iter, fds.get()); | 155 HandleGetFallbackFontForChar(fd, iter, fds.get()); |
156 } else if (kind == LinuxSandbox::METHOD_LOCALTIME) { | 156 } else if (kind == LinuxSandbox::METHOD_LOCALTIME) { |
157 HandleLocaltime(fd, pickle, iter, fds.get()); | 157 HandleLocaltime(fd, iter, fds.get()); |
158 } else if (kind == LinuxSandbox::METHOD_GET_STYLE_FOR_STRIKE) { | 158 } else if (kind == LinuxSandbox::METHOD_GET_STYLE_FOR_STRIKE) { |
159 HandleGetStyleForStrike(fd, pickle, iter, fds.get()); | 159 HandleGetStyleForStrike(fd, iter, fds.get()); |
160 } else if (kind == LinuxSandbox::METHOD_MAKE_SHARED_MEMORY_SEGMENT) { | 160 } else if (kind == LinuxSandbox::METHOD_MAKE_SHARED_MEMORY_SEGMENT) { |
161 HandleMakeSharedMemorySegment(fd, pickle, iter, fds.get()); | 161 HandleMakeSharedMemorySegment(fd, iter, fds.get()); |
162 } else if (kind == LinuxSandbox::METHOD_MATCH_WITH_FALLBACK) { | 162 } else if (kind == LinuxSandbox::METHOD_MATCH_WITH_FALLBACK) { |
163 HandleMatchWithFallback(fd, pickle, iter, fds.get()); | 163 HandleMatchWithFallback(fd, iter, fds.get()); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 int SandboxIPCHandler::FindOrAddPath(const SkString& path) { | 167 int SandboxIPCHandler::FindOrAddPath(const SkString& path) { |
168 int count = paths_.count(); | 168 int count = paths_.count(); |
169 for (int i = 0; i < count; ++i) { | 169 for (int i = 0; i < count; ++i) { |
170 if (path == *paths_[i]) | 170 if (path == *paths_[i]) |
171 return i; | 171 return i; |
172 } | 172 } |
173 *paths_.append() = new SkString(path); | 173 *paths_.append() = new SkString(path); |
174 return count; | 174 return count; |
175 } | 175 } |
176 | 176 |
177 void SandboxIPCHandler::HandleFontMatchRequest( | 177 void SandboxIPCHandler::HandleFontMatchRequest( |
178 int fd, | 178 int fd, |
179 const Pickle& pickle, | |
180 PickleIterator iter, | 179 PickleIterator iter, |
181 const std::vector<base::ScopedFD*>& fds) { | 180 const std::vector<base::ScopedFD*>& fds) { |
182 uint32_t requested_style; | 181 uint32_t requested_style; |
183 std::string family; | 182 std::string family; |
184 if (!pickle.ReadString(&iter, &family) || | 183 if (!iter.ReadString(&family) || !iter.ReadUInt32(&requested_style)) |
185 !pickle.ReadUInt32(&iter, &requested_style)) | |
186 return; | 184 return; |
187 | 185 |
188 SkFontConfigInterface::FontIdentity result_identity; | 186 SkFontConfigInterface::FontIdentity result_identity; |
189 SkString result_family; | 187 SkString result_family; |
190 SkTypeface::Style result_style; | 188 SkTypeface::Style result_style; |
191 SkFontConfigInterface* fc = | 189 SkFontConfigInterface* fc = |
192 SkFontConfigInterface::GetSingletonDirectInterface(); | 190 SkFontConfigInterface::GetSingletonDirectInterface(); |
193 const bool r = | 191 const bool r = |
194 fc->matchFamilyName(family.c_str(), | 192 fc->matchFamilyName(family.c_str(), |
195 static_cast<SkTypeface::Style>(requested_style), | 193 static_cast<SkTypeface::Style>(requested_style), |
(...skipping 13 matching lines...) Expand all Loading... |
209 reply.WriteBool(true); | 207 reply.WriteBool(true); |
210 skia::WriteSkString(&reply, result_family); | 208 skia::WriteSkString(&reply, result_family); |
211 skia::WriteSkFontIdentity(&reply, result_identity); | 209 skia::WriteSkFontIdentity(&reply, result_identity); |
212 reply.WriteUInt32(result_style); | 210 reply.WriteUInt32(result_style); |
213 } | 211 } |
214 SendRendererReply(fds, reply, -1); | 212 SendRendererReply(fds, reply, -1); |
215 } | 213 } |
216 | 214 |
217 void SandboxIPCHandler::HandleFontOpenRequest( | 215 void SandboxIPCHandler::HandleFontOpenRequest( |
218 int fd, | 216 int fd, |
219 const Pickle& pickle, | |
220 PickleIterator iter, | 217 PickleIterator iter, |
221 const std::vector<base::ScopedFD*>& fds) { | 218 const std::vector<base::ScopedFD*>& fds) { |
222 uint32_t index; | 219 uint32_t index; |
223 if (!pickle.ReadUInt32(&iter, &index)) | 220 if (!iter.ReadUInt32(&index)) |
224 return; | 221 return; |
225 if (index >= static_cast<uint32_t>(paths_.count())) | 222 if (index >= static_cast<uint32_t>(paths_.count())) |
226 return; | 223 return; |
227 const int result_fd = open(paths_[index]->c_str(), O_RDONLY); | 224 const int result_fd = open(paths_[index]->c_str(), O_RDONLY); |
228 | 225 |
229 Pickle reply; | 226 Pickle reply; |
230 if (result_fd == -1) { | 227 if (result_fd == -1) { |
231 reply.WriteBool(false); | 228 reply.WriteBool(false); |
232 } else { | 229 } else { |
233 reply.WriteBool(true); | 230 reply.WriteBool(true); |
234 } | 231 } |
235 | 232 |
236 // The receiver will have its own access to the file, so we will close it | 233 // The receiver will have its own access to the file, so we will close it |
237 // after this send. | 234 // after this send. |
238 SendRendererReply(fds, reply, result_fd); | 235 SendRendererReply(fds, reply, result_fd); |
239 | 236 |
240 if (result_fd >= 0) { | 237 if (result_fd >= 0) { |
241 int err = IGNORE_EINTR(close(result_fd)); | 238 int err = IGNORE_EINTR(close(result_fd)); |
242 DCHECK(!err); | 239 DCHECK(!err); |
243 } | 240 } |
244 } | 241 } |
245 | 242 |
246 void SandboxIPCHandler::HandleGetFallbackFontForChar( | 243 void SandboxIPCHandler::HandleGetFallbackFontForChar( |
247 int fd, | 244 int fd, |
248 const Pickle& pickle, | |
249 PickleIterator iter, | 245 PickleIterator iter, |
250 const std::vector<base::ScopedFD*>& fds) { | 246 const std::vector<base::ScopedFD*>& fds) { |
251 // The other side of this call is | 247 // The other side of this call is |
252 // content/common/child_process_sandbox_support_impl_linux.cc | 248 // content/common/child_process_sandbox_support_impl_linux.cc |
253 | 249 |
254 EnsureWebKitInitialized(); | 250 EnsureWebKitInitialized(); |
255 WebUChar32 c; | 251 WebUChar32 c; |
256 if (!pickle.ReadInt(&iter, &c)) | 252 if (!iter.ReadInt(&c)) |
257 return; | 253 return; |
258 | 254 |
259 std::string preferred_locale; | 255 std::string preferred_locale; |
260 if (!pickle.ReadString(&iter, &preferred_locale)) | 256 if (!iter.ReadString(&preferred_locale)) |
261 return; | 257 return; |
262 | 258 |
263 blink::WebFallbackFont fallbackFont; | 259 blink::WebFallbackFont fallbackFont; |
264 WebFontInfo::fallbackFontForChar(c, preferred_locale.c_str(), &fallbackFont); | 260 WebFontInfo::fallbackFontForChar(c, preferred_locale.c_str(), &fallbackFont); |
265 | 261 |
266 int pathIndex = FindOrAddPath(SkString(fallbackFont.filename.data())); | 262 int pathIndex = FindOrAddPath(SkString(fallbackFont.filename.data())); |
267 fallbackFont.fontconfigInterfaceId = pathIndex; | 263 fallbackFont.fontconfigInterfaceId = pathIndex; |
268 | 264 |
269 Pickle reply; | 265 Pickle reply; |
270 if (fallbackFont.name.data()) { | 266 if (fallbackFont.name.data()) { |
271 reply.WriteString(fallbackFont.name.data()); | 267 reply.WriteString(fallbackFont.name.data()); |
272 } else { | 268 } else { |
273 reply.WriteString(std::string()); | 269 reply.WriteString(std::string()); |
274 } | 270 } |
275 if (fallbackFont.filename.data()) { | 271 if (fallbackFont.filename.data()) { |
276 reply.WriteString(fallbackFont.filename.data()); | 272 reply.WriteString(fallbackFont.filename.data()); |
277 } else { | 273 } else { |
278 reply.WriteString(std::string()); | 274 reply.WriteString(std::string()); |
279 } | 275 } |
280 reply.WriteInt(fallbackFont.fontconfigInterfaceId); | 276 reply.WriteInt(fallbackFont.fontconfigInterfaceId); |
281 reply.WriteInt(fallbackFont.ttcIndex); | 277 reply.WriteInt(fallbackFont.ttcIndex); |
282 reply.WriteBool(fallbackFont.isBold); | 278 reply.WriteBool(fallbackFont.isBold); |
283 reply.WriteBool(fallbackFont.isItalic); | 279 reply.WriteBool(fallbackFont.isItalic); |
284 SendRendererReply(fds, reply, -1); | 280 SendRendererReply(fds, reply, -1); |
285 } | 281 } |
286 | 282 |
287 void SandboxIPCHandler::HandleGetStyleForStrike( | 283 void SandboxIPCHandler::HandleGetStyleForStrike( |
288 int fd, | 284 int fd, |
289 const Pickle& pickle, | |
290 PickleIterator iter, | 285 PickleIterator iter, |
291 const std::vector<base::ScopedFD*>& fds) { | 286 const std::vector<base::ScopedFD*>& fds) { |
292 std::string family; | 287 std::string family; |
293 bool bold, italic; | 288 bool bold, italic; |
294 uint16 pixel_size; | 289 uint16 pixel_size; |
295 | 290 |
296 if (!pickle.ReadString(&iter, &family) || | 291 if (!iter.ReadString(&family) || |
297 !pickle.ReadBool(&iter, &bold) || | 292 !iter.ReadBool(&bold) || |
298 !pickle.ReadBool(&iter, &italic) || | 293 !iter.ReadBool(&italic) || |
299 !pickle.ReadUInt16(&iter, &pixel_size)) { | 294 !iter.ReadUInt16(&pixel_size)) { |
300 return; | 295 return; |
301 } | 296 } |
302 | 297 |
303 EnsureWebKitInitialized(); | 298 EnsureWebKitInitialized(); |
304 | 299 |
305 gfx::FontRenderParamsQuery query(true); | 300 gfx::FontRenderParamsQuery query(true); |
306 query.families.push_back(family); | 301 query.families.push_back(family); |
307 query.pixel_size = pixel_size; | 302 query.pixel_size = pixel_size; |
308 query.style = gfx::Font::NORMAL | | 303 query.style = gfx::Font::NORMAL | |
309 (bold ? gfx::Font::BOLD : 0) | (italic ? gfx::Font::ITALIC : 0); | 304 (bold ? gfx::Font::BOLD : 0) | (italic ? gfx::Font::ITALIC : 0); |
310 const gfx::FontRenderParams params = gfx::GetFontRenderParams(query, NULL); | 305 const gfx::FontRenderParams params = gfx::GetFontRenderParams(query, NULL); |
311 | 306 |
312 // These are passed as ints since they're interpreted as tri-state chars in | 307 // These are passed as ints since they're interpreted as tri-state chars in |
313 // Blink. | 308 // Blink. |
314 Pickle reply; | 309 Pickle reply; |
315 reply.WriteInt(params.use_bitmaps); | 310 reply.WriteInt(params.use_bitmaps); |
316 reply.WriteInt(params.autohinter); | 311 reply.WriteInt(params.autohinter); |
317 reply.WriteInt(params.hinting != gfx::FontRenderParams::HINTING_NONE); | 312 reply.WriteInt(params.hinting != gfx::FontRenderParams::HINTING_NONE); |
318 reply.WriteInt(ConvertHinting(params.hinting)); | 313 reply.WriteInt(ConvertHinting(params.hinting)); |
319 reply.WriteInt(params.antialiasing); | 314 reply.WriteInt(params.antialiasing); |
320 reply.WriteInt(ConvertSubpixelRendering(params.subpixel_rendering)); | 315 reply.WriteInt(ConvertSubpixelRendering(params.subpixel_rendering)); |
321 reply.WriteInt(params.subpixel_positioning); | 316 reply.WriteInt(params.subpixel_positioning); |
322 | 317 |
323 SendRendererReply(fds, reply, -1); | 318 SendRendererReply(fds, reply, -1); |
324 } | 319 } |
325 | 320 |
326 void SandboxIPCHandler::HandleLocaltime( | 321 void SandboxIPCHandler::HandleLocaltime( |
327 int fd, | 322 int fd, |
328 const Pickle& pickle, | |
329 PickleIterator iter, | 323 PickleIterator iter, |
330 const std::vector<base::ScopedFD*>& fds) { | 324 const std::vector<base::ScopedFD*>& fds) { |
331 // The other side of this call is in zygote_main_linux.cc | 325 // The other side of this call is in zygote_main_linux.cc |
332 | 326 |
333 std::string time_string; | 327 std::string time_string; |
334 if (!pickle.ReadString(&iter, &time_string) || | 328 if (!iter.ReadString(&time_string) || time_string.size() != sizeof(time_t)) |
335 time_string.size() != sizeof(time_t)) { | |
336 return; | 329 return; |
337 } | |
338 | 330 |
339 time_t time; | 331 time_t time; |
340 memcpy(&time, time_string.data(), sizeof(time)); | 332 memcpy(&time, time_string.data(), sizeof(time)); |
341 // We use localtime here because we need the tm_zone field to be filled | 333 // We use localtime here because we need the tm_zone field to be filled |
342 // out. Since we are a single-threaded process, this is safe. | 334 // out. Since we are a single-threaded process, this is safe. |
343 const struct tm* expanded_time = localtime(&time); | 335 const struct tm* expanded_time = localtime(&time); |
344 | 336 |
345 std::string result_string; | 337 std::string result_string; |
346 const char* time_zone_string = ""; | 338 const char* time_zone_string = ""; |
347 if (expanded_time != NULL) { | 339 if (expanded_time != NULL) { |
348 result_string = std::string(reinterpret_cast<const char*>(expanded_time), | 340 result_string = std::string(reinterpret_cast<const char*>(expanded_time), |
349 sizeof(struct tm)); | 341 sizeof(struct tm)); |
350 time_zone_string = expanded_time->tm_zone; | 342 time_zone_string = expanded_time->tm_zone; |
351 } | 343 } |
352 | 344 |
353 Pickle reply; | 345 Pickle reply; |
354 reply.WriteString(result_string); | 346 reply.WriteString(result_string); |
355 reply.WriteString(time_zone_string); | 347 reply.WriteString(time_zone_string); |
356 SendRendererReply(fds, reply, -1); | 348 SendRendererReply(fds, reply, -1); |
357 } | 349 } |
358 | 350 |
359 void SandboxIPCHandler::HandleMakeSharedMemorySegment( | 351 void SandboxIPCHandler::HandleMakeSharedMemorySegment( |
360 int fd, | 352 int fd, |
361 const Pickle& pickle, | |
362 PickleIterator iter, | 353 PickleIterator iter, |
363 const std::vector<base::ScopedFD*>& fds) { | 354 const std::vector<base::ScopedFD*>& fds) { |
364 base::SharedMemoryCreateOptions options; | 355 base::SharedMemoryCreateOptions options; |
365 uint32_t size; | 356 uint32_t size; |
366 if (!pickle.ReadUInt32(&iter, &size)) | 357 if (!iter.ReadUInt32(&size)) |
367 return; | 358 return; |
368 options.size = size; | 359 options.size = size; |
369 if (!pickle.ReadBool(&iter, &options.executable)) | 360 if (!iter.ReadBool(&options.executable)) |
370 return; | 361 return; |
371 int shm_fd = -1; | 362 int shm_fd = -1; |
372 base::SharedMemory shm; | 363 base::SharedMemory shm; |
373 if (shm.Create(options)) | 364 if (shm.Create(options)) |
374 shm_fd = shm.handle().fd; | 365 shm_fd = shm.handle().fd; |
375 Pickle reply; | 366 Pickle reply; |
376 SendRendererReply(fds, reply, shm_fd); | 367 SendRendererReply(fds, reply, shm_fd); |
377 } | 368 } |
378 | 369 |
379 void SandboxIPCHandler::HandleMatchWithFallback( | 370 void SandboxIPCHandler::HandleMatchWithFallback( |
380 int fd, | 371 int fd, |
381 const Pickle& pickle, | |
382 PickleIterator iter, | 372 PickleIterator iter, |
383 const std::vector<base::ScopedFD*>& fds) { | 373 const std::vector<base::ScopedFD*>& fds) { |
384 std::string face; | 374 std::string face; |
385 bool is_bold, is_italic; | 375 bool is_bold, is_italic; |
386 uint32 charset, fallback_family; | 376 uint32 charset, fallback_family; |
387 | 377 |
388 if (!pickle.ReadString(&iter, &face) || face.empty() || | 378 if (!iter.ReadString(&face) || face.empty() || |
389 !pickle.ReadBool(&iter, &is_bold) || | 379 !iter.ReadBool(&is_bold) || |
390 !pickle.ReadBool(&iter, &is_italic) || | 380 !iter.ReadBool(&is_italic) || |
391 !pickle.ReadUInt32(&iter, &charset) || | 381 !iter.ReadUInt32(&charset) || |
392 !pickle.ReadUInt32(&iter, &fallback_family)) { | 382 !iter.ReadUInt32(&fallback_family)) { |
393 return; | 383 return; |
394 } | 384 } |
395 | 385 |
396 int font_fd = MatchFontFaceWithFallback( | 386 int font_fd = MatchFontFaceWithFallback( |
397 face, is_bold, is_italic, charset, fallback_family); | 387 face, is_bold, is_italic, charset, fallback_family); |
398 | 388 |
399 Pickle reply; | 389 Pickle reply; |
400 SendRendererReply(fds, reply, font_fd); | 390 SendRendererReply(fds, reply, font_fd); |
401 | 391 |
402 if (font_fd >= 0) { | 392 if (font_fd >= 0) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 443 } |
454 | 444 |
455 void SandboxIPCHandler::EnsureWebKitInitialized() { | 445 void SandboxIPCHandler::EnsureWebKitInitialized() { |
456 if (blink_platform_impl_) | 446 if (blink_platform_impl_) |
457 return; | 447 return; |
458 blink_platform_impl_.reset(new BlinkPlatformImpl); | 448 blink_platform_impl_.reset(new BlinkPlatformImpl); |
459 blink::initializeWithoutV8(blink_platform_impl_.get()); | 449 blink::initializeWithoutV8(blink_platform_impl_.get()); |
460 } | 450 } |
461 | 451 |
462 } // namespace content | 452 } // namespace content |
OLD | NEW |