Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 int g_LastError; | 267 int g_LastError; |
| 268 void SetLastError(int err) { | 268 void SetLastError(int err) { |
| 269 g_LastError = err; | 269 g_LastError = err; |
| 270 } | 270 } |
| 271 | 271 |
| 272 int GetLastError() { | 272 int GetLastError() { |
| 273 return g_LastError; | 273 return g_LastError; |
| 274 } | 274 } |
| 275 #endif // _WIN32 | 275 #endif // _WIN32 |
| 276 | 276 |
| 277 void ProcessParseError(FX_DWORD err_code) { | 277 void ProcessParseError(CPDF_Parser::Error err) { |
| 278 FX_DWORD err_code; | |
| 278 // Translate FPDFAPI error code to FPDFVIEW error code | 279 // Translate FPDFAPI error code to FPDFVIEW error code |
| 279 switch (err_code) { | 280 switch (err) { |
| 280 case PDFPARSE_ERROR_FILE: | 281 case CPDF_Parser::SUCCESS: |
| 282 err_code = FPDF_ERR_SUCCESS; | |
|
Lei Zhang
2016/01/26 22:13:44
This is NOTREACHED(), BTW.
Tom Sepez
2016/01/26 22:19:35
It exists just to satisfy the all enums handled by
brucedawson
2016/02/03 19:49:08
Was clang giving a warning without this case? Argu
| |
| 283 break; | |
| 284 case CPDF_Parser::FILE_ERROR: | |
| 281 err_code = FPDF_ERR_FILE; | 285 err_code = FPDF_ERR_FILE; |
| 282 break; | 286 break; |
| 283 case PDFPARSE_ERROR_FORMAT: | 287 case CPDF_Parser::FORMAT_ERROR: |
| 284 err_code = FPDF_ERR_FORMAT; | 288 err_code = FPDF_ERR_FORMAT; |
| 285 break; | 289 break; |
| 286 case PDFPARSE_ERROR_PASSWORD: | 290 case CPDF_Parser::PASSWORD_ERROR: |
| 287 err_code = FPDF_ERR_PASSWORD; | 291 err_code = FPDF_ERR_PASSWORD; |
| 288 break; | 292 break; |
| 289 case PDFPARSE_ERROR_HANDLER: | 293 case CPDF_Parser::HANDLER_ERROR: |
| 290 err_code = FPDF_ERR_SECURITY; | 294 err_code = FPDF_ERR_SECURITY; |
| 291 break; | 295 break; |
| 292 } | 296 } |
| 293 SetLastError(err_code); | 297 SetLastError(err_code); |
| 294 } | 298 } |
| 295 | 299 |
| 296 DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, | 300 DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, |
| 297 FPDF_BOOL enable) { | 301 FPDF_BOOL enable) { |
| 298 return FSDK_SetSandBoxPolicy(policy, enable); | 302 return FSDK_SetSandBoxPolicy(policy, enable); |
| 299 } | 303 } |
| 300 | 304 |
| 301 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, | 305 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, |
| 302 FPDF_BYTESTRING password) { | 306 FPDF_BYTESTRING password) { |
| 303 // NOTE: the creation of the file needs to be by the embedder on the | 307 // NOTE: the creation of the file needs to be by the embedder on the |
| 304 // other side of this API. | 308 // other side of this API. |
| 305 IFX_FileRead* pFileAccess = FX_CreateFileRead((const FX_CHAR*)file_path); | 309 IFX_FileRead* pFileAccess = FX_CreateFileRead((const FX_CHAR*)file_path); |
| 306 if (!pFileAccess) { | 310 if (!pFileAccess) { |
| 307 return nullptr; | 311 return nullptr; |
| 308 } | 312 } |
| 309 | 313 |
| 310 CPDF_Parser* pParser = new CPDF_Parser; | 314 CPDF_Parser* pParser = new CPDF_Parser; |
| 311 pParser->SetPassword(password); | 315 pParser->SetPassword(password); |
| 312 | 316 |
| 313 FX_DWORD err_code = pParser->StartParse(pFileAccess); | 317 CPDF_Parser::Error error = pParser->StartParse(pFileAccess); |
| 314 if (err_code) { | 318 if (error != CPDF_Parser::SUCCESS) { |
| 315 delete pParser; | 319 delete pParser; |
| 316 ProcessParseError(err_code); | 320 ProcessParseError(error); |
| 317 return NULL; | 321 return NULL; |
| 318 } | 322 } |
| 319 #ifdef PDF_ENABLE_XFA | 323 #ifdef PDF_ENABLE_XFA |
| 320 CPDF_Document* pPDFDoc = pParser->GetDocument(); | 324 CPDF_Document* pPDFDoc = pParser->GetDocument(); |
| 321 if (!pPDFDoc) | 325 if (!pPDFDoc) |
| 322 return NULL; | 326 return NULL; |
| 323 | 327 |
| 324 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | 328 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
| 325 return new CPDFXFA_Document(pPDFDoc, pProvider); | 329 return new CPDFXFA_Document(pPDFDoc, pProvider); |
| 326 #else // PDF_ENABLE_XFA | 330 #else // PDF_ENABLE_XFA |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 uint8_t* const m_pBuf; | 396 uint8_t* const m_pBuf; |
| 393 const FX_FILESIZE m_size; | 397 const FX_FILESIZE m_size; |
| 394 }; | 398 }; |
| 395 | 399 |
| 396 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, | 400 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, |
| 397 int size, | 401 int size, |
| 398 FPDF_BYTESTRING password) { | 402 FPDF_BYTESTRING password) { |
| 399 CPDF_Parser* pParser = new CPDF_Parser; | 403 CPDF_Parser* pParser = new CPDF_Parser; |
| 400 pParser->SetPassword(password); | 404 pParser->SetPassword(password); |
| 401 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); | 405 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); |
| 402 FX_DWORD err_code = pParser->StartParse(pMemFile); | 406 CPDF_Parser::Error error = pParser->StartParse(pMemFile); |
| 403 if (err_code) { | 407 if (error != CPDF_Parser::SUCCESS) { |
| 404 delete pParser; | 408 delete pParser; |
| 405 ProcessParseError(err_code); | 409 ProcessParseError(error); |
| 406 return NULL; | 410 return NULL; |
| 407 } | 411 } |
| 408 CPDF_Document* pDoc = NULL; | 412 CPDF_Document* pDoc = NULL; |
| 409 pDoc = pParser ? pParser->GetDocument() : NULL; | 413 pDoc = pParser ? pParser->GetDocument() : NULL; |
| 410 CheckUnSupportError(pDoc, err_code); | 414 CheckUnSupportError(pDoc, error); |
|
Lei Zhang
2016/01/26 22:13:44
BTW, all the CheckUnSupportError() errors pass |er
Tom Sepez
2016/01/26 22:19:35
Thanks. Next time.
| |
| 411 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); | 415 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); |
| 412 } | 416 } |
| 413 | 417 |
| 414 DLLEXPORT FPDF_DOCUMENT STDCALL | 418 DLLEXPORT FPDF_DOCUMENT STDCALL |
| 415 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, | 419 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, |
| 416 FPDF_BYTESTRING password) { | 420 FPDF_BYTESTRING password) { |
| 417 CPDF_Parser* pParser = new CPDF_Parser; | 421 CPDF_Parser* pParser = new CPDF_Parser; |
| 418 pParser->SetPassword(password); | 422 pParser->SetPassword(password); |
| 419 CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); | 423 CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); |
| 420 FX_DWORD err_code = pParser->StartParse(pFile); | 424 CPDF_Parser::Error error = pParser->StartParse(pFile); |
| 421 if (err_code) { | 425 if (error != CPDF_Parser::SUCCESS) { |
| 422 delete pParser; | 426 delete pParser; |
| 423 ProcessParseError(err_code); | 427 ProcessParseError(error); |
| 424 return NULL; | 428 return NULL; |
| 425 } | 429 } |
| 426 CPDF_Document* pDoc = NULL; | 430 CPDF_Document* pDoc = NULL; |
| 427 pDoc = pParser ? pParser->GetDocument() : NULL; | 431 pDoc = pParser ? pParser->GetDocument() : NULL; |
| 428 CheckUnSupportError(pDoc, err_code); | 432 CheckUnSupportError(pDoc, error); |
| 429 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); | 433 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); |
| 430 } | 434 } |
| 431 | 435 |
| 432 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, | 436 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, |
| 433 int* fileVersion) { | 437 int* fileVersion) { |
| 434 if (!fileVersion) | 438 if (!fileVersion) |
| 435 return FALSE; | 439 return FALSE; |
| 436 | 440 |
| 437 *fileVersion = 0; | 441 *fileVersion = 0; |
| 438 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); | 442 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1189 if (!buffer) { | 1193 if (!buffer) { |
| 1190 *buflen = len; | 1194 *buflen = len; |
| 1191 } else if (*buflen >= len) { | 1195 } else if (*buflen >= len) { |
| 1192 memcpy(buffer, utf16Name.c_str(), len); | 1196 memcpy(buffer, utf16Name.c_str(), len); |
| 1193 *buflen = len; | 1197 *buflen = len; |
| 1194 } else { | 1198 } else { |
| 1195 *buflen = -1; | 1199 *buflen = -1; |
| 1196 } | 1200 } |
| 1197 return (FPDF_DEST)pDestObj; | 1201 return (FPDF_DEST)pDestObj; |
| 1198 } | 1202 } |
| OLD | NEW |