OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "build/build_config.h" |
| 6 |
| 7 #include "webkit/glue/plugins/pepper_font.h" |
| 8 |
| 9 #if defined(OS_LINUX) |
| 10 #include <unistd.h> |
| 11 #endif |
| 12 |
| 13 #include "base/logging.h" |
| 14 #include "third_party/ppapi/c/ppb_font.h" |
| 15 #include "webkit/glue/plugins/pepper_plugin_module.h" |
| 16 #include "webkit/glue/webkit_glue.h" |
| 17 |
| 18 namespace pepper { |
| 19 |
| 20 namespace { |
| 21 |
| 22 PP_Resource MatchFontWithFallback(PP_Module module_id, |
| 23 const PP_FontDescription* description) { |
| 24 #if defined(OS_LINUX) |
| 25 PluginModule* module = PluginModule::FromPPModule(module_id); |
| 26 if (!module) |
| 27 return NULL; |
| 28 |
| 29 int fd = webkit_glue::MatchFontWithFallback(description->face, |
| 30 description->weight >= 700, |
| 31 description->italic, |
| 32 description->charset); |
| 33 if (fd == -1) |
| 34 return NULL; |
| 35 |
| 36 scoped_refptr<Font> font(new Font(module, fd)); |
| 37 font->AddRef(); // AddRef for the caller. |
| 38 |
| 39 return font->GetResource(); |
| 40 #else |
| 41 // For trusted pepper plugins, this is only needed in Linux since font loading |
| 42 // on Windows and Mac works through the renderer sandbox. |
| 43 return false; |
| 44 #endif |
| 45 } |
| 46 |
| 47 bool IsFont(PP_Resource resource) { |
| 48 return !!Resource::GetAs<Font>(resource).get(); |
| 49 } |
| 50 |
| 51 bool GetFontTable(PP_Resource font_id, |
| 52 uint32_t table, |
| 53 void* output, |
| 54 uint32_t* output_length) { |
| 55 scoped_refptr<Font> font(Resource::GetAs<Font>(font_id)); |
| 56 if (!font.get()) |
| 57 return false; |
| 58 |
| 59 return font->GetFontTable(table, output, output_length); |
| 60 } |
| 61 |
| 62 const PPB_Font ppb_font = { |
| 63 &MatchFontWithFallback, |
| 64 &IsFont, |
| 65 &GetFontTable, |
| 66 }; |
| 67 |
| 68 } // namespace |
| 69 |
| 70 Font::Font(PluginModule* module, int fd) |
| 71 : Resource(module), |
| 72 fd_(fd) { |
| 73 } |
| 74 |
| 75 Font::~Font() { |
| 76 #if defined (OS_LINUX) |
| 77 close(fd_); |
| 78 #endif |
| 79 } |
| 80 |
| 81 // static |
| 82 const PPB_Font* Font::GetInterface() { |
| 83 return &ppb_font; |
| 84 } |
| 85 |
| 86 bool Font::GetFontTable(uint32_t table, |
| 87 void* output, |
| 88 uint32_t* output_length) { |
| 89 #if defined(OS_LINUX) |
| 90 size_t temp_size = static_cast<size_t>(*output_length); |
| 91 bool rv = webkit_glue::GetFontTable( |
| 92 fd_, table, static_cast<uint8_t*>(output), &temp_size); |
| 93 *output_length = static_cast<uint32_t>(temp_size); |
| 94 return rv; |
| 95 #else |
| 96 return false; |
| 97 #endif |
| 98 } |
| 99 |
| 100 } // namespace pepper |
OLD | NEW |