| 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/plugin_resource_tracker.h" |
| 18 #include "ppapi/proxy/ppapi_messages.h" | 18 #include "ppapi/proxy/ppapi_messages.h" |
| 19 | 19 |
| 20 namespace pp { | 20 namespace pp { |
| 21 namespace proxy { | 21 namespace proxy { |
| 22 | 22 |
| 23 class PrivateFontFile : public PluginResource { | 23 class PrivateFontFile : public PluginResource { |
| 24 public: | 24 public: |
| 25 PrivateFontFile(PP_Instance instance) : PluginResource(instance) {} | 25 PrivateFontFile(PP_Instance instance, SerializedResource resource) |
| 26 : PluginResource(instance, resource) { |
| 27 } |
| 26 virtual ~PrivateFontFile() {} | 28 virtual ~PrivateFontFile() {} |
| 27 | 29 |
| 28 // Resource overrides. | 30 // Resource overrides. |
| 29 virtual PrivateFontFile* AsPrivateFontFile() { return this; } | 31 virtual PrivateFontFile* AsPrivateFontFile() { return this; } |
| 30 | 32 |
| 31 // Sees if we have a cache of the font table and returns a pointer to it. | 33 // Sees if we have a cache of the font table and returns a pointer to it. |
| 32 // Returns NULL if we don't have it. | 34 // Returns NULL if we don't have it. |
| 33 std::string* GetFontTable(uint32_t table) const; | 35 std::string* GetFontTable(uint32_t table) const; |
| 34 | 36 |
| 35 std::string* AddFontTable(uint32_t table, const std::string& contents); | 37 std::string* AddFontTable(uint32_t table, const std::string& contents); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 61 PP_Instance instance, | 63 PP_Instance instance, |
| 62 const PP_FontDescription_Dev* description, | 64 const PP_FontDescription_Dev* description, |
| 63 PP_PrivateFontCharset charset) { | 65 PP_PrivateFontCharset charset) { |
| 64 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 66 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 65 if (!dispatcher) | 67 if (!dispatcher) |
| 66 return 0; | 68 return 0; |
| 67 | 69 |
| 68 SerializedFontDescription desc; | 70 SerializedFontDescription desc; |
| 69 desc.SetFromPPFontDescription(dispatcher, *description, true); | 71 desc.SetFromPPFontDescription(dispatcher, *description, true); |
| 70 | 72 |
| 71 PP_Resource result = 0; | 73 SerializedResource result; |
| 72 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( | 74 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( |
| 73 INTERFACE_ID_PPB_PDF, instance, desc, charset, &result)); | 75 INTERFACE_ID_PPB_PDF, instance, desc, charset, &result)); |
| 74 if (!result) | 76 if (result.is_null()) |
| 75 return 0; | 77 return 0; |
| 76 | 78 |
| 77 linked_ptr<PrivateFontFile> object(new PrivateFontFile(instance)); | 79 linked_ptr<PrivateFontFile> object(new PrivateFontFile(instance, result)); |
| 78 PluginResourceTracker::GetInstance()->AddResource(result, object); | 80 return PluginResourceTracker::GetInstance()->AddResource(object); |
| 79 return result; | |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | 83 bool GetFontTableForPrivateFontFile(PP_Resource font_file, |
| 83 uint32_t table, | 84 uint32_t table, |
| 84 void* output, | 85 void* output, |
| 85 uint32_t* output_length) { | 86 uint32_t* output_length) { |
| 86 PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file); | 87 PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file); |
| 87 if (!object) | 88 if (!object) |
| 88 return false; | 89 return false; |
| 89 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( | 90 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 90 object->instance()); | 91 object->instance()); |
| 91 if (!dispatcher) | 92 if (!dispatcher) |
| 92 return false; | 93 return false; |
| 93 | 94 |
| 94 std::string* contents = object->GetFontTable(table); | 95 std::string* contents = object->GetFontTable(table); |
| 95 if (!contents) { | 96 if (!contents) { |
| 96 std::string deserialized; | 97 std::string deserialized; |
| 97 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( | 98 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( |
| 98 INTERFACE_ID_PPB_PDF, font_file, table, &deserialized)); | 99 INTERFACE_ID_PPB_PDF, object->host_resource(), table, &deserialized)); |
| 99 if (deserialized.empty()) | 100 if (deserialized.empty()) |
| 100 return false; | 101 return false; |
| 101 contents = object->AddFontTable(table, deserialized); | 102 contents = object->AddFontTable(table, deserialized); |
| 102 } | 103 } |
| 103 | 104 |
| 104 *output_length = static_cast<uint32_t>(contents->size()); | 105 *output_length = static_cast<uint32_t>(contents->size()); |
| 105 if (output) | 106 if (output) |
| 106 memcpy(output, contents->c_str(), *output_length); | 107 memcpy(output, contents->c_str(), *output_length); |
| 107 return true; | 108 return true; |
| 108 } | 109 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 IPC_MESSAGE_UNHANDLED(handled = false) | 143 IPC_MESSAGE_UNHANDLED(handled = false) |
| 143 IPC_END_MESSAGE_MAP() | 144 IPC_END_MESSAGE_MAP() |
| 144 // TODO(brettw): handle bad messages! | 145 // TODO(brettw): handle bad messages! |
| 145 return handled; | 146 return handled; |
| 146 } | 147 } |
| 147 | 148 |
| 148 void PPB_PDF_Proxy::OnMsgGetFontFileWithFallback( | 149 void PPB_PDF_Proxy::OnMsgGetFontFileWithFallback( |
| 149 PP_Instance instance, | 150 PP_Instance instance, |
| 150 const SerializedFontDescription& in_desc, | 151 const SerializedFontDescription& in_desc, |
| 151 int32_t charset, | 152 int32_t charset, |
| 152 PP_Resource* result) { | 153 SerializedResource* result) { |
| 153 PP_FontDescription_Dev desc; | 154 PP_FontDescription_Dev desc; |
| 154 in_desc.SetToPPFontDescription(dispatcher(), &desc, false); | 155 in_desc.SetToPPFontDescription(dispatcher(), &desc, false); |
| 155 *result = ppb_pdf_target()->GetFontFileWithFallback(instance, &desc, | 156 result->set_host_resource(ppb_pdf_target()->GetFontFileWithFallback( |
| 156 static_cast<PP_PrivateFontCharset>(charset)); | 157 instance, &desc, static_cast<PP_PrivateFontCharset>(charset))); |
| 157 } | 158 } |
| 158 | 159 |
| 159 void PPB_PDF_Proxy::OnMsgGetFontTableForPrivateFontFile(PP_Resource font_file, | 160 void PPB_PDF_Proxy::OnMsgGetFontTableForPrivateFontFile( |
| 160 uint32_t table, | 161 SerializedResource font_file, |
| 161 std::string* result) { | 162 uint32_t table, |
| 163 std::string* result) { |
| 162 // TODO(brettw): It would be nice not to copy here. At least on Linux, | 164 // TODO(brettw): It would be nice not to copy here. At least on Linux, |
| 163 // we can map the font file into shared memory and read it that way. | 165 // we can map the font file into shared memory and read it that way. |
| 164 uint32_t table_length = 0; | 166 uint32_t table_length = 0; |
| 165 if (!ppb_pdf_target()->GetFontTableForPrivateFontFile( | 167 if (!ppb_pdf_target()->GetFontTableForPrivateFontFile( |
| 166 font_file, table, NULL, &table_length)) | 168 font_file.host_resource(), table, NULL, &table_length)) |
| 167 return; | 169 return; |
| 168 | 170 |
| 169 result->resize(table_length); | 171 result->resize(table_length); |
| 170 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file, table, | 172 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file.host_resource(), |
| 171 const_cast<char*>(result->c_str()), &table_length); | 173 table, const_cast<char*>(result->c_str()), &table_length); |
| 172 } | 174 } |
| 173 | 175 |
| 174 } // namespace proxy | 176 } // namespace proxy |
| 175 } // namespace pp | 177 } // namespace pp |
| OLD | NEW |