| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>( | 112 pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>( |
| 113 pContext->m_pContext.get(), pContext->m_pDevice.get(), | 113 pContext->m_pContext.get(), pContext->m_pDevice.get(), |
| 114 pContext->m_pOptions.get()); | 114 pContext->m_pOptions.get()); |
| 115 pContext->m_pRenderer->Start(pause); | 115 pContext->m_pRenderer->Start(pause); |
| 116 if (bNeedToRestore) | 116 if (bNeedToRestore) |
| 117 pContext->m_pDevice->RestoreState(false); | 117 pContext->m_pDevice->RestoreState(false); |
| 118 } | 118 } |
| 119 | 119 |
| 120 class CPDF_CustomAccess final : public IFX_SeekableReadStream { |
| 121 public: |
| 122 explicit CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess); |
| 123 ~CPDF_CustomAccess() override {} |
| 124 |
| 125 // IFX_SeekableReadStream |
| 126 FX_FILESIZE GetSize() override; |
| 127 void Release() override; |
| 128 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
| 129 |
| 130 private: |
| 131 FPDF_FILEACCESS m_FileAccess; |
| 132 }; |
| 133 |
| 134 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) |
| 135 : m_FileAccess(*pFileAccess) {} |
| 136 |
| 137 FX_FILESIZE CPDF_CustomAccess::GetSize() { |
| 138 return m_FileAccess.m_FileLen; |
| 139 } |
| 140 |
| 141 void CPDF_CustomAccess::Release() { |
| 142 delete this; |
| 143 } |
| 144 |
| 145 bool CPDF_CustomAccess::ReadBlock(void* buffer, |
| 146 FX_FILESIZE offset, |
| 147 size_t size) { |
| 148 if (offset < 0) |
| 149 return false; |
| 150 |
| 151 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size); |
| 152 newPos += offset; |
| 153 if (!newPos.IsValid() || |
| 154 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { |
| 155 return false; |
| 156 } |
| 157 return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, |
| 158 reinterpret_cast<uint8_t*>(buffer), size); |
| 159 } |
| 160 |
| 120 } // namespace | 161 } // namespace |
| 121 | 162 |
| 122 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { | 163 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { |
| 123 return static_cast<UnderlyingDocumentType*>(doc); | 164 return static_cast<UnderlyingDocumentType*>(doc); |
| 124 } | 165 } |
| 125 | 166 |
| 126 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { | 167 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { |
| 127 return static_cast<FPDF_DOCUMENT>(doc); | 168 return static_cast<FPDF_DOCUMENT>(doc); |
| 128 } | 169 } |
| 129 | 170 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 280 } |
| 240 | 281 |
| 241 bool CFPDF_FileStream::Flush() { | 282 bool CFPDF_FileStream::Flush() { |
| 242 if (!m_pFS || !m_pFS->Flush) | 283 if (!m_pFS || !m_pFS->Flush) |
| 243 return true; | 284 return true; |
| 244 | 285 |
| 245 return m_pFS->Flush(m_pFS->clientData) == 0; | 286 return m_pFS->Flush(m_pFS->clientData) == 0; |
| 246 } | 287 } |
| 247 #endif // PDF_ENABLE_XFA | 288 #endif // PDF_ENABLE_XFA |
| 248 | 289 |
| 249 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) | 290 IFX_SeekableReadStream* MakeSeekableReadStream(FPDF_FILEACCESS* pFileAccess) { |
| 250 : m_FileAccess(*pFileAccess) {} | 291 return new CPDF_CustomAccess(pFileAccess); |
| 251 | |
| 252 FX_FILESIZE CPDF_CustomAccess::GetSize() { | |
| 253 return m_FileAccess.m_FileLen; | |
| 254 } | |
| 255 | |
| 256 void CPDF_CustomAccess::Release() { | |
| 257 delete this; | |
| 258 } | |
| 259 | |
| 260 bool CPDF_CustomAccess::ReadBlock(void* buffer, | |
| 261 FX_FILESIZE offset, | |
| 262 size_t size) { | |
| 263 if (offset < 0) | |
| 264 return false; | |
| 265 | |
| 266 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size); | |
| 267 newPos += offset; | |
| 268 if (!newPos.IsValid() || | |
| 269 newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) { | |
| 270 return false; | |
| 271 } | |
| 272 return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset, | |
| 273 reinterpret_cast<uint8_t*>(buffer), size); | |
| 274 } | 292 } |
| 275 | 293 |
| 276 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS | 294 // 0 bit: FPDF_POLICY_MACHINETIME_ACCESS |
| 277 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; | 295 static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; |
| 278 | 296 |
| 279 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { | 297 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { |
| 280 switch (policy) { | 298 switch (policy) { |
| 281 case FPDF_POLICY_MACHINETIME_ACCESS: { | 299 case FPDF_POLICY_MACHINETIME_ACCESS: { |
| 282 if (enable) | 300 if (enable) |
| 283 foxit_sandbox_policy |= 0x01; | 301 foxit_sandbox_policy |= 0x01; |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 if (!buffer) { | 1195 if (!buffer) { |
| 1178 *buflen = len; | 1196 *buflen = len; |
| 1179 } else if (len <= *buflen) { | 1197 } else if (len <= *buflen) { |
| 1180 memcpy(buffer, utf16Name.c_str(), len); | 1198 memcpy(buffer, utf16Name.c_str(), len); |
| 1181 *buflen = len; | 1199 *buflen = len; |
| 1182 } else { | 1200 } else { |
| 1183 *buflen = -1; | 1201 *buflen = -1; |
| 1184 } | 1202 } |
| 1185 return (FPDF_DEST)pDestObj; | 1203 return (FPDF_DEST)pDestObj; |
| 1186 } | 1204 } |
| OLD | NEW |