| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ppb_pdf_proxy.h" | 5 #include "ppapi/proxy/ppb_pdf_proxy.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy. | 7 #include <string.h> // For memcpy. |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/linked_ptr.h" | 11 #include "base/linked_ptr.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "ppapi/c/private/ppb_pdf.h" | 14 #include "ppapi/c/private/ppb_pdf.h" |
| 15 #include "ppapi/proxy/plugin_dispatcher.h" | 15 #include "ppapi/proxy/plugin_dispatcher.h" |
| 16 #include "ppapi/proxy/plugin_resource.h" | 16 #include "ppapi/proxy/plugin_resource.h" |
| 17 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 17 #include "ppapi/proxy/ppapi_messages.h" | 18 #include "ppapi/proxy/ppapi_messages.h" |
| 18 | 19 |
| 19 namespace pp { | 20 namespace pp { |
| 20 namespace proxy { | 21 namespace proxy { |
| 21 | 22 |
| 22 class PrivateFontFile : public PluginResource { | 23 class PrivateFontFile : public PluginResource { |
| 23 public: | 24 public: |
| 24 PrivateFontFile() {} | 25 PrivateFontFile(PP_Instance instance) : PluginResource(instance) {} |
| 25 virtual ~PrivateFontFile() {} | 26 virtual ~PrivateFontFile() {} |
| 26 | 27 |
| 27 // Resource overrides. | 28 // Resource overrides. |
| 28 virtual PrivateFontFile* AsPrivateFontFile() { return this; } | 29 virtual PrivateFontFile* AsPrivateFontFile() { return this; } |
| 29 | 30 |
| 30 // Sees if we have a cache of the font table and returns a pointer to it. | 31 // Sees if we have a cache of the font table and returns a pointer to it. |
| 31 // Returns NULL if we don't have it. | 32 // Returns NULL if we don't have it. |
| 32 std::string* GetFontTable(uint32_t table) const; | 33 std::string* GetFontTable(uint32_t table) const; |
| 33 | 34 |
| 34 std::string* AddFontTable(uint32_t table, const std::string& contents); | 35 std::string* AddFontTable(uint32_t table, const std::string& contents); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 53 font_tables_[table] = heap_string; | 54 font_tables_[table] = heap_string; |
| 54 return heap_string.get(); | 55 return heap_string.get(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 namespace { | 58 namespace { |
| 58 | 59 |
| 59 PP_Resource GetFontFileWithFallback( | 60 PP_Resource GetFontFileWithFallback( |
| 60 PP_Instance instance, | 61 PP_Instance instance, |
| 61 const PP_FontDescription_Dev* description, | 62 const PP_FontDescription_Dev* description, |
| 62 PP_PrivateFontCharset charset) { | 63 PP_PrivateFontCharset charset) { |
| 63 PluginDispatcher* dispatcher = PluginDispatcher::Get(); | 64 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 65 if (!dispatcher) |
| 66 return 0; |
| 67 |
| 64 SerializedFontDescription desc; | 68 SerializedFontDescription desc; |
| 65 desc.SetFromPPFontDescription(dispatcher, *description, true); | 69 desc.SetFromPPFontDescription(dispatcher, *description, true); |
| 66 | 70 |
| 67 PP_Resource result = 0; | 71 PP_Resource result = 0; |
| 68 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( | 72 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( |
| 69 INTERFACE_ID_PPB_PDF, instance, desc, charset, &result)); | 73 INTERFACE_ID_PPB_PDF, instance, desc, charset, &result)); |
| 70 if (!result) | 74 if (!result) |
| 71 return 0; | 75 return 0; |
| 72 | 76 |
| 73 linked_ptr<PrivateFontFile> object(new PrivateFontFile); | 77 linked_ptr<PrivateFontFile> object(new PrivateFontFile(instance)); |
| 74 dispatcher->plugin_resource_tracker()->AddResource(result, object); | 78 PluginResourceTracker::GetInstance()->AddResource(result, object); |
| 75 return result; | 79 return result; |
| 76 } | 80 } |
| 77 | 81 |
| 78 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | 82 bool GetFontTableForPrivateFontFile(PP_Resource font_file, |
| 79 uint32_t table, | 83 uint32_t table, |
| 80 void* output, | 84 void* output, |
| 81 uint32_t* output_length) { | 85 uint32_t* output_length) { |
| 82 PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file); | 86 PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file); |
| 83 if (!object) | 87 if (!object) |
| 84 return false; | 88 return false; |
| 89 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 90 object->instance()); |
| 91 if (!dispatcher) |
| 92 return false; |
| 85 | 93 |
| 86 std::string* contents = object->GetFontTable(table); | 94 std::string* contents = object->GetFontTable(table); |
| 87 if (!contents) { | 95 if (!contents) { |
| 88 std::string deserialized; | 96 std::string deserialized; |
| 89 PluginDispatcher::Get()->Send( | 97 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( |
| 90 new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( | 98 INTERFACE_ID_PPB_PDF, font_file, table, &deserialized)); |
| 91 INTERFACE_ID_PPB_PDF, font_file, table, &deserialized)); | |
| 92 if (deserialized.empty()) | 99 if (deserialized.empty()) |
| 93 return false; | 100 return false; |
| 94 contents = object->AddFontTable(table, deserialized); | 101 contents = object->AddFontTable(table, deserialized); |
| 95 } | 102 } |
| 96 | 103 |
| 97 *output_length = static_cast<uint32_t>(contents->size()); | 104 *output_length = static_cast<uint32_t>(contents->size()); |
| 98 if (output) | 105 if (output) |
| 99 memcpy(output, contents->c_str(), *output_length); | 106 memcpy(output, contents->c_str(), *output_length); |
| 100 return true; | 107 return true; |
| 101 } | 108 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 font_file, table, NULL, &table_length)) | 166 font_file, table, NULL, &table_length)) |
| 160 return; | 167 return; |
| 161 | 168 |
| 162 result->resize(table_length); | 169 result->resize(table_length); |
| 163 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file, table, | 170 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file, table, |
| 164 const_cast<char*>(result->c_str()), &table_length); | 171 const_cast<char*>(result->c_str()), &table_length); |
| 165 } | 172 } |
| 166 | 173 |
| 167 } // namespace proxy | 174 } // namespace proxy |
| 168 } // namespace pp | 175 } // namespace pp |
| OLD | NEW |