summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 20:52:36 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 20:52:36 +0000
commit8ef13715896630c51f1926cfce8a67d7308c05b2 (patch)
tree82ca203f477243330bea49b1ce280518b01f2e86 /webkit/glue
parent2ffc6f7dd40198a8f8f4445bf25be5cf2ebdafe1 (diff)
downloadchromium_src-8ef13715896630c51f1926cfce8a67d7308c05b2.zip
chromium_src-8ef13715896630c51f1926cfce8a67d7308c05b2.tar.gz
chromium_src-8ef13715896630c51f1926cfce8a67d7308c05b2.tar.bz2
Pepper v2 Font API browser implementation.
Review URL: http://codereview.chromium.org/2956002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52009 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/plugins/pepper_font.cc100
-rw-r--r--webkit/glue/plugins/pepper_font.h39
-rw-r--r--webkit/glue/plugins/pepper_plugin_module.cc4
-rw-r--r--webkit/glue/plugins/pepper_resource.h3
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/glue/webkit_glue.h20
6 files changed, 168 insertions, 0 deletions
diff --git a/webkit/glue/plugins/pepper_font.cc b/webkit/glue/plugins/pepper_font.cc
new file mode 100644
index 0000000..8bc48a3
--- /dev/null
+++ b/webkit/glue/plugins/pepper_font.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "build/build_config.h"
+
+#include "webkit/glue/plugins/pepper_font.h"
+
+#if defined(OS_LINUX)
+#include <unistd.h>
+#endif
+
+#include "base/logging.h"
+#include "third_party/ppapi/c/ppb_font.h"
+#include "webkit/glue/plugins/pepper_plugin_module.h"
+#include "webkit/glue/webkit_glue.h"
+
+namespace pepper {
+
+namespace {
+
+PP_Resource MatchFontWithFallback(PP_Module module_id,
+ const PP_FontDescription* description) {
+#if defined(OS_LINUX)
+ PluginModule* module = PluginModule::FromPPModule(module_id);
+ if (!module)
+ return NULL;
+
+ int fd = webkit_glue::MatchFontWithFallback(description->face,
+ description->weight >= 700,
+ description->italic,
+ description->charset);
+ if (fd == -1)
+ return NULL;
+
+ scoped_refptr<Font> font(new Font(module, fd));
+ font->AddRef(); // AddRef for the caller.
+
+ return font->GetResource();
+#else
+ // For trusted pepper plugins, this is only needed in Linux since font loading
+ // on Windows and Mac works through the renderer sandbox.
+ return false;
+#endif
+}
+
+bool IsFont(PP_Resource resource) {
+ return !!Resource::GetAs<Font>(resource).get();
+}
+
+bool GetFontTable(PP_Resource font_id,
+ uint32_t table,
+ void* output,
+ uint32_t* output_length) {
+ scoped_refptr<Font> font(Resource::GetAs<Font>(font_id));
+ if (!font.get())
+ return false;
+
+ return font->GetFontTable(table, output, output_length);
+}
+
+const PPB_Font ppb_font = {
+ &MatchFontWithFallback,
+ &IsFont,
+ &GetFontTable,
+};
+
+} // namespace
+
+Font::Font(PluginModule* module, int fd)
+ : Resource(module),
+ fd_(fd) {
+}
+
+Font::~Font() {
+#if defined (OS_LINUX)
+ close(fd_);
+#endif
+}
+
+// static
+const PPB_Font* Font::GetInterface() {
+ return &ppb_font;
+}
+
+bool Font::GetFontTable(uint32_t table,
+ void* output,
+ uint32_t* output_length) {
+#if defined(OS_LINUX)
+ size_t temp_size = static_cast<size_t>(*output_length);
+ bool rv = webkit_glue::GetFontTable(
+ fd_, table, static_cast<uint8_t*>(output), &temp_size);
+ *output_length = static_cast<uint32_t>(temp_size);
+ return rv;
+#else
+ return false;
+#endif
+}
+
+} // namespace pepper
diff --git a/webkit/glue/plugins/pepper_font.h b/webkit/glue/plugins/pepper_font.h
new file mode 100644
index 0000000..ad1abba
--- /dev/null
+++ b/webkit/glue/plugins/pepper_font.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_FONT_H_
+#define WEBKIT_GLUE_PLUGINS_PEPPER_FONT_H_
+
+#include "webkit/glue/plugins/pepper_resource.h"
+
+typedef struct _ppb_Font PPB_Font;
+
+namespace pepper {
+
+class PluginInstance;
+
+class Font : public Resource {
+ public:
+ Font(PluginModule* module, int fd);
+ virtual ~Font();
+
+ // Returns a pointer to the interface implementing PPB_Font that is exposed to
+ // the plugin.
+ static const PPB_Font* GetInterface();
+
+ // Resource overrides.
+ Font* AsFont() { return this; }
+
+ // PPB_Font implementation.
+ bool GetFontTable(uint32_t table,
+ void* output,
+ uint32_t* output_length);
+
+ private:
+ int fd_;
+};
+
+} // namespace pepper
+
+#endif // WEBKIT_GLUE_PLUGINS_PEPPER_FONT_H_
diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc
index 7eecfb6..3dc3e04 100644
--- a/webkit/glue/plugins/pepper_plugin_module.cc
+++ b/webkit/glue/plugins/pepper_plugin_module.cc
@@ -19,6 +19,7 @@
#include "third_party/ppapi/c/ppb_file_io_trusted.h"
#include "third_party/ppapi/c/ppb_file_system.h"
#include "third_party/ppapi/c/ppb_image_data.h"
+#include "third_party/ppapi/c/ppb_font.h"
#include "third_party/ppapi/c/ppb_instance.h"
#include "third_party/ppapi/c/ppb_scrollbar.h"
#include "third_party/ppapi/c/ppb_testing.h"
@@ -38,6 +39,7 @@
#include "webkit/glue/plugins/pepper_file_io.h"
#include "webkit/glue/plugins/pepper_file_ref.h"
#include "webkit/glue/plugins/pepper_file_system.h"
+#include "webkit/glue/plugins/pepper_font.h"
#include "webkit/glue/plugins/pepper_image_data.h"
#include "webkit/glue/plugins/pepper_plugin_instance.h"
#include "webkit/glue/plugins/pepper_resource_tracker.h"
@@ -181,6 +183,8 @@ const void* GetInterface(const char* name) {
return Widget::GetInterface();
if (strcmp(name, PPB_SCROLLBAR_INTERFACE) == 0)
return Scrollbar::GetInterface();
+ if (strcmp(name, PPB_FONT_INTERFACE) == 0)
+ return Font::GetInterface();
// Only support the testing interface when the command line switch is
// specified. This allows us to prevent people from (ab)using this interface
diff --git a/webkit/glue/plugins/pepper_resource.h b/webkit/glue/plugins/pepper_resource.h
index d8cf837..4e347cb 100644
--- a/webkit/glue/plugins/pepper_resource.h
+++ b/webkit/glue/plugins/pepper_resource.h
@@ -18,6 +18,7 @@ class DirectoryReader;
class FileChooser;
class FileIO;
class FileRef;
+class Font;
class ImageData;
class PluginModule;
class Scrollbar;
@@ -57,6 +58,7 @@ class Resource : public base::RefCountedThreadSafe<Resource> {
virtual FileChooser* AsFileChooser() { return NULL; }
virtual FileIO* AsFileIO() { return NULL; }
virtual FileRef* AsFileRef() { return NULL; }
+ virtual Font* AsFont() { return NULL; }
virtual ImageData* AsImageData() { return NULL; }
virtual Scrollbar* AsScrollbar() { return NULL; }
virtual URLLoader* AsURLLoader() { return NULL; }
@@ -81,6 +83,7 @@ DEFINE_RESOURCE_CAST(DirectoryReader)
DEFINE_RESOURCE_CAST(FileChooser)
DEFINE_RESOURCE_CAST(FileIO)
DEFINE_RESOURCE_CAST(FileRef)
+DEFINE_RESOURCE_CAST(Font)
DEFINE_RESOURCE_CAST(ImageData)
DEFINE_RESOURCE_CAST(Scrollbar)
DEFINE_RESOURCE_CAST(URLLoader)
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 9bdebd7..75631bf 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -179,6 +179,8 @@
'plugins/pepper_file_ref.h',
'plugins/pepper_file_system.cc',
'plugins/pepper_file_system.h',
+ 'plugins/pepper_font.cc',
+ 'plugins/pepper_font.h',
'plugins/pepper_image_data.cc',
'plugins/pepper_image_data.h',
'plugins/pepper_plugin_delegate.h',
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index d24e1512..541836b 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -265,6 +265,26 @@ std::string GetProductVersion();
// Returns true if the embedder is running in single process mode.
bool IsSingleProcess();
+#if defined(OS_LINUX)
+// Return a read-only file descriptor to the font which best matches the given
+// properties or -1 on failure.
+// charset: specifies the language(s) that the font must cover. See
+// render_sandbox_host_linux.cc for more information.
+int MatchFontWithFallback(const std::string& face, bool bold,
+ bool italic, int charset);
+
+// GetFontTable loads a specified font table from an open SFNT file.
+// fd: a file descriptor to the SFNT file. The position doesn't matter.
+// table: the table in *big-endian* format, or 0 for the whole font file.
+// output: a buffer of size output_length that gets the data. can be 0, in
+// which case output_length will be set to the required size in bytes.
+// output_length: size of output, if it's not 0.
+//
+// returns: true on success.
+bool GetFontTable(int fd, uint32_t table, uint8_t* output,
+ size_t* output_length);
+#endif
+
// ---- END FUNCTIONS IMPLEMENTED BY EMBEDDER ---------------------------------