summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-01 13:54:42 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-01 13:54:42 -0800
commitbea049784abf7c32d0b9758fc77d0e601d5c232b (patch)
tree8cb30eec48538191531ead20100d4e696fa6ebef /fpdfsdk
parentaeeb6d19d1fc794de482826ecaf8ec2fd9e92d0e (diff)
downloadpdfium-bea049784abf7c32d0b9758fc77d0e601d5c232b.tar.xz
Make more concrete stream classes private to .cpp files
Review-Url: https://codereview.chromium.org/2545653003
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdfeditimg.cpp2
-rw-r--r--fpdfsdk/fpdfview.cpp68
-rw-r--r--fpdfsdk/fsdk_define.h16
3 files changed, 47 insertions, 39 deletions
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp
index da9f2b3909..2c869ac624 100644
--- a/fpdfsdk/fpdfeditimg.cpp
+++ b/fpdfsdk/fpdfeditimg.cpp
@@ -32,7 +32,7 @@ FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
if (!image_object || !fileAccess || !pages)
return false;
- IFX_SeekableReadStream* pFile = new CPDF_CustomAccess(fileAccess);
+ IFX_SeekableReadStream* pFile = MakeSeekableReadStream(fileAccess);
CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object);
for (int index = 0; index < nCount; index++) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 633cbe879e..449433ed90 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -117,6 +117,47 @@ void RenderPageImpl(CPDF_PageRenderContext* pContext,
pContext->m_pDevice->RestoreState(false);
}
+class CPDF_CustomAccess final : public IFX_SeekableReadStream {
+ public:
+ explicit CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess);
+ ~CPDF_CustomAccess() override {}
+
+ // IFX_SeekableReadStream
+ FX_FILESIZE GetSize() override;
+ void Release() override;
+ bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
+
+ private:
+ FPDF_FILEACCESS m_FileAccess;
+};
+
+CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
+ : m_FileAccess(*pFileAccess) {}
+
+FX_FILESIZE CPDF_CustomAccess::GetSize() {
+ return m_FileAccess.m_FileLen;
+}
+
+void CPDF_CustomAccess::Release() {
+ delete this;
+}
+
+bool CPDF_CustomAccess::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
+ if (offset < 0)
+ return false;
+
+ FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
+ newPos += offset;
+ if (!newPos.IsValid() ||
+ newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) {
+ return false;
+ }
+ return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,
+ reinterpret_cast<uint8_t*>(buffer), size);
+}
+
} // namespace
UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) {
@@ -246,31 +287,8 @@ bool CFPDF_FileStream::Flush() {
}
#endif // PDF_ENABLE_XFA
-CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
- : m_FileAccess(*pFileAccess) {}
-
-FX_FILESIZE CPDF_CustomAccess::GetSize() {
- return m_FileAccess.m_FileLen;
-}
-
-void CPDF_CustomAccess::Release() {
- delete this;
-}
-
-bool CPDF_CustomAccess::ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) {
- if (offset < 0)
- return false;
-
- FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
- newPos += offset;
- if (!newPos.IsValid() ||
- newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) {
- return false;
- }
- return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,
- reinterpret_cast<uint8_t*>(buffer), size);
+IFX_SeekableReadStream* MakeSeekableReadStream(FPDF_FILEACCESS* pFileAccess) {
+ return new CPDF_CustomAccess(pFileAccess);
}
// 0 bit: FPDF_POLICY_MACHINETIME_ACCESS
diff --git a/fpdfsdk/fsdk_define.h b/fpdfsdk/fsdk_define.h
index 3a75c84500..d878e54963 100644
--- a/fpdfsdk/fsdk_define.h
+++ b/fpdfsdk/fsdk_define.h
@@ -25,19 +25,9 @@ class CPDF_Page;
class CPDF_PageRenderContext;
class IFSDK_PAUSE_Adapter;
-class CPDF_CustomAccess final : public IFX_SeekableReadStream {
- public:
- explicit CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess);
- ~CPDF_CustomAccess() override {}
-
- // IFX_SeekableReadStream
- FX_FILESIZE GetSize() override;
- void Release() override;
- bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
-
- private:
- FPDF_FILEACCESS m_FileAccess;
-};
+// Layering prevents fxcrt from knowing about FPDF_FILEACCESS, so this can't
+// be a static method of IFX_SeekableReadStream.
+IFX_SeekableReadStream* MakeSeekableReadStream(FPDF_FILEACCESS* pFileAccess);
#ifdef PDF_ENABLE_XFA
class CFPDF_FileStream : public IFX_SeekableStream {