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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/renderer_sandbox_support_linux.cc
===================================================================
--- chrome/renderer/renderer_sandbox_support_linux.cc (revision 49461)
+++ chrome/renderer/renderer_sandbox_support_linux.cc (working copy)
@@ -4,8 +4,12 @@
#include "chrome/renderer/renderer_sandbox_support_linux.h"
+#include <sys/stat.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"
@@ -18,7 +22,8 @@
namespace renderer_sandbox_support {
-std::string getFontFamilyForCharacters(const uint16_t* utf16, size_t num_utf16) {
+std::string getFontFamilyForCharacters(const uint16_t* utf16,
+ size_t num_utf16) {
Pickle request;
request.WriteInt(LinuxSandbox::METHOD_GET_FONT_FAMILY_FOR_CHARS);
request.WriteInt(num_utf16);
@@ -87,4 +92,96 @@
return result_fd;
}
+int MatchFontWithFallback(const std::string& face, bool bold,
+ bool italic, NPCharset charset) {
+ Pickle request;
+ request.WriteInt(LinuxSandbox::METHOD_MATCH_WITH_FALLBACK);
+ request.WriteString(face);
+ request.WriteBool(bold);
+ request.WriteBool(italic);
+ request.WriteUInt32(charset);
+ uint8_t reply_buf[64];
+ int fd = -1;
+ base::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf),
+ &fd, request);
+ return fd;
+}
+
+bool GetFontTable(int fd, uint32_t table, uint8_t* output,
+ size_t* output_length) {
+ if (table == 0) {
+ struct stat st;
+ if (fstat(fd, &st) < 0)
+ return false;
+ size_t length = st.st_size;
+ if (!output) {
+ *output_length = length;
+ return true;
+ }
+ if (*output_length < length)
+ return false;
+ *output_length = length;
+ ssize_t n = HANDLE_EINTR(pread(fd, output, length, 0));
+ if (n != static_cast<ssize_t>(length))
+ return false;
+ return true;
+ }
+
+ 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 != static_cast<ssize_t>(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;
+
+ if (!output) {
+ *output_length = length;
+ return true;
+ }
+
+ if (*output_length < length)
+ return false;
+
+ *output_length = length;
+ n = HANDLE_EINTR(pread(fd, output, length, offset));
+ if (n != static_cast<ssize_t>(length))
+ return false;
+
+ return true;
+}
+
} // namespace render_sandbox_support
« 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