| 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 #include <utility> | 10 #include <utility> |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size); | 151 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size); |
| 152 newPos += offset; | 152 newPos += offset; |
| 153 if (!newPos.IsValid() || | 153 if (!newPos.IsValid() || |
| 154 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { | 154 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { |
| 155 return false; | 155 return false; |
| 156 } | 156 } |
| 157 return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, | 157 return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, |
| 158 reinterpret_cast<uint8_t*>(buffer), size); | 158 reinterpret_cast<uint8_t*>(buffer), size); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace | 161 #ifdef PDF_ENABLE_XFA |
| 162 class CFPDF_FileStream : public IFX_SeekableStream { |
| 163 public: |
| 164 explicit CFPDF_FileStream(FPDF_FILEHANDLER* pFS); |
| 165 ~CFPDF_FileStream() override {} |
| 162 | 166 |
| 163 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { | 167 // IFX_SeekableStream: |
| 164 return static_cast<UnderlyingDocumentType*>(doc); | 168 IFX_SeekableStream* Retain() override; |
| 165 } | 169 void Release() override; |
| 170 FX_FILESIZE GetSize() override; |
| 171 bool IsEOF() override; |
| 172 FX_FILESIZE GetPosition() override; |
| 173 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
| 174 size_t ReadBlock(void* buffer, size_t size) override; |
| 175 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; |
| 176 bool Flush() override; |
| 166 | 177 |
| 167 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { | 178 void SetPosition(FX_FILESIZE pos) { m_nCurPos = pos; } |
| 168 return static_cast<FPDF_DOCUMENT>(doc); | |
| 169 } | |
| 170 | 179 |
| 171 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { | 180 protected: |
| 172 return static_cast<UnderlyingPageType*>(page); | 181 FPDF_FILEHANDLER* m_pFS; |
| 173 } | 182 FX_FILESIZE m_nCurPos; |
| 183 }; |
| 174 | 184 |
| 175 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { | |
| 176 #ifdef PDF_ENABLE_XFA | |
| 177 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; | |
| 178 #else // PDF_ENABLE_XFA | |
| 179 return UnderlyingFromFPDFDocument(doc); | |
| 180 #endif // PDF_ENABLE_XFA | |
| 181 } | |
| 182 | |
| 183 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { | |
| 184 #ifdef PDF_ENABLE_XFA | |
| 185 return doc ? FPDFDocumentFromUnderlying( | |
| 186 new CPDFXFA_Context(pdfium::WrapUnique(doc))) | |
| 187 : nullptr; | |
| 188 #else // PDF_ENABLE_XFA | |
| 189 return FPDFDocumentFromUnderlying(doc); | |
| 190 #endif // PDF_ENABLE_XFA | |
| 191 } | |
| 192 | |
| 193 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | |
| 194 #ifdef PDF_ENABLE_XFA | |
| 195 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; | |
| 196 #else // PDF_ENABLE_XFA | |
| 197 return UnderlyingFromFPDFPage(page); | |
| 198 #endif // PDF_ENABLE_XFA | |
| 199 } | |
| 200 | |
| 201 CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) { | |
| 202 return static_cast<CFX_DIBitmap*>(bitmap); | |
| 203 } | |
| 204 | |
| 205 #ifdef PDF_ENABLE_XFA | |
| 206 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { | 185 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { |
| 207 m_pFS = pFS; | 186 m_pFS = pFS; |
| 208 m_nCurPos = 0; | 187 m_nCurPos = 0; |
| 209 } | 188 } |
| 210 | 189 |
| 211 IFX_SeekableStream* CFPDF_FileStream::Retain() { | 190 IFX_SeekableStream* CFPDF_FileStream::Retain() { |
| 212 return this; | 191 return this; |
| 213 } | 192 } |
| 214 | 193 |
| 215 void CFPDF_FileStream::Release() { | 194 void CFPDF_FileStream::Release() { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 259 } |
| 281 | 260 |
| 282 bool CFPDF_FileStream::Flush() { | 261 bool CFPDF_FileStream::Flush() { |
| 283 if (!m_pFS || !m_pFS->Flush) | 262 if (!m_pFS || !m_pFS->Flush) |
| 284 return true; | 263 return true; |
| 285 | 264 |
| 286 return m_pFS->Flush(m_pFS->clientData) == 0; | 265 return m_pFS->Flush(m_pFS->clientData) == 0; |
| 287 } | 266 } |
| 288 #endif // PDF_ENABLE_XFA | 267 #endif // PDF_ENABLE_XFA |
| 289 | 268 |
| 269 } // namespace |
| 270 |
| 271 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { |
| 272 return static_cast<UnderlyingDocumentType*>(doc); |
| 273 } |
| 274 |
| 275 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { |
| 276 return static_cast<FPDF_DOCUMENT>(doc); |
| 277 } |
| 278 |
| 279 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { |
| 280 return static_cast<UnderlyingPageType*>(page); |
| 281 } |
| 282 |
| 283 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { |
| 284 #ifdef PDF_ENABLE_XFA |
| 285 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; |
| 286 #else // PDF_ENABLE_XFA |
| 287 return UnderlyingFromFPDFDocument(doc); |
| 288 #endif // PDF_ENABLE_XFA |
| 289 } |
| 290 |
| 291 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { |
| 292 #ifdef PDF_ENABLE_XFA |
| 293 return doc ? FPDFDocumentFromUnderlying( |
| 294 new CPDFXFA_Context(pdfium::WrapUnique(doc))) |
| 295 : nullptr; |
| 296 #else // PDF_ENABLE_XFA |
| 297 return FPDFDocumentFromUnderlying(doc); |
| 298 #endif // PDF_ENABLE_XFA |
| 299 } |
| 300 |
| 301 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
| 302 #ifdef PDF_ENABLE_XFA |
| 303 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; |
| 304 #else // PDF_ENABLE_XFA |
| 305 return UnderlyingFromFPDFPage(page); |
| 306 #endif // PDF_ENABLE_XFA |
| 307 } |
| 308 |
| 309 CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) { |
| 310 return static_cast<CFX_DIBitmap*>(bitmap); |
| 311 } |
| 312 |
| 290 IFX_SeekableReadStream* MakeSeekableReadStream(FPDF_FILEACCESS* pFileAccess) { | 313 IFX_SeekableReadStream* MakeSeekableReadStream(FPDF_FILEACCESS* pFileAccess) { |
| 291 return new CPDF_CustomAccess(pFileAccess); | 314 return new CPDF_CustomAccess(pFileAccess); |
| 292 } | 315 } |
| 293 | 316 |
| 317 #ifdef PDF_ENABLE_XFA |
| 318 IFX_SeekableStream* MakeSeekableStream(FPDF_FILEHANDLER* pFilehandler) { |
| 319 return new CFPDF_FileStream(pFilehandler); |
| 320 } |
| 321 #endif // PDF_ENABLE_XFA |
| 322 |
| 294 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS | 323 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS |
| 295 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; | 324 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; |
| 296 | 325 |
| 297 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { | 326 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { |
| 298 switch (policy) { | 327 switch (policy) { |
| 299 case FPDF_POLICY_MACHINETIME_ACCESS: { | 328 case FPDF_POLICY_MACHINETIME_ACCESS: { |
| 300 if (enable) | 329 if (enable) |
| 301 foxit_sandbox_policy |= 0x01; | 330 foxit_sandbox_policy |= 0x01; |
| 302 else | 331 else |
| 303 foxit_sandbox_policy &= 0xFFFFFFFE; | 332 foxit_sandbox_policy &= 0xFFFFFFFE; |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 if (!buffer) { | 1224 if (!buffer) { |
| 1196 *buflen = len; | 1225 *buflen = len; |
| 1197 } else if (len <= *buflen) { | 1226 } else if (len <= *buflen) { |
| 1198 memcpy(buffer, utf16Name.c_str(), len); | 1227 memcpy(buffer, utf16Name.c_str(), len); |
| 1199 *buflen = len; | 1228 *buflen = len; |
| 1200 } else { | 1229 } else { |
| 1201 *buflen = -1; | 1230 *buflen = -1; |
| 1202 } | 1231 } |
| 1203 return (FPDF_DEST)pDestObj; | 1232 return (FPDF_DEST)pDestObj; |
| 1204 } | 1233 } |
| OLD | NEW |