Index: chrome/renderer/renderer_sandbox_support_linux.cc |
diff --git a/chrome/renderer/renderer_sandbox_support_linux.cc b/chrome/renderer/renderer_sandbox_support_linux.cc |
index f1d03e3ac4d5c8c4faba23ca464211eb4a30d605..e06232dcf0b0131a762217475d6651471611e5ad 100644 |
--- a/chrome/renderer/renderer_sandbox_support_linux.cc |
+++ b/chrome/renderer/renderer_sandbox_support_linux.cc |
@@ -4,8 +4,10 @@ |
#include "chrome/renderer/renderer_sandbox_support_linux.h" |
+#include "base/eintr_wrapper.h" |
#include "base/global_descriptors_posix.h" |
#include "base/pickle.h" |
+#include "base/scoped_ptr.h" |
#include "base/unix_domain_socket_posix.h" |
#include "chrome/common/chrome_descriptors.h" |
#include "chrome/common/sandbox_methods_linux.h" |
@@ -87,4 +89,72 @@ int MakeSharedMemorySegmentViaIPC(size_t length) { |
return result_fd; |
} |
+int MatchFontWithFallback(const std::string& family, bool bold, |
+ bool italic, uint32_t microsoft_charset) { |
+ Pickle request; |
+ request.WriteInt(LinuxSandbox::METHOD_MATCH_WITH_FALLBACK); |
+ request.WriteString(family); |
+ request.WriteBool(bold); |
+ request.WriteBool(italic); |
+ request.WriteUInt32(microsoft_charset); |
+ uint8_t reply_buf[64]; |
+ int fd = -1; |
+ base::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf), |
+ &fd, request); |
+ return fd; |
+} |
+ |
+bool GetFontTable(uint8_t** output, size_t* output_length, |
+ int fd, uint32_t table) { |
+ unsigned num_tables; |
+ uint8_t num_tables_buf[2]; |
+ |
+ ssize_t n = HANDLE_EINTR(pread(fd, &num_tables_buf, sizeof(num_tables_buf), |
+ 4 /* skip the font type */)); |
+ if (n != sizeof(num_tables_buf)) |
+ return false; |
+ |
+ num_tables = static_cast<unsigned>(num_tables_buf[0]) << 8 | |
+ num_tables_buf[1]; |
+ |
+ // The size in bytes of an entry in the table directory. |
+ static const unsigned kTableEntrySize = 16; |
+ scoped_array<uint8_t> table_entries( |
+ new uint8_t[num_tables * kTableEntrySize]); |
+ n = HANDLE_EINTR(pread(fd, table_entries.get(), num_tables * kTableEntrySize, |
+ 12 /* skip the SFNT header */)); |
+ if (n != num_tables * kTableEntrySize) |
+ return false; |
+ |
+ size_t offset; |
+ size_t length = 0; |
+ for (unsigned i = 0; i < num_tables; i++) { |
+ const uint8_t* entry = table_entries.get() + i * kTableEntrySize; |
+ if (memcmp(entry, &table, sizeof(table)) == 0) { |
+ offset = static_cast<size_t>(entry[8]) << 24 | |
+ static_cast<size_t>(entry[9]) << 16 | |
+ static_cast<size_t>(entry[10]) << 8 | |
+ static_cast<size_t>(entry[11]); |
+ length = static_cast<size_t>(entry[12]) << 24 | |
+ static_cast<size_t>(entry[13]) << 16 | |
+ static_cast<size_t>(entry[14]) << 8 | |
+ static_cast<size_t>(entry[15]); |
+ |
+ break; |
+ } |
+ } |
+ |
+ if (!length) |
+ return false; |
+ |
+ *output = new uint8_t[length]; |
+ n = HANDLE_EINTR(pread(fd, *output, length, offset)); |
+ if (n != static_cast<ssize_t>(length)) { |
+ delete[] *output; |
+ return false; |
+ } |
+ *output_length = length; |
+ return true; |
+} |
+ |
} // namespace render_sandbox_support |