OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "pdf/pdf.h" | 5 #include "pdf/pdf.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 // definition because they are not referenced here. This causes the Pepper | 21 // definition because they are not referenced here. This causes the Pepper |
22 // exports (PPP_GetInterface etc) to not be exported. So we force the linker | 22 // exports (PPP_GetInterface etc) to not be exported. So we force the linker |
23 // to include this code by using __attribute__((used)). | 23 // to include this code by using __attribute__((used)). |
24 #if __GNUC__ >= 4 | 24 #if __GNUC__ >= 4 |
25 #define PDF_USED __attribute__((used)) | 25 #define PDF_USED __attribute__((used)) |
26 #else | 26 #else |
27 #define PDF_USED | 27 #define PDF_USED |
28 #endif | 28 #endif |
29 | 29 |
30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
31 HMODULE g_hmodule; | |
32 | 31 |
33 void HandleInvalidParameter(const wchar_t* expression, | 32 void HandleInvalidParameter(const wchar_t* expression, |
34 const wchar_t* function, | 33 const wchar_t* function, |
35 const wchar_t* file, | 34 const wchar_t* file, |
36 unsigned int line, | 35 unsigned int line, |
37 uintptr_t reserved) { | 36 uintptr_t reserved) { |
38 // Do the same as Chrome's CHECK(false) which is undefined. | 37 // Do the same as Chrome's CHECK(false) which is undefined. |
39 ::base::debug::BreakDebugger(); | 38 ::base::debug::BreakDebugger(); |
40 return; | 39 return; |
41 } | 40 } |
42 | 41 |
43 void HandlePureVirtualCall() { | 42 void HandlePureVirtualCall() { |
44 // Do the same as Chrome's CHECK(false) which is undefined. | 43 // Do the same as Chrome's CHECK(false) which is undefined. |
45 ::base::debug::BreakDebugger(); | 44 ::base::debug::BreakDebugger(); |
46 return; | 45 return; |
47 } | 46 } |
48 | 47 |
49 | 48 |
50 BOOL APIENTRY DllMain(HMODULE module, DWORD reason_for_call, LPVOID reserved) { | 49 BOOL APIENTRY DllMain(HMODULE module, DWORD reason_for_call, LPVOID reserved) { |
51 g_hmodule = module; | |
52 if (reason_for_call == DLL_PROCESS_ATTACH) { | 50 if (reason_for_call == DLL_PROCESS_ATTACH) { |
53 // On windows following handlers work only inside module. So breakpad in | 51 // On windows following handlers work only inside module. So breakpad in |
54 // chrome.dll does not catch that. To avoid linking related code or | 52 // chrome.dll does not catch that. To avoid linking related code or |
55 // duplication breakpad_win.cc::InitCrashReporter() just catch errors here | 53 // duplication breakpad_win.cc::InitCrashReporter() just catch errors here |
56 // and crash in a way interceptable by breakpad of parent module. | 54 // and crash in a way interceptable by breakpad of parent module. |
57 _set_invalid_parameter_handler(HandleInvalidParameter); | 55 _set_invalid_parameter_handler(HandleInvalidParameter); |
58 _set_purecall_handler(HandlePureVirtualCall); | 56 _set_purecall_handler(HandlePureVirtualCall); |
59 | 57 |
60 #if defined(ARCH_CPU_X86_64) && _MSC_VER <= 1800 | 58 #if defined(ARCH_CPU_X86_64) && _MSC_VER <= 1800 |
61 // VS2013's CRT only checks the existence of FMA3 instructions, not the | 59 // VS2013's CRT only checks the existence of FMA3 instructions, not the |
(...skipping 30 matching lines...) Expand all Loading... |
92 g_sdk_initialized_via_pepper = false; | 90 g_sdk_initialized_via_pepper = false; |
93 } | 91 } |
94 } | 92 } |
95 | 93 |
96 bool PDFModule::Init() { | 94 bool PDFModule::Init() { |
97 return true; | 95 return true; |
98 } | 96 } |
99 | 97 |
100 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) { | 98 pp::Instance* PDFModule::CreateInstance(PP_Instance instance) { |
101 if (!g_sdk_initialized_via_pepper) { | 99 if (!g_sdk_initialized_via_pepper) { |
102 void* data = NULL; | 100 if (!chrome_pdf::InitializeSDK()) |
103 #if defined(OS_WIN) | |
104 data = g_hmodule; | |
105 #endif | |
106 if (!chrome_pdf::InitializeSDK(data)) | |
107 return NULL; | 101 return NULL; |
108 g_sdk_initialized_via_pepper = true; | 102 g_sdk_initialized_via_pepper = true; |
109 } | 103 } |
110 | 104 |
111 if (pp::PDF::IsOutOfProcess(pp::InstanceHandle(instance))) | 105 if (pp::PDF::IsOutOfProcess(pp::InstanceHandle(instance))) |
112 return new OutOfProcessInstance(instance); | 106 return new OutOfProcessInstance(instance); |
113 return new Instance(instance); | 107 return new Instance(instance); |
114 } | 108 } |
115 | 109 |
116 } // namespace chrome_pdf | 110 } // namespace chrome_pdf |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 int bounds_origin_x, | 153 int bounds_origin_x, |
160 int bounds_origin_y, | 154 int bounds_origin_y, |
161 int bounds_width, | 155 int bounds_width, |
162 int bounds_height, | 156 int bounds_height, |
163 bool fit_to_bounds, | 157 bool fit_to_bounds, |
164 bool stretch_to_bounds, | 158 bool stretch_to_bounds, |
165 bool keep_aspect_ratio, | 159 bool keep_aspect_ratio, |
166 bool center_in_bounds, | 160 bool center_in_bounds, |
167 bool autorotate) { | 161 bool autorotate) { |
168 if (!g_sdk_initialized_via_pepper) { | 162 if (!g_sdk_initialized_via_pepper) { |
169 if (!chrome_pdf::InitializeSDK(g_hmodule)) { | 163 if (!chrome_pdf::InitializeSDK()) { |
170 return false; | 164 return false; |
171 } | 165 } |
172 } | 166 } |
173 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 167 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
174 chrome_pdf::PDFEngineExports::Create()); | 168 chrome_pdf::PDFEngineExports::Create()); |
175 chrome_pdf::PDFEngineExports::RenderingSettings settings( | 169 chrome_pdf::PDFEngineExports::RenderingSettings settings( |
176 dpi_x, dpi_y, pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, | 170 dpi_x, dpi_y, pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width, |
177 bounds_height), | 171 bounds_height), |
178 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds, | 172 fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds, |
179 autorotate); | 173 autorotate); |
180 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size, | 174 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size, |
181 page_number, settings, dc); | 175 page_number, settings, dc); |
182 if (!g_sdk_initialized_via_pepper) { | 176 if (!g_sdk_initialized_via_pepper) { |
183 chrome_pdf::ShutdownSDK(); | 177 chrome_pdf::ShutdownSDK(); |
184 } | 178 } |
185 return ret; | 179 return ret; |
186 } | 180 } |
187 | 181 |
188 #endif // OS_WIN | 182 #endif // OS_WIN |
189 | 183 |
190 // |page_count| and |max_page_width| are optional and can be NULL. | 184 // |page_count| and |max_page_width| are optional and can be NULL. |
191 // Returns false if the document is not valid. | 185 // Returns false if the document is not valid. |
192 PDF_USED PP_EXPORT | 186 PDF_USED PP_EXPORT |
193 bool GetPDFDocInfo(const void* pdf_buffer, | 187 bool GetPDFDocInfo(const void* pdf_buffer, |
194 int buffer_size, int* page_count, | 188 int buffer_size, int* page_count, |
195 double* max_page_width) { | 189 double* max_page_width) { |
196 if (!g_sdk_initialized_via_pepper) { | 190 if (!g_sdk_initialized_via_pepper) { |
197 void* data = NULL; | 191 if (!chrome_pdf::InitializeSDK()) |
198 #if defined(OS_WIN) | |
199 data = g_hmodule; | |
200 #endif | |
201 if (!chrome_pdf::InitializeSDK(data)) | |
202 return false; | 192 return false; |
203 } | 193 } |
204 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 194 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
205 chrome_pdf::PDFEngineExports::Create()); | 195 chrome_pdf::PDFEngineExports::Create()); |
206 bool ret = engine_exports->GetPDFDocInfo( | 196 bool ret = engine_exports->GetPDFDocInfo( |
207 pdf_buffer, buffer_size, page_count, max_page_width); | 197 pdf_buffer, buffer_size, page_count, max_page_width); |
208 if (!g_sdk_initialized_via_pepper) { | 198 if (!g_sdk_initialized_via_pepper) { |
209 chrome_pdf::ShutdownSDK(); | 199 chrome_pdf::ShutdownSDK(); |
210 } | 200 } |
211 return ret; | 201 return ret; |
212 } | 202 } |
213 | 203 |
214 // Gets the dimensions of a specific page in a document. | 204 // Gets the dimensions of a specific page in a document. |
215 // |pdf_buffer| is the buffer that contains the entire PDF document to be | 205 // |pdf_buffer| is the buffer that contains the entire PDF document to be |
216 // rendered. | 206 // rendered. |
217 // |pdf_buffer_size| is the size of |pdf_buffer| in bytes. | 207 // |pdf_buffer_size| is the size of |pdf_buffer| in bytes. |
218 // |page_number| is the page number that the function will get the dimensions | 208 // |page_number| is the page number that the function will get the dimensions |
219 // of. | 209 // of. |
220 // |width| is the output for the width of the page in points. | 210 // |width| is the output for the width of the page in points. |
221 // |height| is the output for the height of the page in points. | 211 // |height| is the output for the height of the page in points. |
222 // Returns false if the document or the page number are not valid. | 212 // Returns false if the document or the page number are not valid. |
223 PDF_USED PP_EXPORT | 213 PDF_USED PP_EXPORT |
224 bool GetPDFPageSizeByIndex(const void* pdf_buffer, | 214 bool GetPDFPageSizeByIndex(const void* pdf_buffer, |
225 int pdf_buffer_size, int page_number, | 215 int pdf_buffer_size, int page_number, |
226 double* width, double* height) { | 216 double* width, double* height) { |
227 if (!g_sdk_initialized_via_pepper) { | 217 if (!g_sdk_initialized_via_pepper) { |
228 void* data = NULL; | 218 if (!chrome_pdf::InitializeSDK()) |
229 #if defined(OS_WIN) | |
230 data = g_hmodule; | |
231 #endif | |
232 if (!chrome_pdf::InitializeSDK(data)) | |
233 return false; | 219 return false; |
234 } | 220 } |
235 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 221 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
236 chrome_pdf::PDFEngineExports::Create()); | 222 chrome_pdf::PDFEngineExports::Create()); |
237 bool ret = engine_exports->GetPDFPageSizeByIndex( | 223 bool ret = engine_exports->GetPDFPageSizeByIndex( |
238 pdf_buffer, pdf_buffer_size, page_number, width, height); | 224 pdf_buffer, pdf_buffer_size, page_number, width, height); |
239 if (!g_sdk_initialized_via_pepper) | 225 if (!g_sdk_initialized_via_pepper) |
240 chrome_pdf::ShutdownSDK(); | 226 chrome_pdf::ShutdownSDK(); |
241 return ret; | 227 return ret; |
242 } | 228 } |
(...skipping 13 matching lines...) Expand all Loading... |
256 PDF_USED PP_EXPORT | 242 PDF_USED PP_EXPORT |
257 bool RenderPDFPageToBitmap(const void* pdf_buffer, | 243 bool RenderPDFPageToBitmap(const void* pdf_buffer, |
258 int pdf_buffer_size, | 244 int pdf_buffer_size, |
259 int page_number, | 245 int page_number, |
260 void* bitmap_buffer, | 246 void* bitmap_buffer, |
261 int bitmap_width, | 247 int bitmap_width, |
262 int bitmap_height, | 248 int bitmap_height, |
263 int dpi, | 249 int dpi, |
264 bool autorotate) { | 250 bool autorotate) { |
265 if (!g_sdk_initialized_via_pepper) { | 251 if (!g_sdk_initialized_via_pepper) { |
266 void* data = NULL; | 252 if (!chrome_pdf::InitializeSDK()) |
267 #if defined(OS_WIN) | |
268 data = g_hmodule; | |
269 #endif | |
270 if (!chrome_pdf::InitializeSDK(data)) | |
271 return false; | 253 return false; |
272 } | 254 } |
273 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 255 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
274 chrome_pdf::PDFEngineExports::Create()); | 256 chrome_pdf::PDFEngineExports::Create()); |
275 chrome_pdf::PDFEngineExports::RenderingSettings settings( | 257 chrome_pdf::PDFEngineExports::RenderingSettings settings( |
276 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true, | 258 dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true, |
277 autorotate); | 259 autorotate); |
278 bool ret = engine_exports->RenderPDFPageToBitmap( | 260 bool ret = engine_exports->RenderPDFPageToBitmap( |
279 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); | 261 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); |
280 if (!g_sdk_initialized_via_pepper) { | 262 if (!g_sdk_initialized_via_pepper) { |
281 chrome_pdf::ShutdownSDK(); | 263 chrome_pdf::ShutdownSDK(); |
282 } | 264 } |
283 return ret; | 265 return ret; |
284 } | 266 } |
285 | 267 |
286 } // extern "C" | 268 } // extern "C" |
OLD | NEW |