Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: fpdfsdk/src/fpdfview.cpp

Issue 1640473002: Merge to Master: War on #defines - part 2 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Pick up build fix. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fpdf_dataavail.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 int g_LastError; 125 int g_LastError;
126 void SetLastError(int err) { 126 void SetLastError(int err) {
127 g_LastError = err; 127 g_LastError = err;
128 } 128 }
129 129
130 int GetLastError() { 130 int GetLastError() {
131 return g_LastError; 131 return g_LastError;
132 } 132 }
133 #endif 133 #endif
134 134
135 void ProcessParseError(FX_DWORD err_code) { 135 void ProcessParseError(CPDF_Parser::Error err) {
136 FX_DWORD err_code;
136 // Translate FPDFAPI error code to FPDFVIEW error code 137 // Translate FPDFAPI error code to FPDFVIEW error code
137 switch (err_code) { 138 switch (err) {
138 case PDFPARSE_ERROR_FILE: 139 case CPDF_Parser::SUCCESS:
140 err_code = FPDF_ERR_SUCCESS;
141 break;
142 case CPDF_Parser::FILE_ERROR:
139 err_code = FPDF_ERR_FILE; 143 err_code = FPDF_ERR_FILE;
140 break; 144 break;
141 case PDFPARSE_ERROR_FORMAT: 145 case CPDF_Parser::FORMAT_ERROR:
142 err_code = FPDF_ERR_FORMAT; 146 err_code = FPDF_ERR_FORMAT;
143 break; 147 break;
144 case PDFPARSE_ERROR_PASSWORD: 148 case CPDF_Parser::PASSWORD_ERROR:
145 err_code = FPDF_ERR_PASSWORD; 149 err_code = FPDF_ERR_PASSWORD;
146 break; 150 break;
147 case PDFPARSE_ERROR_HANDLER: 151 case CPDF_Parser::HANDLER_ERROR:
148 err_code = FPDF_ERR_SECURITY; 152 err_code = FPDF_ERR_SECURITY;
149 break; 153 break;
150 } 154 }
151 SetLastError(err_code); 155 SetLastError(err_code);
152 } 156 }
153 157
154 DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, 158 DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy,
155 FPDF_BOOL enable) { 159 FPDF_BOOL enable) {
156 return FSDK_SetSandBoxPolicy(policy, enable); 160 return FSDK_SetSandBoxPolicy(policy, enable);
157 } 161 }
158 162
159 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, 163 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path,
160 FPDF_BYTESTRING password) { 164 FPDF_BYTESTRING password) {
161 // NOTE: the creation of the file needs to be by the embedder on the 165 // NOTE: the creation of the file needs to be by the embedder on the
162 // other side of this API. 166 // other side of this API.
163 IFX_FileRead* pFileAccess = FX_CreateFileRead((const FX_CHAR*)file_path); 167 IFX_FileRead* pFileAccess = FX_CreateFileRead((const FX_CHAR*)file_path);
164 if (!pFileAccess) { 168 if (!pFileAccess) {
165 return nullptr; 169 return nullptr;
166 } 170 }
167 171
168 CPDF_Parser* pParser = new CPDF_Parser; 172 CPDF_Parser* pParser = new CPDF_Parser;
169 pParser->SetPassword(password); 173 pParser->SetPassword(password);
170 174
171 FX_DWORD err_code = pParser->StartParse(pFileAccess); 175 CPDF_Parser::Error error = pParser->StartParse(pFileAccess);
172 if (err_code) { 176 if (error != CPDF_Parser::SUCCESS) {
173 delete pParser; 177 delete pParser;
174 ProcessParseError(err_code); 178 ProcessParseError(error);
175 return NULL; 179 return NULL;
176 } 180 }
177 return pParser->GetDocument(); 181 return pParser->GetDocument();
178 } 182 }
179 183
180 class CMemFile final : public IFX_FileRead { 184 class CMemFile final : public IFX_FileRead {
181 public: 185 public:
182 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} 186 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {}
183 187
184 void Release() override { delete this; } 188 void Release() override { delete this; }
(...skipping 18 matching lines...) Expand all
203 uint8_t* const m_pBuf; 207 uint8_t* const m_pBuf;
204 const FX_FILESIZE m_size; 208 const FX_FILESIZE m_size;
205 }; 209 };
206 210
207 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, 211 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf,
208 int size, 212 int size,
209 FPDF_BYTESTRING password) { 213 FPDF_BYTESTRING password) {
210 CPDF_Parser* pParser = new CPDF_Parser; 214 CPDF_Parser* pParser = new CPDF_Parser;
211 pParser->SetPassword(password); 215 pParser->SetPassword(password);
212 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); 216 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size);
213 FX_DWORD err_code = pParser->StartParse(pMemFile); 217 CPDF_Parser::Error error = pParser->StartParse(pMemFile);
214 if (err_code) { 218 if (error != CPDF_Parser::SUCCESS) {
215 delete pParser; 219 delete pParser;
216 ProcessParseError(err_code); 220 ProcessParseError(error);
217 return NULL; 221 return NULL;
218 } 222 }
219 CPDF_Document* pDoc = NULL; 223 CPDF_Document* pDoc = NULL;
220 pDoc = pParser ? pParser->GetDocument() : NULL; 224 pDoc = pParser ? pParser->GetDocument() : NULL;
221 CheckUnSupportError(pDoc, err_code); 225 CheckUnSupportError(pDoc, error);
222 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); 226 return FPDFDocumentFromCPDFDocument(pParser->GetDocument());
223 } 227 }
224 228
225 DLLEXPORT FPDF_DOCUMENT STDCALL 229 DLLEXPORT FPDF_DOCUMENT STDCALL
226 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, 230 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess,
227 FPDF_BYTESTRING password) { 231 FPDF_BYTESTRING password) {
228 CPDF_Parser* pParser = new CPDF_Parser; 232 CPDF_Parser* pParser = new CPDF_Parser;
229 pParser->SetPassword(password); 233 pParser->SetPassword(password);
230 CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); 234 CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess);
231 FX_DWORD err_code = pParser->StartParse(pFile); 235 CPDF_Parser::Error error = pParser->StartParse(pFile);
232 if (err_code) { 236 if (error != CPDF_Parser::SUCCESS) {
233 delete pParser; 237 delete pParser;
234 ProcessParseError(err_code); 238 ProcessParseError(error);
235 return NULL; 239 return NULL;
236 } 240 }
237 CPDF_Document* pDoc = NULL; 241 CPDF_Document* pDoc = NULL;
238 pDoc = pParser ? pParser->GetDocument() : NULL; 242 pDoc = pParser ? pParser->GetDocument() : NULL;
239 CheckUnSupportError(pDoc, err_code); 243 CheckUnSupportError(pDoc, error);
240 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); 244 return FPDFDocumentFromCPDFDocument(pParser->GetDocument());
241 } 245 }
242 246
243 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, 247 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
244 int* fileVersion) { 248 int* fileVersion) {
245 if (!fileVersion) 249 if (!fileVersion)
246 return FALSE; 250 return FALSE;
247 251
248 *fileVersion = 0; 252 *fileVersion = 0;
249 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); 253 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc);
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 if (!buffer) { 917 if (!buffer) {
914 *buflen = len; 918 *buflen = len;
915 } else if (*buflen >= len) { 919 } else if (*buflen >= len) {
916 memcpy(buffer, utf16Name.c_str(), len); 920 memcpy(buffer, utf16Name.c_str(), len);
917 *buflen = len; 921 *buflen = len;
918 } else { 922 } else {
919 *buflen = -1; 923 *buflen = -1;
920 } 924 }
921 return (FPDF_DEST)pDestObj; 925 return (FPDF_DEST)pDestObj;
922 } 926 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdf_dataavail.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698