| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "webkit/glue/plugins/pepper_private.h" | 7 #include "webkit/glue/plugins/pepper_private.h" |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "grit/webkit_strings.h" | 10 #include "grit/webkit_strings.h" |
| 11 #include "webkit/glue/webkit_glue.h" | 11 #include "webkit/glue/webkit_glue.h" |
| 12 #include "webkit/glue/plugins/pepper_plugin_module.h" | |
| 13 #include "webkit/glue/plugins/pepper_var.h" | 12 #include "webkit/glue/plugins/pepper_var.h" |
| 14 #include "webkit/glue/plugins/ppb_private.h" | 13 #include "webkit/glue/plugins/ppb_private.h" |
| 15 | 14 |
| 16 namespace pepper { | 15 namespace pepper { |
| 17 | 16 |
| 18 #if defined(OS_LINUX) | |
| 19 class PrivateFontFile : public Resource { | |
| 20 public: | |
| 21 PrivateFontFile(PluginModule* module, int fd) : Resource(module), fd_(fd) {} | |
| 22 virtual ~PrivateFontFile() {} | |
| 23 | |
| 24 // Resource overrides. | |
| 25 PrivateFontFile* AsPrivateFontFile() { return this; } | |
| 26 | |
| 27 bool GetFontTable(uint32_t table, | |
| 28 void* output, | |
| 29 uint32_t* output_length); | |
| 30 | |
| 31 private: | |
| 32 int fd_; | |
| 33 }; | |
| 34 #endif | |
| 35 | |
| 36 namespace { | 17 namespace { |
| 37 | 18 |
| 38 PP_Var GetLocalizedString(PP_ResourceString string_id) { | 19 PP_Var GetLocalizedString(PP_ResourceString string_id) { |
| 39 std::string rv; | 20 std::string rv; |
| 40 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) | 21 if (string_id == PP_RESOURCESTRING_PDFGETPASSWORD) |
| 41 rv = UTF16ToUTF8(webkit_glue::GetLocalizedString(IDS_PDF_NEED_PASSWORD)); | 22 rv = UTF16ToUTF8(webkit_glue::GetLocalizedString(IDS_PDF_NEED_PASSWORD)); |
| 42 | 23 |
| 43 return StringToPPVar(rv); | 24 return StringToPPVar(rv); |
| 44 } | 25 } |
| 45 | 26 |
| 46 PP_Resource GetFontFileWithFallback( | |
| 47 PP_Module module_id, | |
| 48 const PP_PrivateFontFileDescription* description) { | |
| 49 #if defined(OS_LINUX) | |
| 50 PluginModule* module = PluginModule::FromPPModule(module_id); | |
| 51 if (!module) | |
| 52 return NULL; | |
| 53 | |
| 54 int fd = webkit_glue::MatchFontWithFallback(description->face, | |
| 55 description->weight >= 700, | |
| 56 description->italic, | |
| 57 description->charset); | |
| 58 if (fd == -1) | |
| 59 return NULL; | |
| 60 | |
| 61 scoped_refptr<PrivateFontFile> font(new PrivateFontFile(module, fd)); | |
| 62 | |
| 63 return font->GetReference(); | |
| 64 #else | |
| 65 // For trusted pepper plugins, this is only needed in Linux since font loading | |
| 66 // on Windows and Mac works through the renderer sandbox. | |
| 67 return false; | |
| 68 #endif | |
| 69 } | |
| 70 | |
| 71 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | |
| 72 uint32_t table, | |
| 73 void* output, | |
| 74 uint32_t* output_length) { | |
| 75 #if defined(OS_LINUX) | |
| 76 scoped_refptr<PrivateFontFile> font( | |
| 77 Resource::GetAs<PrivateFontFile>(font_file)); | |
| 78 if (!font.get()) | |
| 79 return false; | |
| 80 return font->GetFontTable(table, output, output_length); | |
| 81 #else | |
| 82 return false; | |
| 83 #endif | |
| 84 } | |
| 85 | |
| 86 const PPB_Private ppb_private = { | 27 const PPB_Private ppb_private = { |
| 87 &GetLocalizedString, | 28 &GetLocalizedString, |
| 88 &GetFontFileWithFallback, | |
| 89 &GetFontTableForPrivateFontFile, | |
| 90 }; | 29 }; |
| 91 | 30 |
| 92 } // namespace | 31 } // namespace |
| 93 | 32 |
| 94 // static | 33 // static |
| 95 const PPB_Private* Private::GetInterface() { | 34 const PPB_Private* Private::GetInterface() { |
| 96 return &ppb_private; | 35 return &ppb_private; |
| 97 } | 36 } |
| 98 | 37 |
| 99 #if defined(OS_LINUX) | |
| 100 bool PrivateFontFile::GetFontTable(uint32_t table, | |
| 101 void* output, | |
| 102 uint32_t* output_length) { | |
| 103 size_t temp_size = static_cast<size_t>(*output_length); | |
| 104 bool rv = webkit_glue::GetFontTable( | |
| 105 fd_, table, static_cast<uint8_t*>(output), &temp_size); | |
| 106 *output_length = static_cast<uint32_t>(temp_size); | |
| 107 return rv; | |
| 108 } | |
| 109 #endif | |
| 110 | |
| 111 } // namespace pepper | 38 } // namespace pepper |
| OLD | NEW |