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(const HostResource& resource) : PluginResource(resource) { |
| 26 } |
26 virtual ~PrivateFontFile() {} | 27 virtual ~PrivateFontFile() {} |
27 | 28 |
28 // Resource overrides. | 29 // Resource overrides. |
29 virtual PrivateFontFile* AsPrivateFontFile() { return this; } | 30 virtual PrivateFontFile* AsPrivateFontFile() { return this; } |
30 | 31 |
31 // Sees if we have a cache of the font table and returns a pointer to it. | 32 // 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. | 33 // Returns NULL if we don't have it. |
33 std::string* GetFontTable(uint32_t table) const; | 34 std::string* GetFontTable(uint32_t table) const; |
34 | 35 |
35 std::string* AddFontTable(uint32_t table, const std::string& contents); | 36 std::string* AddFontTable(uint32_t table, const std::string& contents); |
(...skipping 25 matching lines...) Expand all Loading... |
61 PP_Instance instance, | 62 PP_Instance instance, |
62 const PP_FontDescription_Dev* description, | 63 const PP_FontDescription_Dev* description, |
63 PP_PrivateFontCharset charset) { | 64 PP_PrivateFontCharset charset) { |
64 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 65 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
65 if (!dispatcher) | 66 if (!dispatcher) |
66 return 0; | 67 return 0; |
67 | 68 |
68 SerializedFontDescription desc; | 69 SerializedFontDescription desc; |
69 desc.SetFromPPFontDescription(dispatcher, *description, true); | 70 desc.SetFromPPFontDescription(dispatcher, *description, true); |
70 | 71 |
71 PP_Resource result = 0; | 72 HostResource result; |
72 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( | 73 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontFileWithFallback( |
73 INTERFACE_ID_PPB_PDF, instance, desc, charset, &result)); | 74 INTERFACE_ID_PPB_PDF, instance, desc, charset, &result)); |
74 if (!result) | 75 if (result.is_null()) |
75 return 0; | 76 return 0; |
76 | 77 |
77 linked_ptr<PrivateFontFile> object(new PrivateFontFile(instance)); | 78 linked_ptr<PrivateFontFile> object(new PrivateFontFile(result)); |
78 PluginResourceTracker::GetInstance()->AddResource(result, object); | 79 return PluginResourceTracker::GetInstance()->AddResource(object); |
79 return result; | |
80 } | 80 } |
81 | 81 |
82 bool GetFontTableForPrivateFontFile(PP_Resource font_file, | 82 bool GetFontTableForPrivateFontFile(PP_Resource font_file, |
83 uint32_t table, | 83 uint32_t table, |
84 void* output, | 84 void* output, |
85 uint32_t* output_length) { | 85 uint32_t* output_length) { |
86 PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file); | 86 PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file); |
87 if (!object) | 87 if (!object) |
88 return false; | 88 return false; |
89 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( | 89 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
90 object->instance()); | 90 object->instance()); |
91 if (!dispatcher) | 91 if (!dispatcher) |
92 return false; | 92 return false; |
93 | 93 |
94 std::string* contents = object->GetFontTable(table); | 94 std::string* contents = object->GetFontTable(table); |
95 if (!contents) { | 95 if (!contents) { |
96 std::string deserialized; | 96 std::string deserialized; |
97 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( | 97 dispatcher->Send(new PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile( |
98 INTERFACE_ID_PPB_PDF, font_file, table, &deserialized)); | 98 INTERFACE_ID_PPB_PDF, object->host_resource(), table, &deserialized)); |
99 if (deserialized.empty()) | 99 if (deserialized.empty()) |
100 return false; | 100 return false; |
101 contents = object->AddFontTable(table, deserialized); | 101 contents = object->AddFontTable(table, deserialized); |
102 } | 102 } |
103 | 103 |
104 *output_length = static_cast<uint32_t>(contents->size()); | 104 *output_length = static_cast<uint32_t>(contents->size()); |
105 if (output) | 105 if (output) |
106 memcpy(output, contents->c_str(), *output_length); | 106 memcpy(output, contents->c_str(), *output_length); |
107 return true; | 107 return true; |
108 } | 108 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 IPC_MESSAGE_UNHANDLED(handled = false) | 142 IPC_MESSAGE_UNHANDLED(handled = false) |
143 IPC_END_MESSAGE_MAP() | 143 IPC_END_MESSAGE_MAP() |
144 // TODO(brettw): handle bad messages! | 144 // TODO(brettw): handle bad messages! |
145 return handled; | 145 return handled; |
146 } | 146 } |
147 | 147 |
148 void PPB_PDF_Proxy::OnMsgGetFontFileWithFallback( | 148 void PPB_PDF_Proxy::OnMsgGetFontFileWithFallback( |
149 PP_Instance instance, | 149 PP_Instance instance, |
150 const SerializedFontDescription& in_desc, | 150 const SerializedFontDescription& in_desc, |
151 int32_t charset, | 151 int32_t charset, |
152 PP_Resource* result) { | 152 HostResource* result) { |
153 PP_FontDescription_Dev desc; | 153 PP_FontDescription_Dev desc; |
154 in_desc.SetToPPFontDescription(dispatcher(), &desc, false); | 154 in_desc.SetToPPFontDescription(dispatcher(), &desc, false); |
155 *result = ppb_pdf_target()->GetFontFileWithFallback(instance, &desc, | 155 result->SetHostResource(instance, |
156 static_cast<PP_PrivateFontCharset>(charset)); | 156 ppb_pdf_target()->GetFontFileWithFallback( |
| 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 const HostResource& 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 |