| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/proxy/flash_font_file_resource.h" | 5 #include "ppapi/proxy/flash_font_file_resource.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "ppapi/c/dev/ppb_font_dev.h" | 9 #include "ppapi/c/dev/ppb_font_dev.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 if (!output_length) | 37 if (!output_length) |
| 38 return PP_FALSE; | 38 return PP_FALSE; |
| 39 | 39 |
| 40 if (!sent_create_to_renderer()) { | 40 if (!sent_create_to_renderer()) { |
| 41 SendCreateToRenderer( | 41 SendCreateToRenderer( |
| 42 PpapiHostMsg_FlashFontFile_Create(description_, charset_)); | 42 PpapiHostMsg_FlashFontFile_Create(description_, charset_)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 std::string* contents = GetFontTable(table); | 45 std::string* contents = GetFontTable(table); |
| 46 if (!contents) { | 46 if (!contents) { |
| 47 IPC::Message reply; | 47 std::string out_contents; |
| 48 int32_t result = CallRendererSync( | 48 int32_t result = SyncCall<PpapiPluginMsg_FlashFontFile_GetFontTableReply>( |
| 49 PpapiHostMsg_FlashFontFile_GetFontTable(table), &reply); | 49 RENDERER, PpapiHostMsg_FlashFontFile_GetFontTable(table), |
| 50 &out_contents); |
| 50 if (result != PP_OK) | 51 if (result != PP_OK) |
| 51 return PP_FALSE; | 52 return PP_FALSE; |
| 52 | 53 |
| 53 PpapiPluginMsg_FlashFontFile_GetFontTableReply::Param param; | 54 contents = AddFontTable(table, out_contents); |
| 54 if (!PpapiPluginMsg_FlashFontFile_GetFontTableReply::Read(&reply, ¶m)) | |
| 55 return PP_FALSE; | |
| 56 | |
| 57 contents = AddFontTable(table, param.a); | |
| 58 } | 55 } |
| 59 | 56 |
| 60 // If we are going to copy the data into |output|, it must be big enough. | 57 // If we are going to copy the data into |output|, it must be big enough. |
| 61 if (output && *output_length < contents->size()) | 58 if (output && *output_length < contents->size()) |
| 62 return PP_FALSE; | 59 return PP_FALSE; |
| 63 | 60 |
| 64 *output_length = static_cast<uint32_t>(contents->size()); | 61 *output_length = static_cast<uint32_t>(contents->size()); |
| 65 if (output) | 62 if (output) |
| 66 memcpy(output, contents->c_str(), *output_length); | 63 memcpy(output, contents->c_str(), *output_length); |
| 67 return PP_TRUE; | 64 return PP_TRUE; |
| 68 } | 65 } |
| 69 | 66 |
| 70 std::string* FlashFontFileResource::GetFontTable(uint32_t table) const { | 67 std::string* FlashFontFileResource::GetFontTable(uint32_t table) const { |
| 71 FontTableMap::const_iterator found = font_tables_.find(table); | 68 FontTableMap::const_iterator found = font_tables_.find(table); |
| 72 if (found == font_tables_.end()) | 69 if (found == font_tables_.end()) |
| 73 return NULL; | 70 return NULL; |
| 74 return found->second.get(); | 71 return found->second.get(); |
| 75 } | 72 } |
| 76 | 73 |
| 77 std::string* FlashFontFileResource::AddFontTable(uint32_t table, | 74 std::string* FlashFontFileResource::AddFontTable(uint32_t table, |
| 78 const std::string& contents) { | 75 const std::string& contents) { |
| 79 linked_ptr<std::string> heap_string(new std::string(contents)); | 76 linked_ptr<std::string> heap_string(new std::string(contents)); |
| 80 font_tables_[table] = heap_string; | 77 font_tables_[table] = heap_string; |
| 81 return heap_string.get(); | 78 return heap_string.get(); |
| 82 } | 79 } |
| 83 | 80 |
| 84 } // namespace proxy | 81 } // namespace proxy |
| 85 } // namespace ppapi | 82 } // namespace ppapi |
| OLD | NEW |