OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "ppapi/proxy/flash_font_file_resource.h" |
| 6 |
| 7 #include <cstring> |
| 8 |
| 9 #include "ppapi/c/dev/ppb_font_dev.h" |
| 10 #include "ppapi/c/pp_errors.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 |
| 13 namespace ppapi { |
| 14 namespace proxy { |
| 15 |
| 16 FlashFontFileResource::FlashFontFileResource( |
| 17 Connection connection, |
| 18 PP_Instance instance, |
| 19 const PP_FontDescription_Dev* description, |
| 20 PP_PrivateFontCharset charset) |
| 21 : PluginResource(connection, instance), |
| 22 charset_(charset) { |
| 23 description_.SetFromPPFontDescription(*description); |
| 24 } |
| 25 |
| 26 FlashFontFileResource::~FlashFontFileResource() { |
| 27 } |
| 28 |
| 29 thunk::PPB_Flash_FontFile_API* |
| 30 FlashFontFileResource::AsPPB_Flash_FontFile_API() { |
| 31 return this; |
| 32 } |
| 33 |
| 34 PP_Bool FlashFontFileResource::GetFontTable(uint32_t table, |
| 35 void* output, |
| 36 uint32_t* output_length) { |
| 37 if (!output_length) |
| 38 return PP_FALSE; |
| 39 |
| 40 if (!sent_create_to_renderer()) { |
| 41 SendCreateToRenderer( |
| 42 PpapiHostMsg_FlashFontFile_Create(description_, charset_)); |
| 43 } |
| 44 |
| 45 std::string* contents = GetFontTable(table); |
| 46 if (!contents) { |
| 47 IPC::Message reply; |
| 48 int32_t result = CallRendererSync( |
| 49 PpapiHostMsg_FlashFontFile_GetFontTable(table), &reply); |
| 50 if (result != PP_OK) |
| 51 return PP_FALSE; |
| 52 |
| 53 PpapiPluginMsg_FlashFontFile_GetFontTableReply::Param param; |
| 54 if (!PpapiPluginMsg_FlashFontFile_GetFontTableReply::Read(&reply, ¶m)) |
| 55 return PP_FALSE; |
| 56 |
| 57 contents = AddFontTable(table, param.a); |
| 58 } |
| 59 |
| 60 // If we are going to copy the data into |output|, it must be big enough. |
| 61 if (output && *output_length < contents->size()) |
| 62 return PP_FALSE; |
| 63 |
| 64 *output_length = static_cast<uint32_t>(contents->size()); |
| 65 if (output) |
| 66 memcpy(output, contents->c_str(), *output_length); |
| 67 return PP_TRUE; |
| 68 } |
| 69 |
| 70 std::string* FlashFontFileResource::GetFontTable(uint32_t table) const { |
| 71 FontTableMap::const_iterator found = font_tables_.find(table); |
| 72 if (found == font_tables_.end()) |
| 73 return NULL; |
| 74 return found->second.get(); |
| 75 } |
| 76 |
| 77 std::string* FlashFontFileResource::AddFontTable(uint32_t table, |
| 78 const std::string& contents) { |
| 79 linked_ptr<std::string> heap_string(new std::string(contents)); |
| 80 font_tables_[table] = heap_string; |
| 81 return heap_string.get(); |
| 82 } |
| 83 |
| 84 } // namespace proxy |
| 85 } // namespace ppapi |
OLD | NEW |