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

Side by Side Diff: xfa/fxfa/app/xfa_ffapp.cpp

Issue 2430743003: in the attempt to fix 627393, changed IFX_FileRead's readBlock to return the length it reads
Patch Set: fix an undefined variable Created 4 years, 1 month 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
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 "xfa/fxfa/xfa_ffapp.h" 7 #include "xfa/fxfa/xfa_ffapp.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
11 11
12 #include "xfa/fgas/font/fgas_stdfontmgr.h" 12 #include "xfa/fgas/font/fgas_stdfontmgr.h"
13 #include "xfa/fwl/core/cfwl_widgetmgr.h" 13 #include "xfa/fwl/core/cfwl_widgetmgr.h"
14 #include "xfa/fwl/core/fwl_noteimp.h" 14 #include "xfa/fwl/core/fwl_noteimp.h"
15 #include "xfa/fxfa/app/xfa_fwladapter.h" 15 #include "xfa/fxfa/app/xfa_fwladapter.h"
16 #include "xfa/fxfa/app/xfa_fwltheme.h" 16 #include "xfa/fxfa/app/xfa_fwltheme.h"
17 #include "xfa/fxfa/xfa_ffdoc.h" 17 #include "xfa/fxfa/xfa_ffdoc.h"
18 #include "xfa/fxfa/xfa_ffdochandler.h" 18 #include "xfa/fxfa/xfa_ffdochandler.h"
19 #include "xfa/fxfa/xfa_ffwidgethandler.h" 19 #include "xfa/fxfa/xfa_ffwidgethandler.h"
20 #include "xfa/fxfa/xfa_fontmgr.h" 20 #include "xfa/fxfa/xfa_fontmgr.h"
21 21
22 CXFA_FileRead::CXFA_FileRead(const std::vector<CPDF_Stream*>& streams) { 22 CXFA_FileRead::CXFA_FileRead(const std::vector<CPDF_Stream*>& streams) {
23 m_FileSize = 0;
24 m_nCurPos = 0;
23 for (CPDF_Stream* pStream : streams) { 25 for (CPDF_Stream* pStream : streams) {
24 CPDF_StreamAcc& acc = m_Data.Add(); 26 CPDF_StreamAcc& acc = m_Data.Add();
25 acc.LoadAllData(pStream); 27 acc.LoadAllData(pStream);
28 m_FileSize += pdfium::base::checked_cast<FX_FILESIZE>(acc.GetSize());
26 } 29 }
27 } 30 }
28 31
29 CXFA_FileRead::~CXFA_FileRead() {} 32 CXFA_FileRead::~CXFA_FileRead() {}
30 33
31 FX_FILESIZE CXFA_FileRead::GetSize() { 34 bool CXFA_FileRead::IsEOF() {
32 uint32_t dwSize = 0; 35 return m_nCurPos >= GetSize();
33 int32_t iCount = m_Data.GetSize();
34 for (int32_t i = 0; i < iCount; i++) {
35 CPDF_StreamAcc& acc = m_Data[i];
36 dwSize += acc.GetSize();
37 }
38 return dwSize;
39 } 36 }
40 37
41 bool CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { 38 FX_FILESIZE CXFA_FileRead::GetSize() {
39 return m_FileSize;
40 }
41
42 size_t CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) {
43 if (offset < 0 || GetSize() < offset) {
44 return 0;
45 }
46 size_t readSize =
47 std::min(pdfium::base::checked_cast<size_t>(GetSize() - offset), size);
42 int32_t iCount = m_Data.GetSize(); 48 int32_t iCount = m_Data.GetSize();
43 int32_t index = 0; 49 int32_t index = 0;
44 while (index < iCount) { 50 while (index < iCount) {
45 CPDF_StreamAcc& acc = m_Data[index]; 51 CPDF_StreamAcc& acc = m_Data[index];
46 FX_FILESIZE dwSize = acc.GetSize(); 52 FX_FILESIZE dwSize = acc.GetSize();
47 if (offset < dwSize) { 53 if (offset < dwSize) {
48 break; 54 break;
49 } 55 }
50 offset -= dwSize; 56 offset -= dwSize;
51 index++; 57 index++;
52 } 58 }
53 while (index < iCount) { 59 while (index < iCount) {
54 CPDF_StreamAcc& acc = m_Data[index]; 60 CPDF_StreamAcc& acc = m_Data[index];
55 uint32_t dwSize = acc.GetSize(); 61 uint32_t dwSize = acc.GetSize();
56 size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset)); 62 size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset));
57 FXSYS_memcpy(buffer, acc.GetData() + offset, dwRead); 63 FXSYS_memcpy(buffer, acc.GetData() + offset, dwRead);
58 size -= dwRead; 64 size -= dwRead;
59 if (size == 0) { 65 if (size == 0) {
60 return true; 66 break;
61 } 67 }
62 buffer = (uint8_t*)buffer + dwRead; 68 buffer = (uint8_t*)buffer + dwRead;
63 offset = 0; 69 offset = 0;
64 index++; 70 index++;
65 } 71 }
66 return false; 72 return readSize;
67 } 73 }
68 74
69 void CXFA_FileRead::Release() { 75 void CXFA_FileRead::Release() {
70 delete this; 76 delete this;
71 } 77 }
72 78
73 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) 79 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider)
74 : m_pProvider(pProvider), 80 : m_pProvider(pProvider),
75 m_pWidgetMgrDelegate(nullptr), 81 m_pWidgetMgrDelegate(nullptr),
76 m_pFWLApp(new IFWL_App(this)) { 82 m_pFWLApp(new IFWL_App(this)) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return m_pAdapterWidgetMgr.get(); 150 return m_pAdapterWidgetMgr.get();
145 } 151 }
146 152
147 IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() const { 153 IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() const {
148 return m_pProvider->GetTimerMgr(); 154 return m_pProvider->GetTimerMgr();
149 } 155 }
150 156
151 void CXFA_FFApp::ClearEventTargets() { 157 void CXFA_FFApp::ClearEventTargets() {
152 m_pFWLApp->GetNoteDriver()->ClearEventTargets(false); 158 m_pFWLApp->GetNoteDriver()->ClearEventTargets(false);
153 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698