| 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/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.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 #include "ppapi/thunk/enter.h" |
| 20 #include "ppapi/thunk/ppb_pdf_api.h" |
| 21 |
| 22 using ppapi::thunk::PPB_PDFFont_API; |
| 23 using ppapi::thunk::EnterResource; |
| 19 | 24 |
| 20 namespace pp { | 25 namespace pp { |
| 21 namespace proxy { | 26 namespace proxy { |
| 22 | 27 |
| 23 class PrivateFontFile : public PluginResource { | 28 class PrivateFontFile : public PluginResource, |
| 29 public PPB_PDFFont_API { |
| 24 public: | 30 public: |
| 25 PrivateFontFile(const HostResource& resource) : PluginResource(resource) { | 31 PrivateFontFile(const HostResource& resource) : PluginResource(resource) { |
| 26 } | 32 } |
| 27 virtual ~PrivateFontFile() {} | 33 virtual ~PrivateFontFile() {} |
| 28 | 34 |
| 29 // Resource overrides. | 35 PPB_PDFFont_API* AsPPB_PDFFont_API() { return this; } |
| 30 virtual PrivateFontFile* AsPrivateFontFile() { return this; } | |
| 31 | 36 |
| 32 // Sees if we have a cache of the font table and returns a pointer to it. | 37 // Sees if we have a cache of the font table and returns a pointer to it. |
| 33 // Returns NULL if we don't have it. | 38 // Returns NULL if we don't have it. |
| 34 std::string* GetFontTable(uint32_t table) const; | 39 std::string* GetFontTable(uint32_t table) const; |
| 35 | 40 |
| 36 std::string* AddFontTable(uint32_t table, const std::string& contents); | 41 std::string* AddFontTable(uint32_t table, const std::string& contents); |
| 37 | 42 |
| 38 private: | 43 private: |
| 39 typedef std::map<uint32_t, linked_ptr<std::string> > FontTableMap; | 44 typedef std::map<uint32_t, linked_ptr<std::string> > FontTableMap; |
| 40 FontTableMap font_tables_; | 45 FontTableMap font_tables_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 return 0; | 81 return 0; |
| 77 | 82 |
| 78 return PluginResourceTracker::GetInstance()->AddResource( | 83 return PluginResourceTracker::GetInstance()->AddResource( |
| 79 new PrivateFontFile(result)); | 84 new PrivateFontFile(result)); |
| 80 } | 85 } |
| 81 | 86 |
| 82 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | 87 bool GetFontTableForPrivateFontFile(PP_Resource font_file, |
| 83 uint32_t table, | 88 uint32_t table, |
| 84 void* output, | 89 void* output, |
| 85 uint32_t* output_length) { | 90 uint32_t* output_length) { |
| 86 PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file); | 91 EnterResource<PPB_PDFFont_API> enter(font_file, true); |
| 87 if (!object) | 92 if (enter.failed()) |
| 88 return false; | 93 return false; |
| 94 |
| 95 PrivateFontFile* object = static_cast<PrivateFontFile*>(enter.object()); |
| 89 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( | 96 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 90 object->instance()); | 97 object->instance()); |
| 91 if (!dispatcher) | 98 if (!dispatcher) |
| 92 return false; | 99 return false; |
| 93 | 100 |
| 94 std::string* contents = object->GetFontTable(table); | 101 std::string* contents = object->GetFontTable(table); |
| 95 if (!contents) { | 102 if (!contents) { |
| 96 std::string deserialized; | 103 std::string deserialized; |
| 97 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( | 104 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( |
| 98 INTERFACE_ID_PPB_PDF, object->host_resource(), table, &deserialized)); | 105 INTERFACE_ID_PPB_PDF, object->host_resource(), table, &deserialized)); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 font_file.host_resource(), table, NULL, &table_length)) | 184 font_file.host_resource(), table, NULL, &table_length)) |
| 178 return; | 185 return; |
| 179 | 186 |
| 180 result->resize(table_length); | 187 result->resize(table_length); |
| 181 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file.host_resource(), | 188 ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file.host_resource(), |
| 182 table, const_cast<char*>(result->c_str()), &table_length); | 189 table, const_cast<char*>(result->c_str()), &table_length); |
| 183 } | 190 } |
| 184 | 191 |
| 185 } // namespace proxy | 192 } // namespace proxy |
| 186 } // namespace pp | 193 } // namespace pp |
| OLD | NEW |