summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-12 11:32:32 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-12 17:23:27 +0000
commit9d6a2089c93c94461289b21a29771039eace95e7 (patch)
tree5b747786fe129b20aaf2ba3271e7b99051f5ae99 /xfa/fxfa
parentb333c9ec415c132451f4a10487b84f91124d08e8 (diff)
downloadpdfium-9d6a2089c93c94461289b21a29771039eace95e7.tar.xz
Remove MakeSeekableReadStream
This Cl removes the MakeSeekableReadStream call and, at the one place it's used, creates an IFX_MemoryStream which is a seekable read stream. Change-Id: I6b0b23636eff47f8caca5432313ba99703e21e4d Reviewed-on: https://pdfium-review.googlesource.com/4037 Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/cxfa_ffapp.cpp66
-rw-r--r--xfa/fxfa/cxfa_ffapp.h5
-rw-r--r--xfa/fxfa/cxfa_ffapp_unittest.cpp10
-rw-r--r--xfa/fxfa/cxfa_ffdoc.cpp3
-rw-r--r--xfa/fxfa/cxfa_fileread.cpp56
-rw-r--r--xfa/fxfa/cxfa_fileread.h31
6 files changed, 93 insertions, 78 deletions
diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp
index 7b88626c91..c02fd30e86 100644
--- a/xfa/fxfa/cxfa_ffapp.cpp
+++ b/xfa/fxfa/cxfa_ffapp.cpp
@@ -23,72 +23,6 @@
#include "xfa/fxfa/cxfa_ffwidgethandler.h"
#include "xfa/fxfa/cxfa_fontmgr.h"
-namespace {
-
-class CXFA_FileRead : public IFX_SeekableReadStream {
- public:
- explicit CXFA_FileRead(const std::vector<CPDF_Stream*>& streams);
- ~CXFA_FileRead() override;
-
- // IFX_SeekableReadStream
- FX_FILESIZE GetSize() override;
- bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
-
- private:
- std::vector<CFX_RetainPtr<CPDF_StreamAcc>> m_Data;
-};
-
-CXFA_FileRead::CXFA_FileRead(const std::vector<CPDF_Stream*>& streams) {
- for (CPDF_Stream* pStream : streams) {
- m_Data.push_back(pdfium::MakeRetain<CPDF_StreamAcc>(pStream));
- m_Data.back()->LoadAllData();
- }
-}
-
-CXFA_FileRead::~CXFA_FileRead() {}
-
-FX_FILESIZE CXFA_FileRead::GetSize() {
- uint32_t dwSize = 0;
- for (const auto& acc : m_Data)
- dwSize += acc->GetSize();
- return dwSize;
-}
-
-bool CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) {
- int32_t iCount = pdfium::CollectionSize<int32_t>(m_Data);
- int32_t index = 0;
- while (index < iCount) {
- const auto& acc = m_Data[index];
- FX_FILESIZE dwSize = acc->GetSize();
- if (offset < dwSize)
- break;
-
- offset -= dwSize;
- index++;
- }
- while (index < iCount) {
- const auto& acc = m_Data[index];
- uint32_t dwSize = acc->GetSize();
- size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset));
- memcpy(buffer, acc->GetData() + offset, dwRead);
- size -= dwRead;
- if (size == 0)
- return true;
-
- buffer = (uint8_t*)buffer + dwRead;
- offset = 0;
- index++;
- }
- return false;
-}
-
-} // namespace
-
-CFX_RetainPtr<IFX_SeekableReadStream> MakeSeekableReadStream(
- const std::vector<CPDF_Stream*>& streams) {
- return CFX_RetainPtr<IFX_SeekableReadStream>(new CXFA_FileRead(streams));
-}
-
CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider)
: m_pProvider(pProvider),
m_pWidgetMgrDelegate(nullptr),
diff --git a/xfa/fxfa/cxfa_ffapp.h b/xfa/fxfa/cxfa_ffapp.h
index 01235d655b..0a6409d3d1 100644
--- a/xfa/fxfa/cxfa_ffapp.h
+++ b/xfa/fxfa/cxfa_ffapp.h
@@ -25,11 +25,6 @@ class CXFA_FontMgr;
class IFWL_AdapterTimerMgr;
class CFWL_WidgetMgrDelegate;
-// Layering prevents fxcrt from knowing about CPDF_Streams; this could go
-// in fpdfsdk, but it is XFA-Only.
-CFX_RetainPtr<IFX_SeekableReadStream> MakeSeekableReadStream(
- const std::vector<CPDF_Stream*>& streams);
-
class CXFA_FFApp {
public:
explicit CXFA_FFApp(IXFA_AppProvider* pProvider);
diff --git a/xfa/fxfa/cxfa_ffapp_unittest.cpp b/xfa/fxfa/cxfa_ffapp_unittest.cpp
index 4d65ccbb2f..fc1d038bac 100644
--- a/xfa/fxfa/cxfa_ffapp_unittest.cpp
+++ b/xfa/fxfa/cxfa_ffapp_unittest.cpp
@@ -13,13 +13,13 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
#include "third_party/base/ptr_util.h"
+#include "xfa/fxfa/cxfa_fileread.h"
class CXFAFileReadTest : public pdfium::FPDF_Test {};
TEST_F(CXFAFileReadTest, NoStreams) {
std::vector<CPDF_Stream*> streams;
- CFX_RetainPtr<IFX_SeekableReadStream> fileread =
- MakeSeekableReadStream(streams);
+ auto fileread = pdfium::MakeRetain<CXFA_FileRead>(streams);
uint8_t output_buffer[16];
memset(output_buffer, 0xbd, sizeof(output_buffer));
@@ -31,8 +31,7 @@ TEST_F(CXFAFileReadTest, EmptyStreams) {
std::vector<CPDF_Stream*> streams;
auto stream1 = pdfium::MakeUnique<CPDF_Stream>();
streams.push_back(stream1.get());
- CFX_RetainPtr<IFX_SeekableReadStream> fileread =
- MakeSeekableReadStream(streams);
+ auto fileread = pdfium::MakeRetain<CXFA_FileRead>(streams);
uint8_t output_buffer[16];
memset(output_buffer, 0xbd, sizeof(output_buffer));
@@ -57,8 +56,7 @@ TEST_F(CXFAFileReadTest, NormalStreams) {
streams.push_back(stream1.get());
streams.push_back(stream2.get());
streams.push_back(stream3.get());
- CFX_RetainPtr<IFX_SeekableReadStream> fileread =
- MakeSeekableReadStream(streams);
+ auto fileread = pdfium::MakeRetain<CXFA_FileRead>(streams);
uint8_t output_buffer[16];
memset(output_buffer, 0xbd, sizeof(output_buffer));
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index 4b6a1e2e07..2bbdfa1b9c 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -25,6 +25,7 @@
#include "xfa/fxfa/cxfa_ffapp.h"
#include "xfa/fxfa/cxfa_ffdocview.h"
#include "xfa/fxfa/cxfa_ffwidget.h"
+#include "xfa/fxfa/cxfa_fileread.h"
#include "xfa/fxfa/cxfa_fontmgr.h"
#include "xfa/fxfa/parser/cxfa_dataexporter.h"
#include "xfa/fxfa/parser/cxfa_dataimporter.h"
@@ -315,7 +316,7 @@ bool CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) {
return false;
m_pPDFDoc = pPDFDoc;
- m_pStream = MakeSeekableReadStream(xfaStreams);
+ m_pStream = pdfium::MakeRetain<CXFA_FileRead>(xfaStreams);
return true;
}
diff --git a/xfa/fxfa/cxfa_fileread.cpp b/xfa/fxfa/cxfa_fileread.cpp
new file mode 100644
index 0000000000..e2ecad2e93
--- /dev/null
+++ b/xfa/fxfa/cxfa_fileread.cpp
@@ -0,0 +1,56 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fxfa/cxfa_fileread.h"
+
+#include <algorithm>
+
+#include "core/fpdfapi/parser/cpdf_stream_acc.h"
+#include "third_party/base/stl_util.h"
+
+CXFA_FileRead::CXFA_FileRead(const std::vector<CPDF_Stream*>& streams) {
+ for (CPDF_Stream* pStream : streams) {
+ m_Data.push_back(pdfium::MakeRetain<CPDF_StreamAcc>(pStream));
+ m_Data.back()->LoadAllData();
+ }
+}
+
+CXFA_FileRead::~CXFA_FileRead() {}
+
+FX_FILESIZE CXFA_FileRead::GetSize() {
+ uint32_t dwSize = 0;
+ for (const auto& acc : m_Data)
+ dwSize += acc->GetSize();
+ return dwSize;
+}
+
+bool CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) {
+ int32_t iCount = pdfium::CollectionSize<int32_t>(m_Data);
+ int32_t index = 0;
+ while (index < iCount) {
+ const auto& acc = m_Data[index];
+ FX_FILESIZE dwSize = acc->GetSize();
+ if (offset < dwSize)
+ break;
+
+ offset -= dwSize;
+ index++;
+ }
+ while (index < iCount) {
+ const auto& acc = m_Data[index];
+ uint32_t dwSize = acc->GetSize();
+ size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset));
+ memcpy(buffer, acc->GetData() + offset, dwRead);
+ size -= dwRead;
+ if (size == 0)
+ return true;
+
+ buffer = static_cast<uint8_t*>(buffer) + dwRead;
+ offset = 0;
+ index++;
+ }
+ return false;
+}
diff --git a/xfa/fxfa/cxfa_fileread.h b/xfa/fxfa/cxfa_fileread.h
new file mode 100644
index 0000000000..0c3348b8d5
--- /dev/null
+++ b/xfa/fxfa/cxfa_fileread.h
@@ -0,0 +1,31 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef XFA_FXFA_CXFA_FILEREAD_H_
+#define XFA_FXFA_CXFA_FILEREAD_H_
+
+#include <vector>
+
+#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/fx_stream.h"
+
+class CPDF_Stream;
+class CPDF_StreamAcc;
+
+class CXFA_FileRead : public IFX_SeekableReadStream {
+ public:
+ explicit CXFA_FileRead(const std::vector<CPDF_Stream*>& streams);
+ ~CXFA_FileRead() override;
+
+ // IFX_SeekableReadStream
+ FX_FILESIZE GetSize() override;
+ bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
+
+ private:
+ std::vector<CFX_RetainPtr<CPDF_StreamAcc>> m_Data;
+};
+
+#endif // XFA_FXFA_CXFA_FILEREAD_H_