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

Unified Diff: content/browser/renderer_host/pepper/pepper_truetype_font_linux.cc

Issue 337203003: Move PPB_TrueTypeFont_Dev host from renderer to browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Check fd / HANDLE / FontRef for validity. Created 6 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
Index: content/browser/renderer_host/pepper/pepper_truetype_font_linux.cc
diff --git a/content/renderer/pepper/pepper_truetype_font_linux.cc b/content/browser/renderer_host/pepper/pepper_truetype_font_linux.cc
similarity index 70%
rename from content/renderer/pepper/pepper_truetype_font_linux.cc
rename to content/browser/renderer_host/pepper/pepper_truetype_font_linux.cc
index c54a5148a1a7a32b0fad447d38620702ac8f0dc7..c1a27fc94ea55a1b440daf531b9c63d5462829db 100644
--- a/content/renderer/pepper/pepper_truetype_font_linux.cc
+++ b/content/browser/renderer_host/pepper/pepper_truetype_font_linux.cc
@@ -3,14 +3,15 @@
// found in the LICENSE file.
#include "base/compiler_specific.h"
+#include "base/files/scoped_file.h"
#include "base/memory/scoped_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/sys_byteorder.h"
+#include "content/browser/renderer_host/font_utils_linux.h"
+#include "content/browser/renderer_host/pepper/pepper_truetype_font.h"
#include "content/public/common/child_process_sandbox_support_linux.h"
-#include "content/renderer/pepper/pepper_truetype_font.h"
#include "ppapi/c/dev/ppb_truetype_font_dev.h"
#include "ppapi/c/pp_errors.h"
-#include "ppapi/c/trusted/ppb_browser_font_trusted.h"
namespace content {
@@ -18,14 +19,11 @@ namespace {
class PepperTrueTypeFontLinux : public PepperTrueTypeFont {
public:
- explicit PepperTrueTypeFontLinux(
- const ppapi::proxy::SerializedTrueTypeFontDesc& desc);
- virtual ~PepperTrueTypeFontLinux() OVERRIDE;
+ PepperTrueTypeFontLinux();
- // PepperTrueTypeFont overrides.
- virtual bool IsValid() OVERRIDE;
- virtual int32_t Describe(ppapi::proxy::SerializedTrueTypeFontDesc* desc)
- OVERRIDE;
+ // PepperTrueTypeFont implementation.
+ virtual int32_t Initialize(
+ ppapi::proxy::SerializedTrueTypeFontDesc* desc) OVERRIDE;
virtual int32_t GetTableTags(std::vector<uint32_t>* tags) OVERRIDE;
virtual int32_t GetTable(uint32_t table_tag,
int32_t offset,
@@ -33,62 +31,61 @@ class PepperTrueTypeFontLinux : public PepperTrueTypeFont {
std::string* data) OVERRIDE;
private:
- // Save creation parameters here and use these to implement Describe.
- // TODO(bbudge) Modify content API to return results of font matching and
- // fallback.
- ppapi::proxy::SerializedTrueTypeFontDesc desc_;
- int fd_;
+ virtual ~PepperTrueTypeFontLinux() OVERRIDE;
+
+ base::ScopedFD fd_;
DISALLOW_COPY_AND_ASSIGN(PepperTrueTypeFontLinux);
};
-PepperTrueTypeFontLinux::PepperTrueTypeFontLinux(
- const ppapi::proxy::SerializedTrueTypeFontDesc& desc)
- : desc_(desc) {
+PepperTrueTypeFontLinux::PepperTrueTypeFontLinux() {
+}
+
+PepperTrueTypeFontLinux::~PepperTrueTypeFontLinux() {
+}
+
+int32_t PepperTrueTypeFontLinux::Initialize(
+ ppapi::proxy::SerializedTrueTypeFontDesc* desc) {
// If no face is provided, convert family to the platform defaults. These
// names should be mapped by FontConfig to an appropriate default font.
- if (desc_.family.empty()) {
- switch (desc_.generic_family) {
+ if (desc->family.empty()) {
+ switch (desc->generic_family) {
case PP_TRUETYPEFONTFAMILY_SERIF:
- desc_.family = "serif";
+ desc->family = "serif";
break;
case PP_TRUETYPEFONTFAMILY_SANSSERIF:
- desc_.family = "sans-serif";
+ desc->family = "sans-serif";
break;
case PP_TRUETYPEFONTFAMILY_CURSIVE:
- desc_.family = "cursive";
+ desc->family = "cursive";
break;
case PP_TRUETYPEFONTFAMILY_FANTASY:
- desc_.family = "fantasy";
+ desc->family = "fantasy";
break;
case PP_TRUETYPEFONTFAMILY_MONOSPACE:
- desc_.family = "monospace";
+ desc->family = "monospace";
break;
}
}
- fd_ = MatchFontWithFallback(desc_.family.c_str(),
- desc_.weight >= PP_TRUETYPEFONTWEIGHT_BOLD,
- desc_.style & PP_TRUETYPEFONTSTYLE_ITALIC,
- desc_.charset,
- PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT);
-}
-
-PepperTrueTypeFontLinux::~PepperTrueTypeFontLinux() {}
-
-bool PepperTrueTypeFontLinux::IsValid() { return fd_ != -1; }
-
-int32_t PepperTrueTypeFontLinux::Describe(
- ppapi::proxy::SerializedTrueTypeFontDesc* desc) {
- *desc = desc_;
- return PP_OK;
+ fd_.reset(
+ MatchFontFaceWithFallback(desc->family,
+ desc->weight >= PP_TRUETYPEFONTWEIGHT_BOLD,
+ desc->style & PP_TRUETYPEFONTSTYLE_ITALIC,
+ desc->charset,
+ PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT));
+ // TODO(bbudge) Modify content API to return results of font matching and
+ // fallback, so we can update |desc| to reflect that.
+ return fd_.is_valid() ? PP_OK : PP_ERROR_FAILED;
}
int32_t PepperTrueTypeFontLinux::GetTableTags(std::vector<uint32_t>* tags) {
+ if (!fd_.is_valid())
+ return PP_ERROR_FAILED;
// Get the 2 byte numTables field at an offset of 4 in the font.
uint8_t num_tables_buf[2];
size_t output_length = sizeof(num_tables_buf);
- if (!GetFontTable(fd_,
+ if (!GetFontTable(fd_.get(),
0 /* tag */,
4 /* offset */,
reinterpret_cast<uint8_t*>(&num_tables_buf),
@@ -104,7 +101,7 @@ int32_t PepperTrueTypeFontLinux::GetTableTags(std::vector<uint32_t>* tags) {
output_length = num_tables * kTableEntrySize;
scoped_ptr<uint8_t[]> table_entries(new uint8_t[output_length]);
// Get the table directory entries, which follow the font header.
- if (!GetFontTable(fd_,
+ if (!GetFontTable(fd_.get(),
0 /* tag */,
kFontHeaderSize /* offset */,
table_entries.get(),
@@ -129,16 +126,18 @@ int32_t PepperTrueTypeFontLinux::GetTable(uint32_t table_tag,
int32_t offset,
int32_t max_data_length,
std::string* data) {
+ if (!fd_.is_valid())
+ return PP_ERROR_FAILED;
// Get the size of the font data first.
size_t table_size = 0;
// Tags are byte swapped on Linux.
table_tag = base::ByteSwap(table_tag);
- if (!GetFontTable(fd_, table_tag, offset, NULL, &table_size))
+ if (!GetFontTable(fd_.get(), table_tag, offset, NULL, &table_size))
return PP_ERROR_FAILED;
// Only retrieve as much as the caller requested.
table_size = std::min(table_size, static_cast<size_t>(max_data_length));
data->resize(table_size);
- if (!GetFontTable(fd_,
+ if (!GetFontTable(fd_.get(),
table_tag,
offset,
reinterpret_cast<uint8_t*>(&(*data)[0]),
@@ -151,9 +150,8 @@ int32_t PepperTrueTypeFontLinux::GetTable(uint32_t table_tag,
} // namespace
// static
-PepperTrueTypeFont* PepperTrueTypeFont::Create(
- const ppapi::proxy::SerializedTrueTypeFontDesc& desc) {
- return new PepperTrueTypeFontLinux(desc);
+PepperTrueTypeFont* PepperTrueTypeFont::Create() {
+ return new PepperTrueTypeFontLinux();
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698