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 "native_client/src/shared/ppapi_proxy/plugin_ppb_pdf.h" | 5 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_pdf.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 17 matching lines...) Expand all Loading... |
28 static_cast<nacl_abi_size_t>(sizeof(PP_PrivateFindResult)); | 28 static_cast<nacl_abi_size_t>(sizeof(PP_PrivateFindResult)); |
29 // Limit the maximum result buffer size. | 29 // Limit the maximum result buffer size. |
30 const nacl_abi_size_t kMaxFindResultsBytes = 65536; | 30 const nacl_abi_size_t kMaxFindResultsBytes = 65536; |
31 const int32_t kMaxFindResults = | 31 const int32_t kMaxFindResults = |
32 kMaxFindResultsBytes / kPpbPrivateFindResultBytes; | 32 kMaxFindResultsBytes / kPpbPrivateFindResultBytes; |
33 | 33 |
34 PP_Var GetLocalizedString( | 34 PP_Var GetLocalizedString( |
35 PP_Instance instance, | 35 PP_Instance instance, |
36 PP_ResourceString string_id) { | 36 PP_ResourceString string_id) { |
37 DebugPrintf("PPB_PDF::GetLocalizedString: " | 37 DebugPrintf("PPB_PDF::GetLocalizedString: " |
38 "instance=%"NACL_PRIu32"\n", instance); | 38 "instance=%"NACL_PRId32"\n", instance); |
39 | 39 |
40 NaClSrpcChannel* channel = GetMainSrpcChannel(); | 40 NaClSrpcChannel* channel = GetMainSrpcChannel(); |
41 nacl_abi_size_t string_size = kMaxReturnVarSize; | 41 nacl_abi_size_t string_size = kMaxReturnVarSize; |
42 nacl::scoped_array<char> string_bytes(new char[string_size]); | 42 nacl::scoped_array<char> string_bytes(new char[string_size]); |
43 NaClSrpcError srpc_result = | 43 NaClSrpcError srpc_result = |
44 PpbPdfRpcClient::PPB_PDF_GetLocalizedString( | 44 PpbPdfRpcClient::PPB_PDF_GetLocalizedString( |
45 channel, | 45 channel, |
46 instance, | 46 instance, |
47 static_cast<int32_t>(string_id), | 47 static_cast<int32_t>(string_id), |
48 &string_size, string_bytes.get()); | 48 &string_size, string_bytes.get()); |
49 | 49 |
50 PP_Var string = PP_MakeUndefined(); | 50 PP_Var string = PP_MakeUndefined(); |
51 if (srpc_result == NACL_SRPC_RESULT_OK) { | 51 if (srpc_result == NACL_SRPC_RESULT_OK) { |
52 (void) DeserializeTo(string_bytes.get(), string_size, 1, &string); | 52 (void) DeserializeTo(string_bytes.get(), string_size, 1, &string); |
53 } | 53 } |
54 | 54 |
55 DebugPrintf("PPB_PDF::GetLocalizedString: %s\n", | 55 DebugPrintf("PPB_PDF::GetLocalizedString: %s\n", |
56 NaClSrpcErrorString(srpc_result)); | 56 NaClSrpcErrorString(srpc_result)); |
57 return string; | 57 return string; |
58 } | 58 } |
59 | 59 |
60 PP_Resource GetResourceImage(PP_Instance instance, | 60 PP_Resource GetResourceImage(PP_Instance instance, |
61 PP_ResourceImage image_id) { | 61 PP_ResourceImage image_id) { |
62 DebugPrintf("PPB_PDF::GetResourceImage: " | 62 DebugPrintf("PPB_PDF::GetResourceImage: " |
63 "instance=%"NACL_PRIu32"\n", instance); | 63 "instance=%"NACL_PRId32"\n", instance); |
64 | 64 |
65 PP_Resource image = kInvalidResourceId; | 65 PP_Resource image = kInvalidResourceId; |
66 NaClSrpcError srpc_result = | 66 NaClSrpcError srpc_result = |
67 PpbPdfRpcClient::PPB_PDF_GetResourceImage( | 67 PpbPdfRpcClient::PPB_PDF_GetResourceImage( |
68 GetMainSrpcChannel(), | 68 GetMainSrpcChannel(), |
69 instance, | 69 instance, |
70 static_cast<int32_t>(image_id), | 70 static_cast<int32_t>(image_id), |
71 &image); | 71 &image); |
72 | 72 |
73 DebugPrintf("PPB_PDF::GetResourceImage: %s\n", | 73 DebugPrintf("PPB_PDF::GetResourceImage: %s\n", |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 ++s; | 105 ++s; |
106 return (s - str); | 106 return (s - str); |
107 } | 107 } |
108 | 108 |
109 void SearchString(PP_Instance instance, | 109 void SearchString(PP_Instance instance, |
110 const unsigned short* string, | 110 const unsigned short* string, |
111 const unsigned short* term, | 111 const unsigned short* term, |
112 bool case_sensitive, | 112 bool case_sensitive, |
113 struct PP_PrivateFindResult** results, | 113 struct PP_PrivateFindResult** results, |
114 int* count) { | 114 int* count) { |
115 DebugPrintf("PPB_PDF::SearchString: instance=%"NACL_PRIu32"\n", instance); | 115 DebugPrintf("PPB_PDF::SearchString: instance=%"NACL_PRId32"\n", instance); |
116 | 116 |
117 CHECK(string != NULL); | 117 CHECK(string != NULL); |
118 CHECK(term != NULL); | 118 CHECK(term != NULL); |
119 CHECK(results != NULL); | 119 CHECK(results != NULL); |
120 CHECK(count != NULL); | 120 CHECK(count != NULL); |
121 | 121 |
122 nacl_abi_size_t find_results_size = kMaxFindResultsBytes; | 122 nacl_abi_size_t find_results_size = kMaxFindResultsBytes; |
123 *results = reinterpret_cast<PP_PrivateFindResult*>(malloc(find_results_size)); | 123 *results = reinterpret_cast<PP_PrivateFindResult*>(malloc(find_results_size)); |
124 *count = 0; | 124 *count = 0; |
125 | 125 |
(...skipping 12 matching lines...) Expand all Loading... |
138 &find_results_size, | 138 &find_results_size, |
139 reinterpret_cast<char*>(*results), | 139 reinterpret_cast<char*>(*results), |
140 reinterpret_cast<int32_t*>(count)); | 140 reinterpret_cast<int32_t*>(count)); |
141 | 141 |
142 DebugPrintf("PPB_PDF::SearchString: %s\n", | 142 DebugPrintf("PPB_PDF::SearchString: %s\n", |
143 NaClSrpcErrorString(srpc_result)); | 143 NaClSrpcErrorString(srpc_result)); |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 void DidStartLoading(PP_Instance instance) { | 147 void DidStartLoading(PP_Instance instance) { |
148 DebugPrintf("PPB_PDF::DidStartLoading: instance=%"NACL_PRIu32"\n", | 148 DebugPrintf("PPB_PDF::DidStartLoading: instance=%"NACL_PRId32"\n", |
149 instance); | 149 instance); |
150 | 150 |
151 NaClSrpcError srpc_result = | 151 NaClSrpcError srpc_result = |
152 PpbPdfRpcClient::PPB_PDF_DidStartLoading(GetMainSrpcChannel(), | 152 PpbPdfRpcClient::PPB_PDF_DidStartLoading(GetMainSrpcChannel(), |
153 instance); | 153 instance); |
154 | 154 |
155 DebugPrintf("PPB_PDF::DidStartLoading: %s\n", | 155 DebugPrintf("PPB_PDF::DidStartLoading: %s\n", |
156 NaClSrpcErrorString(srpc_result)); | 156 NaClSrpcErrorString(srpc_result)); |
157 } | 157 } |
158 | 158 |
159 void DidStopLoading(PP_Instance instance) { | 159 void DidStopLoading(PP_Instance instance) { |
160 DebugPrintf("PPB_PDF::DidStopLoading: instance=%"NACL_PRIu32"\n", | 160 DebugPrintf("PPB_PDF::DidStopLoading: instance=%"NACL_PRId32"\n", |
161 instance); | 161 instance); |
162 | 162 |
163 NaClSrpcError srpc_result = | 163 NaClSrpcError srpc_result = |
164 PpbPdfRpcClient::PPB_PDF_DidStopLoading(GetMainSrpcChannel(), | 164 PpbPdfRpcClient::PPB_PDF_DidStopLoading(GetMainSrpcChannel(), |
165 instance); | 165 instance); |
166 | 166 |
167 DebugPrintf("PPB_PDF::DidStopLoading: %s\n", | 167 DebugPrintf("PPB_PDF::DidStopLoading: %s\n", |
168 NaClSrpcErrorString(srpc_result)); | 168 NaClSrpcErrorString(srpc_result)); |
169 } | 169 } |
170 | 170 |
171 void SetContentRestriction(PP_Instance instance, | 171 void SetContentRestriction(PP_Instance instance, |
172 int restrictions) { | 172 int restrictions) { |
173 DebugPrintf("PPB_PDF::SetContentRestriction: instance=%"NACL_PRIu32"\n", | 173 DebugPrintf("PPB_PDF::SetContentRestriction: instance=%"NACL_PRId32"\n", |
174 instance); | 174 instance); |
175 | 175 |
176 NaClSrpcError srpc_result = | 176 NaClSrpcError srpc_result = |
177 PpbPdfRpcClient::PPB_PDF_SetContentRestriction(GetMainSrpcChannel(), | 177 PpbPdfRpcClient::PPB_PDF_SetContentRestriction(GetMainSrpcChannel(), |
178 instance, | 178 instance, |
179 restrictions); | 179 restrictions); |
180 | 180 |
181 DebugPrintf("PPB_PDF::SetContentRestriction: %s\n", | 181 DebugPrintf("PPB_PDF::SetContentRestriction: %s\n", |
182 NaClSrpcErrorString(srpc_result)); | 182 NaClSrpcErrorString(srpc_result)); |
183 } | 183 } |
(...skipping 18 matching lines...) Expand all Loading... |
202 NaClSrpcError srpc_result = | 202 NaClSrpcError srpc_result = |
203 PpbPdfRpcClient::PPB_PDF_UserMetricsRecordAction(GetMainSrpcChannel(), | 203 PpbPdfRpcClient::PPB_PDF_UserMetricsRecordAction(GetMainSrpcChannel(), |
204 action_size, | 204 action_size, |
205 action_bytes.get()); | 205 action_bytes.get()); |
206 | 206 |
207 DebugPrintf("PPB_PDF::UserMetricsRecordAction: %s\n", | 207 DebugPrintf("PPB_PDF::UserMetricsRecordAction: %s\n", |
208 NaClSrpcErrorString(srpc_result)); | 208 NaClSrpcErrorString(srpc_result)); |
209 } | 209 } |
210 | 210 |
211 void HasUnsupportedFeature(PP_Instance instance) { | 211 void HasUnsupportedFeature(PP_Instance instance) { |
212 DebugPrintf("PPB_PDF::HasUnsupportedFeature: instance=%"NACL_PRIu32"\n", | 212 DebugPrintf("PPB_PDF::HasUnsupportedFeature: instance=%"NACL_PRId32"\n", |
213 instance); | 213 instance); |
214 | 214 |
215 NaClSrpcError srpc_result = | 215 NaClSrpcError srpc_result = |
216 PpbPdfRpcClient::PPB_PDF_HasUnsupportedFeature(GetMainSrpcChannel(), | 216 PpbPdfRpcClient::PPB_PDF_HasUnsupportedFeature(GetMainSrpcChannel(), |
217 instance); | 217 instance); |
218 | 218 |
219 DebugPrintf("PPB_PDF::HasUnsupportedFeature: %s\n", | 219 DebugPrintf("PPB_PDF::HasUnsupportedFeature: %s\n", |
220 NaClSrpcErrorString(srpc_result)); | 220 NaClSrpcErrorString(srpc_result)); |
221 } | 221 } |
222 | 222 |
223 void SaveAs(PP_Instance instance) { | 223 void SaveAs(PP_Instance instance) { |
224 DebugPrintf("PPB_PDF::SaveAs: instance=%"NACL_PRIu32"\n", instance); | 224 DebugPrintf("PPB_PDF::SaveAs: instance=%"NACL_PRId32"\n", instance); |
225 | 225 |
226 NaClSrpcError srpc_result = | 226 NaClSrpcError srpc_result = |
227 PpbPdfRpcClient::PPB_PDF_SaveAs(GetMainSrpcChannel(), | 227 PpbPdfRpcClient::PPB_PDF_SaveAs(GetMainSrpcChannel(), |
228 instance); | 228 instance); |
229 | 229 |
230 DebugPrintf("PPB_PDF::SaveAs: %s\n", NaClSrpcErrorString(srpc_result)); | 230 DebugPrintf("PPB_PDF::SaveAs: %s\n", NaClSrpcErrorString(srpc_result)); |
231 } | 231 } |
232 | 232 |
233 } // namespace | 233 } // namespace |
234 | 234 |
235 const PPB_PDF* PluginPDF::GetInterface() { | 235 const PPB_PDF* PluginPDF::GetInterface() { |
236 static const PPB_PDF pdf_interface = { | 236 static const PPB_PDF pdf_interface = { |
237 GetLocalizedString, | 237 GetLocalizedString, |
238 GetResourceImage, | 238 GetResourceImage, |
239 GetFontFileWithFallback, | 239 GetFontFileWithFallback, |
240 GetFontTableForPrivateFontFile, | 240 GetFontTableForPrivateFontFile, |
241 SearchString, | 241 SearchString, |
242 DidStartLoading, | 242 DidStartLoading, |
243 DidStopLoading, | 243 DidStopLoading, |
244 SetContentRestriction, | 244 SetContentRestriction, |
245 HistogramPDFPageCount, | 245 HistogramPDFPageCount, |
246 UserMetricsRecordAction, | 246 UserMetricsRecordAction, |
247 HasUnsupportedFeature, | 247 HasUnsupportedFeature, |
248 SaveAs | 248 SaveAs |
249 }; | 249 }; |
250 return &pdf_interface; | 250 return &pdf_interface; |
251 } | 251 } |
252 | 252 |
253 } // namespace ppapi_proxy | 253 } // namespace ppapi_proxy |
OLD | NEW |