diff options
Diffstat (limited to 'webkit/glue/plugins')
-rw-r--r-- | webkit/glue/plugins/pepper_font.cc | 100 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_font.h | 39 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.cc | 4 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_resource.h | 3 |
4 files changed, 146 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) |