Skip to content

Commit

Permalink
Revert 187283
Browse files Browse the repository at this point in the history
memcheck reported errors which need to be investigated

> Call version of SkFontHost_fontconfig in Skia (cloned from here).
> Retool the direct/remove plumbing to use SkFontConfigInterface.
> 
> This change allows Skia to interate on the details of SkFontHost w/o having
> to synchromize with chrome on each change. It also means Skia's internal testing
> can exercise exactly the same config that Chrome does.
> Review URL: https://codereview.chromium.org/12391070

TBR=reed@google.com
Review URL: https://codereview.chromium.org/12771003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187287 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
reed@google.com committed Mar 11, 2013
1 parent a5fda2a commit c7f723c
Show file tree
Hide file tree
Showing 12 changed files with 1,151 additions and 180 deletions.
88 changes: 48 additions & 40 deletions content/browser/renderer_host/render_sandbox_host_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,7 +59,8 @@ class SandboxIPCProcess {
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);
Expand Down Expand Up @@ -119,7 +119,7 @@ class SandboxIPCProcess {
// 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) {
Expand Down Expand Up @@ -163,58 +163,64 @@ class SandboxIPCProcess {
}
}

int FindOrAddPath(const SkString& path) {
int count = paths_.count();
for (int i = 0; i < count; ++i) {
if (path == *paths_[i])
return i;
}
*paths_.append() = new SkString(path);
return count;
}

void HandleFontMatchRequest(int fd, const Pickle& pickle, PickleIterator iter,
std::vector<int>& fds) {
uint32_t requested_style;
bool filefaceid_valid;
uint32_t filefaceid = 0;

if (!pickle.ReadBool(&iter, &filefaceid_valid))
return;
if (filefaceid_valid) {
if (!pickle.ReadUInt32(&iter, &filefaceid))
return;
}
bool is_bold, is_italic;
if (!pickle.ReadBool(&iter, &is_bold) ||
!pickle.ReadBool(&iter, &is_italic)) {
return;
}

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) {
Expand All @@ -224,6 +230,9 @@ class SandboxIPCProcess {
}

SendRendererReply(fds, reply, result_fd);

if (result_fd >= 0)
close(result_fd);
}

void HandleGetFontFamilyForChars(int fd, const Pickle& pickle,
Expand Down Expand Up @@ -650,13 +659,12 @@ class SandboxIPCProcess {

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();
}
Expand Down
70 changes: 41 additions & 29 deletions content/common/font_config_ipc_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

#include "base/pickle.h"
#include "base/posix/unix_domain_socket_linux.h"
#include "skia/ext/skia_utils_base.h"
#include "third_party/skia/include/core/SkStream.h"

namespace content {

Expand All @@ -25,21 +23,31 @@ FontConfigIPC::~FontConfigIPC() {
close(fd_);
}

bool FontConfigIPC::matchFamilyName(const char familyName[],
SkTypeface::Style requestedStyle,
FontIdentity* outFontIdentity,
SkString* outFamilyName,
SkTypeface::Style* outStyle) {
size_t familyNameLen = familyName ? strlen(familyName) : 0;
if (familyNameLen > kMaxFontFamilyLength)
bool FontConfigIPC::Match(std::string* result_family,
unsigned* result_filefaceid,
bool filefaceid_valid, unsigned filefaceid,
const std::string& family,
const void* characters, size_t characters_bytes,
bool* is_bold, bool* is_italic) {
if (family.length() > kMaxFontFamilyLength)
return false;

Pickle request;
request.WriteInt(METHOD_MATCH);
request.WriteData(familyName, familyNameLen);
request.WriteUInt32(requestedStyle);
request.WriteBool(filefaceid_valid);
if (filefaceid_valid)
request.WriteUInt32(filefaceid);

uint8_t reply_buf[2048];
request.WriteBool(is_bold && *is_bold);
request.WriteBool(is_bold && *is_italic);

request.WriteUInt32(characters_bytes);
if (characters_bytes)
request.WriteBytes(characters, characters_bytes);

request.WriteString(family);

uint8_t reply_buf[512];
const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
sizeof(reply_buf), NULL,
request);
Expand All @@ -54,29 +62,33 @@ bool FontConfigIPC::matchFamilyName(const char familyName[],
if (!result)
return false;

SkString reply_family;
FontIdentity reply_identity;
uint32_t reply_style;
if (!skia::ReadSkString(reply, &iter, &reply_family) ||
!skia::ReadSkFontIdentity(reply, &iter, &reply_identity) ||
!reply.ReadUInt32(&iter, &reply_style)) {
uint32_t reply_filefaceid;
std::string reply_family;
bool resulting_bold, resulting_italic;
if (!reply.ReadUInt32(&iter, &reply_filefaceid) ||
!reply.ReadString(&iter, &reply_family) ||
!reply.ReadBool(&iter, &resulting_bold) ||
!reply.ReadBool(&iter, &resulting_italic)) {
return false;
}

if (outFontIdentity)
*outFontIdentity = reply_identity;
if (outFamilyName)
*outFamilyName = reply_family;
if (outStyle)
*outStyle = static_cast<SkTypeface::Style>(reply_style);
if (result_filefaceid)
*result_filefaceid = reply_filefaceid;
if (result_family)
*result_family = reply_family;

if (is_bold)
*is_bold = resulting_bold;
if (is_italic)
*is_italic = resulting_italic;

return true;
}

SkStream* FontConfigIPC::openStream(const FontIdentity& identity) {
int FontConfigIPC::Open(unsigned filefaceid) {
Pickle request;
request.WriteInt(METHOD_OPEN);
request.WriteUInt32(identity.fID);
request.WriteUInt32(filefaceid);

int result_fd = -1;
uint8_t reply_buf[256];
Expand All @@ -85,7 +97,7 @@ SkStream* FontConfigIPC::openStream(const FontIdentity& identity) {
&result_fd, request);

if (r == -1)
return NULL;
return -1;

Pickle reply(reinterpret_cast<char*>(reply_buf), r);
bool result;
Expand All @@ -94,10 +106,10 @@ SkStream* FontConfigIPC::openStream(const FontIdentity& identity) {
!result) {
if (result_fd)
close(result_fd);
return NULL;
return -1;
}

return new SkFDStream(result_fd, true);
return result_fd;
}

} // namespace content
25 changes: 12 additions & 13 deletions content/common/font_config_ipc_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,35 @@
#define CONTENT_COMMON_FONT_CONFIG_IPC_LINUX_H_

#include "base/compiler_specific.h"
#include "third_party/skia/include/ports/SkFontConfigInterface.h"
#include "skia/ext/SkFontHost_fontconfig_impl.h"

#include <string>

namespace content {

// FontConfig implementation for Skia that proxies out of process to get out
// of the sandbox. See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC
class FontConfigIPC : public SkFontConfigInterface {
class FontConfigIPC : public FontConfigInterface {
public:
explicit FontConfigIPC(int fd);
virtual ~FontConfigIPC();

virtual bool matchFamilyName(const char familyName[],
SkTypeface::Style requested,
FontIdentity* outFontIdentifier,
SkString* outFamilyName,
SkTypeface::Style* outStyle) OVERRIDE;

virtual SkStream* openStream(const FontIdentity&) OVERRIDE;
// FontConfigInterface implementation.
virtual bool Match(std::string* result_family,
unsigned* result_filefaceid,
bool filefaceid_valid,
unsigned filefaceid,
const std::string& family,
const void* characters,
size_t characters_bytes,
bool* is_bold, bool* is_italic) OVERRIDE;
virtual int Open(unsigned filefaceid) OVERRIDE;

enum Method {
METHOD_MATCH = 0,
METHOD_OPEN = 1,
};

enum {
kMaxFontFamilyLength = 2048
};

private:
const int fd_;
};
Expand Down
10 changes: 5 additions & 5 deletions content/zygote/zygote_main_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include "crypto/nss_util.h"
#include "sandbox/linux/services/libc_urandom_override.h"
#include "sandbox/linux/suid/client/setuid_sandbox_client.h"
#include "skia/ext/SkFontHost_fontconfig_control.h"
#include "third_party/icu/public/i18n/unicode/timezone.h"
#include "third_party/skia/include/ports/SkFontConfigInterface.h"

#if defined(OS_LINUX)
#include <sys/epoll.h>
Expand Down Expand Up @@ -368,8 +368,8 @@ static bool EnterSandbox(sandbox::SetuidSandboxClient* setuid_sandbox,
return false;

PreSandboxInit();
SkFontConfigInterface::SetGlobal(
new FontConfigIPC(Zygote::kMagicSandboxIPCDescriptor))->unref();
SkiaFontConfigSetImplementation(
new FontConfigIPC(Zygote::kMagicSandboxIPCDescriptor));

if (setuid_sandbox->IsSuidSandboxChild()) {
// Use the SUID sandbox. This still allows the seccomp sandbox to
Expand Down Expand Up @@ -438,8 +438,8 @@ static bool EnterSandbox(sandbox::SetuidSandboxClient* setuid_sandbox,
return false;

PreSandboxInit();
SkFontConfigInterface::SetGlobal(
new FontConfigIPC(Zygote::kMagicSandboxIPCDescriptor)))->unref();
SkiaFontConfigSetImplementation(
new FontConfigIPC(Zygote::kMagicSandboxIPCDescriptor));
return true;
}

Expand Down
Loading

0 comments on commit c7f723c

Please sign in to comment.