| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); | 134 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); |
| 135 if (len == -1) { | 135 if (len == -1) { |
| 136 // TODO: should send an error reply, or the sender might block forever. | 136 // TODO: should send an error reply, or the sender might block forever. |
| 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 base::Pickle pickle(buf, len); |
| 144 PickleIterator iter(pickle); | 144 base::PickleIterator iter(pickle); |
| 145 | 145 |
| 146 int kind; | 146 int kind; |
| 147 if (!iter.ReadInt(&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, 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, 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) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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 PickleIterator iter, | 179 base::PickleIterator iter, |
| 180 const std::vector<base::ScopedFD*>& fds) { | 180 const std::vector<base::ScopedFD*>& fds) { |
| 181 uint32_t requested_style; | 181 uint32_t requested_style; |
| 182 std::string family; | 182 std::string family; |
| 183 if (!iter.ReadString(&family) || !iter.ReadUInt32(&requested_style)) | 183 if (!iter.ReadString(&family) || !iter.ReadUInt32(&requested_style)) |
| 184 return; | 184 return; |
| 185 | 185 |
| 186 SkFontConfigInterface::FontIdentity result_identity; | 186 SkFontConfigInterface::FontIdentity result_identity; |
| 187 SkString result_family; | 187 SkString result_family; |
| 188 SkTypeface::Style result_style; | 188 SkTypeface::Style result_style; |
| 189 SkFontConfigInterface* fc = | 189 SkFontConfigInterface* fc = |
| 190 SkFontConfigInterface::GetSingletonDirectInterface(); | 190 SkFontConfigInterface::GetSingletonDirectInterface(); |
| 191 const bool r = | 191 const bool r = |
| 192 fc->matchFamilyName(family.c_str(), | 192 fc->matchFamilyName(family.c_str(), |
| 193 static_cast<SkTypeface::Style>(requested_style), | 193 static_cast<SkTypeface::Style>(requested_style), |
| 194 &result_identity, | 194 &result_identity, |
| 195 &result_family, | 195 &result_family, |
| 196 &result_style); | 196 &result_style); |
| 197 | 197 |
| 198 Pickle reply; | 198 base::Pickle reply; |
| 199 if (!r) { | 199 if (!r) { |
| 200 reply.WriteBool(false); | 200 reply.WriteBool(false); |
| 201 } else { | 201 } else { |
| 202 // Stash away the returned path, so we can give it an ID (index) | 202 // Stash away the returned path, so we can give it an ID (index) |
| 203 // which will later be given to us in a request to open the file. | 203 // which will later be given to us in a request to open the file. |
| 204 int index = FindOrAddPath(result_identity.fString); | 204 int index = FindOrAddPath(result_identity.fString); |
| 205 result_identity.fID = static_cast<uint32_t>(index); | 205 result_identity.fID = static_cast<uint32_t>(index); |
| 206 | 206 |
| 207 reply.WriteBool(true); | 207 reply.WriteBool(true); |
| 208 skia::WriteSkString(&reply, result_family); | 208 skia::WriteSkString(&reply, result_family); |
| 209 skia::WriteSkFontIdentity(&reply, result_identity); | 209 skia::WriteSkFontIdentity(&reply, result_identity); |
| 210 reply.WriteUInt32(result_style); | 210 reply.WriteUInt32(result_style); |
| 211 } | 211 } |
| 212 SendRendererReply(fds, reply, -1); | 212 SendRendererReply(fds, reply, -1); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void SandboxIPCHandler::HandleFontOpenRequest( | 215 void SandboxIPCHandler::HandleFontOpenRequest( |
| 216 int fd, | 216 int fd, |
| 217 PickleIterator iter, | 217 base::PickleIterator iter, |
| 218 const std::vector<base::ScopedFD*>& fds) { | 218 const std::vector<base::ScopedFD*>& fds) { |
| 219 uint32_t index; | 219 uint32_t index; |
| 220 if (!iter.ReadUInt32(&index)) | 220 if (!iter.ReadUInt32(&index)) |
| 221 return; | 221 return; |
| 222 if (index >= static_cast<uint32_t>(paths_.count())) | 222 if (index >= static_cast<uint32_t>(paths_.count())) |
| 223 return; | 223 return; |
| 224 const int result_fd = open(paths_[index]->c_str(), O_RDONLY); | 224 const int result_fd = open(paths_[index]->c_str(), O_RDONLY); |
| 225 | 225 |
| 226 Pickle reply; | 226 base::Pickle reply; |
| 227 if (result_fd == -1) { | 227 if (result_fd == -1) { |
| 228 reply.WriteBool(false); | 228 reply.WriteBool(false); |
| 229 } else { | 229 } else { |
| 230 reply.WriteBool(true); | 230 reply.WriteBool(true); |
| 231 } | 231 } |
| 232 | 232 |
| 233 // 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 |
| 234 // after this send. | 234 // after this send. |
| 235 SendRendererReply(fds, reply, result_fd); | 235 SendRendererReply(fds, reply, result_fd); |
| 236 | 236 |
| 237 if (result_fd >= 0) { | 237 if (result_fd >= 0) { |
| 238 int err = IGNORE_EINTR(close(result_fd)); | 238 int err = IGNORE_EINTR(close(result_fd)); |
| 239 DCHECK(!err); | 239 DCHECK(!err); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 void SandboxIPCHandler::HandleGetFallbackFontForChar( | 243 void SandboxIPCHandler::HandleGetFallbackFontForChar( |
| 244 int fd, | 244 int fd, |
| 245 PickleIterator iter, | 245 base::PickleIterator iter, |
| 246 const std::vector<base::ScopedFD*>& fds) { | 246 const std::vector<base::ScopedFD*>& fds) { |
| 247 // The other side of this call is | 247 // The other side of this call is |
| 248 // content/common/child_process_sandbox_support_impl_linux.cc | 248 // content/common/child_process_sandbox_support_impl_linux.cc |
| 249 | 249 |
| 250 EnsureWebKitInitialized(); | 250 EnsureWebKitInitialized(); |
| 251 WebUChar32 c; | 251 WebUChar32 c; |
| 252 if (!iter.ReadInt(&c)) | 252 if (!iter.ReadInt(&c)) |
| 253 return; | 253 return; |
| 254 | 254 |
| 255 std::string preferred_locale; | 255 std::string preferred_locale; |
| 256 if (!iter.ReadString(&preferred_locale)) | 256 if (!iter.ReadString(&preferred_locale)) |
| 257 return; | 257 return; |
| 258 | 258 |
| 259 blink::WebFallbackFont fallbackFont; | 259 blink::WebFallbackFont fallbackFont; |
| 260 WebFontInfo::fallbackFontForChar(c, preferred_locale.c_str(), &fallbackFont); | 260 WebFontInfo::fallbackFontForChar(c, preferred_locale.c_str(), &fallbackFont); |
| 261 | 261 |
| 262 int pathIndex = FindOrAddPath(SkString(fallbackFont.filename.data())); | 262 int pathIndex = FindOrAddPath(SkString(fallbackFont.filename.data())); |
| 263 fallbackFont.fontconfigInterfaceId = pathIndex; | 263 fallbackFont.fontconfigInterfaceId = pathIndex; |
| 264 | 264 |
| 265 Pickle reply; | 265 base::Pickle reply; |
| 266 if (fallbackFont.name.data()) { | 266 if (fallbackFont.name.data()) { |
| 267 reply.WriteString(fallbackFont.name.data()); | 267 reply.WriteString(fallbackFont.name.data()); |
| 268 } else { | 268 } else { |
| 269 reply.WriteString(std::string()); | 269 reply.WriteString(std::string()); |
| 270 } | 270 } |
| 271 if (fallbackFont.filename.data()) { | 271 if (fallbackFont.filename.data()) { |
| 272 reply.WriteString(fallbackFont.filename.data()); | 272 reply.WriteString(fallbackFont.filename.data()); |
| 273 } else { | 273 } else { |
| 274 reply.WriteString(std::string()); | 274 reply.WriteString(std::string()); |
| 275 } | 275 } |
| 276 reply.WriteInt(fallbackFont.fontconfigInterfaceId); | 276 reply.WriteInt(fallbackFont.fontconfigInterfaceId); |
| 277 reply.WriteInt(fallbackFont.ttcIndex); | 277 reply.WriteInt(fallbackFont.ttcIndex); |
| 278 reply.WriteBool(fallbackFont.isBold); | 278 reply.WriteBool(fallbackFont.isBold); |
| 279 reply.WriteBool(fallbackFont.isItalic); | 279 reply.WriteBool(fallbackFont.isItalic); |
| 280 SendRendererReply(fds, reply, -1); | 280 SendRendererReply(fds, reply, -1); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void SandboxIPCHandler::HandleGetStyleForStrike( | 283 void SandboxIPCHandler::HandleGetStyleForStrike( |
| 284 int fd, | 284 int fd, |
| 285 PickleIterator iter, | 285 base::PickleIterator iter, |
| 286 const std::vector<base::ScopedFD*>& fds) { | 286 const std::vector<base::ScopedFD*>& fds) { |
| 287 std::string family; | 287 std::string family; |
| 288 bool bold, italic; | 288 bool bold, italic; |
| 289 uint16 pixel_size; | 289 uint16 pixel_size; |
| 290 | 290 |
| 291 if (!iter.ReadString(&family) || | 291 if (!iter.ReadString(&family) || |
| 292 !iter.ReadBool(&bold) || | 292 !iter.ReadBool(&bold) || |
| 293 !iter.ReadBool(&italic) || | 293 !iter.ReadBool(&italic) || |
| 294 !iter.ReadUInt16(&pixel_size)) { | 294 !iter.ReadUInt16(&pixel_size)) { |
| 295 return; | 295 return; |
| 296 } | 296 } |
| 297 | 297 |
| 298 EnsureWebKitInitialized(); | 298 EnsureWebKitInitialized(); |
| 299 | 299 |
| 300 gfx::FontRenderParamsQuery query; | 300 gfx::FontRenderParamsQuery query; |
| 301 query.families.push_back(family); | 301 query.families.push_back(family); |
| 302 query.pixel_size = pixel_size; | 302 query.pixel_size = pixel_size; |
| 303 query.style = gfx::Font::NORMAL | | 303 query.style = gfx::Font::NORMAL | |
| 304 (bold ? gfx::Font::BOLD : 0) | (italic ? gfx::Font::ITALIC : 0); | 304 (bold ? gfx::Font::BOLD : 0) | (italic ? gfx::Font::ITALIC : 0); |
| 305 const gfx::FontRenderParams params = gfx::GetFontRenderParams(query, NULL); | 305 const gfx::FontRenderParams params = gfx::GetFontRenderParams(query, NULL); |
| 306 | 306 |
| 307 // 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 |
| 308 // Blink. | 308 // Blink. |
| 309 Pickle reply; | 309 base::Pickle reply; |
| 310 reply.WriteInt(params.use_bitmaps); | 310 reply.WriteInt(params.use_bitmaps); |
| 311 reply.WriteInt(params.autohinter); | 311 reply.WriteInt(params.autohinter); |
| 312 reply.WriteInt(params.hinting != gfx::FontRenderParams::HINTING_NONE); | 312 reply.WriteInt(params.hinting != gfx::FontRenderParams::HINTING_NONE); |
| 313 reply.WriteInt(ConvertHinting(params.hinting)); | 313 reply.WriteInt(ConvertHinting(params.hinting)); |
| 314 reply.WriteInt(params.antialiasing); | 314 reply.WriteInt(params.antialiasing); |
| 315 reply.WriteInt(ConvertSubpixelRendering(params.subpixel_rendering)); | 315 reply.WriteInt(ConvertSubpixelRendering(params.subpixel_rendering)); |
| 316 reply.WriteInt(params.subpixel_positioning); | 316 reply.WriteInt(params.subpixel_positioning); |
| 317 | 317 |
| 318 SendRendererReply(fds, reply, -1); | 318 SendRendererReply(fds, reply, -1); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void SandboxIPCHandler::HandleLocaltime( | 321 void SandboxIPCHandler::HandleLocaltime( |
| 322 int fd, | 322 int fd, |
| 323 PickleIterator iter, | 323 base::PickleIterator iter, |
| 324 const std::vector<base::ScopedFD*>& fds) { | 324 const std::vector<base::ScopedFD*>& fds) { |
| 325 // 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 |
| 326 | 326 |
| 327 std::string time_string; | 327 std::string time_string; |
| 328 if (!iter.ReadString(&time_string) || time_string.size() != sizeof(time_t)) | 328 if (!iter.ReadString(&time_string) || time_string.size() != sizeof(time_t)) |
| 329 return; | 329 return; |
| 330 | 330 |
| 331 time_t time; | 331 time_t time; |
| 332 memcpy(&time, time_string.data(), sizeof(time)); | 332 memcpy(&time, time_string.data(), sizeof(time)); |
| 333 // 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 |
| 334 // out. Since we are a single-threaded process, this is safe. | 334 // out. Since we are a single-threaded process, this is safe. |
| 335 const struct tm* expanded_time = localtime(&time); | 335 const struct tm* expanded_time = localtime(&time); |
| 336 | 336 |
| 337 std::string result_string; | 337 std::string result_string; |
| 338 const char* time_zone_string = ""; | 338 const char* time_zone_string = ""; |
| 339 if (expanded_time != NULL) { | 339 if (expanded_time != NULL) { |
| 340 result_string = std::string(reinterpret_cast<const char*>(expanded_time), | 340 result_string = std::string(reinterpret_cast<const char*>(expanded_time), |
| 341 sizeof(struct tm)); | 341 sizeof(struct tm)); |
| 342 time_zone_string = expanded_time->tm_zone; | 342 time_zone_string = expanded_time->tm_zone; |
| 343 } | 343 } |
| 344 | 344 |
| 345 Pickle reply; | 345 base::Pickle reply; |
| 346 reply.WriteString(result_string); | 346 reply.WriteString(result_string); |
| 347 reply.WriteString(time_zone_string); | 347 reply.WriteString(time_zone_string); |
| 348 SendRendererReply(fds, reply, -1); | 348 SendRendererReply(fds, reply, -1); |
| 349 } | 349 } |
| 350 | 350 |
| 351 void SandboxIPCHandler::HandleMakeSharedMemorySegment( | 351 void SandboxIPCHandler::HandleMakeSharedMemorySegment( |
| 352 int fd, | 352 int fd, |
| 353 PickleIterator iter, | 353 base::PickleIterator iter, |
| 354 const std::vector<base::ScopedFD*>& fds) { | 354 const std::vector<base::ScopedFD*>& fds) { |
| 355 base::SharedMemoryCreateOptions options; | 355 base::SharedMemoryCreateOptions options; |
| 356 uint32_t size; | 356 uint32_t size; |
| 357 if (!iter.ReadUInt32(&size)) | 357 if (!iter.ReadUInt32(&size)) |
| 358 return; | 358 return; |
| 359 options.size = size; | 359 options.size = size; |
| 360 if (!iter.ReadBool(&options.executable)) | 360 if (!iter.ReadBool(&options.executable)) |
| 361 return; | 361 return; |
| 362 int shm_fd = -1; | 362 int shm_fd = -1; |
| 363 base::SharedMemory shm; | 363 base::SharedMemory shm; |
| 364 if (shm.Create(options)) | 364 if (shm.Create(options)) |
| 365 shm_fd = shm.handle().fd; | 365 shm_fd = shm.handle().fd; |
| 366 Pickle reply; | 366 base::Pickle reply; |
| 367 SendRendererReply(fds, reply, shm_fd); | 367 SendRendererReply(fds, reply, shm_fd); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void SandboxIPCHandler::HandleMatchWithFallback( | 370 void SandboxIPCHandler::HandleMatchWithFallback( |
| 371 int fd, | 371 int fd, |
| 372 PickleIterator iter, | 372 base::PickleIterator iter, |
| 373 const std::vector<base::ScopedFD*>& fds) { | 373 const std::vector<base::ScopedFD*>& fds) { |
| 374 std::string face; | 374 std::string face; |
| 375 bool is_bold, is_italic; | 375 bool is_bold, is_italic; |
| 376 uint32 charset, fallback_family; | 376 uint32 charset, fallback_family; |
| 377 | 377 |
| 378 if (!iter.ReadString(&face) || face.empty() || | 378 if (!iter.ReadString(&face) || face.empty() || |
| 379 !iter.ReadBool(&is_bold) || | 379 !iter.ReadBool(&is_bold) || |
| 380 !iter.ReadBool(&is_italic) || | 380 !iter.ReadBool(&is_italic) || |
| 381 !iter.ReadUInt32(&charset) || | 381 !iter.ReadUInt32(&charset) || |
| 382 !iter.ReadUInt32(&fallback_family)) { | 382 !iter.ReadUInt32(&fallback_family)) { |
| 383 return; | 383 return; |
| 384 } | 384 } |
| 385 | 385 |
| 386 int font_fd = MatchFontFaceWithFallback( | 386 int font_fd = MatchFontFaceWithFallback( |
| 387 face, is_bold, is_italic, charset, fallback_family); | 387 face, is_bold, is_italic, charset, fallback_family); |
| 388 | 388 |
| 389 Pickle reply; | 389 base::Pickle reply; |
| 390 SendRendererReply(fds, reply, font_fd); | 390 SendRendererReply(fds, reply, font_fd); |
| 391 | 391 |
| 392 if (font_fd >= 0) { | 392 if (font_fd >= 0) { |
| 393 if (IGNORE_EINTR(close(font_fd)) < 0) | 393 if (IGNORE_EINTR(close(font_fd)) < 0) |
| 394 PLOG(ERROR) << "close"; | 394 PLOG(ERROR) << "close"; |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 | 397 |
| 398 void SandboxIPCHandler::SendRendererReply( | 398 void SandboxIPCHandler::SendRendererReply( |
| 399 const std::vector<base::ScopedFD*>& fds, | 399 const std::vector<base::ScopedFD*>& fds, |
| 400 const Pickle& reply, | 400 const base::Pickle& reply, |
| 401 int reply_fd) { | 401 int reply_fd) { |
| 402 struct msghdr msg; | 402 struct msghdr msg; |
| 403 memset(&msg, 0, sizeof(msg)); | 403 memset(&msg, 0, sizeof(msg)); |
| 404 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()}; | 404 struct iovec iov = {const_cast<void*>(reply.data()), reply.size()}; |
| 405 msg.msg_iov = &iov; | 405 msg.msg_iov = &iov; |
| 406 msg.msg_iovlen = 1; | 406 msg.msg_iovlen = 1; |
| 407 | 407 |
| 408 char control_buffer[CMSG_SPACE(sizeof(int))]; | 408 char control_buffer[CMSG_SPACE(sizeof(int))]; |
| 409 | 409 |
| 410 if (reply_fd != -1) { | 410 if (reply_fd != -1) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 } | 443 } |
| 444 | 444 |
| 445 void SandboxIPCHandler::EnsureWebKitInitialized() { | 445 void SandboxIPCHandler::EnsureWebKitInitialized() { |
| 446 if (blink_platform_impl_) | 446 if (blink_platform_impl_) |
| 447 return; | 447 return; |
| 448 blink_platform_impl_.reset(new BlinkPlatformImpl); | 448 blink_platform_impl_.reset(new BlinkPlatformImpl); |
| 449 blink::initializeWithoutV8(blink_platform_impl_.get()); | 449 blink::initializeWithoutV8(blink_platform_impl_.get()); |
| 450 } | 450 } |
| 451 | 451 |
| 452 } // namespace content | 452 } // namespace content |
| OLD | NEW |