Index: content/browser/renderer_host/render_sandbox_host_linux.cc |
=================================================================== |
--- content/browser/renderer_host/render_sandbox_host_linux.cc (revision 187285) |
+++ content/browser/renderer_host/render_sandbox_host_linux.cc (working copy) |
@@ -30,11 +30,10 @@ |
#include "content/common/font_config_ipc_linux.h" |
#include "content/common/sandbox_linux.h" |
#include "content/common/webkitplatformsupport_impl.h" |
-#include "skia/ext/skia_utils_base.h" |
+#include "skia/ext/SkFontHost_fontconfig_direct.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebFontInfo.h" |
#include "third_party/npapi/bindings/npapi_extensions.h" |
-#include "third_party/skia/include/ports/SkFontConfigInterface.h" |
#include "ui/gfx/font_render_params_linux.h" |
using WebKit::WebCString; |
@@ -60,7 +59,8 @@ |
SandboxIPCProcess(int lifeline_fd, int browser_socket, |
std::string sandbox_cmd) |
: lifeline_fd_(lifeline_fd), |
- browser_socket_(browser_socket) { |
+ browser_socket_(browser_socket), |
+ font_config_(new FontConfigDirect()) { |
if (!sandbox_cmd.empty()) { |
sandbox_cmd_.push_back(sandbox_cmd); |
sandbox_cmd_.push_back(base::kFindInodeSwitch); |
@@ -119,7 +119,7 @@ |
// bytes long (this is the largest message type). |
// 128 bytes padding are necessary so recvmsg() does not return MSG_TRUNC |
// error for a maximum length message. |
- char buf[FontConfigIPC::kMaxFontFamilyLength + 128]; |
+ char buf[FontConfigInterface::kMaxFontFamilyLength + 128]; |
const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); |
if (len == -1) { |
@@ -163,58 +163,64 @@ |
} |
} |
- int FindOrAddPath(const SkString& path) { |
- int count = paths_.count(); |
- for (int i = 0; i < count; ++i) { |
- if (path == *paths_[i]) |
- return i; |
+ void HandleFontMatchRequest(int fd, const Pickle& pickle, PickleIterator iter, |
+ std::vector<int>& fds) { |
+ bool filefaceid_valid; |
+ uint32_t filefaceid = 0; |
+ |
+ if (!pickle.ReadBool(&iter, &filefaceid_valid)) |
+ return; |
+ if (filefaceid_valid) { |
+ if (!pickle.ReadUInt32(&iter, &filefaceid)) |
+ return; |
} |
- *paths_.append() = new SkString(path); |
- return count; |
- } |
+ bool is_bold, is_italic; |
+ if (!pickle.ReadBool(&iter, &is_bold) || |
+ !pickle.ReadBool(&iter, &is_italic)) { |
+ return; |
+ } |
- void HandleFontMatchRequest(int fd, const Pickle& pickle, PickleIterator iter, |
- std::vector<int>& fds) { |
- uint32_t requested_style; |
+ uint32_t characters_bytes; |
+ if (!pickle.ReadUInt32(&iter, &characters_bytes)) |
+ return; |
+ const char* characters = NULL; |
+ if (characters_bytes > 0) { |
+ const uint32_t kMaxCharactersBytes = 1 << 10; |
+ if (characters_bytes % 2 != 0 || // We expect UTF-16. |
+ characters_bytes > kMaxCharactersBytes || |
+ !pickle.ReadBytes(&iter, &characters, characters_bytes)) |
+ return; |
+ } |
+ |
std::string family; |
- if (!pickle.ReadString(&iter, &family) || |
- !pickle.ReadUInt32(&iter, &requested_style)) |
+ if (!pickle.ReadString(&iter, &family)) |
return; |
- SkFontConfigInterface::FontIdentity result_identity; |
- SkString result_family; |
- SkTypeface::Style result_style; |
- SkFontConfigInterface* fc = |
- SkFontConfigInterface::GetSingletonDirectInterface(); |
- const bool r = fc->matchFamilyName( |
- family.c_str(), static_cast<SkTypeface::Style>(requested_style), |
- &result_identity, &result_family, &result_style); |
+ std::string result_family; |
+ unsigned result_filefaceid; |
+ const bool r = font_config_->Match( |
+ &result_family, &result_filefaceid, filefaceid_valid, filefaceid, |
+ family, characters, characters_bytes, &is_bold, &is_italic); |
Pickle reply; |
if (!r) { |
reply.WriteBool(false); |
} else { |
- // Stash away the returned path, so we can give it an ID (index) |
- // which will later be given to us in a request to open the file. |
- int index = FindOrAddPath(result_identity.fString); |
- result_identity.fID = static_cast<uint32_t>(index); |
- |
reply.WriteBool(true); |
- skia::WriteSkString(&reply, result_family); |
- skia::WriteSkFontIdentity(&reply, result_identity); |
- reply.WriteUInt32(result_style); |
+ reply.WriteUInt32(result_filefaceid); |
+ reply.WriteString(result_family); |
+ reply.WriteBool(is_bold); |
+ reply.WriteBool(is_italic); |
} |
SendRendererReply(fds, reply, -1); |
} |
void HandleFontOpenRequest(int fd, const Pickle& pickle, PickleIterator iter, |
std::vector<int>& fds) { |
- uint32_t index; |
- if (!pickle.ReadUInt32(&iter, &index)) |
+ uint32_t filefaceid; |
+ if (!pickle.ReadUInt32(&iter, &filefaceid)) |
return; |
- if (index >= static_cast<uint32_t>(paths_.count())) |
- return; |
- const int result_fd = open(paths_[index]->c_str(), O_RDONLY); |
+ const int result_fd = font_config_->Open(filefaceid); |
Pickle reply; |
if (result_fd == -1) { |
@@ -224,6 +230,9 @@ |
} |
SendRendererReply(fds, reply, result_fd); |
+ |
+ if (result_fd >= 0) |
+ close(result_fd); |
} |
void HandleGetFontFamilyForChars(int fd, const Pickle& pickle, |
@@ -650,13 +659,12 @@ |
const int lifeline_fd_; |
const int browser_socket_; |
+ scoped_ptr<FontConfigDirect> font_config_; |
std::vector<std::string> sandbox_cmd_; |
scoped_ptr<WebKitPlatformSupportImpl> webkit_platform_support_; |
- SkTDArray<SkString*> paths_; |
}; |
SandboxIPCProcess::~SandboxIPCProcess() { |
- paths_.deleteAll(); |
if (webkit_platform_support_.get()) |
WebKit::shutdown(); |
} |