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

Side by Side Diff: fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp

Issue 1921033003: Fixup page removal for XFA documents. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months 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
« no previous file with comments | « fpdfsdk/fpdfdoc_embeddertest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" 7 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if (m_pXFADoc) 147 if (m_pXFADoc)
148 return m_pXFADocView->CountPageViews(); 148 return m_pXFADocView->CountPageViews();
149 default: 149 default:
150 return 0; 150 return 0;
151 } 151 }
152 } 152 }
153 153
154 CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) { 154 CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) {
155 if (page_index < 0) 155 if (page_index < 0)
156 return nullptr; 156 return nullptr;
157
157 CPDFXFA_Page* pPage = nullptr; 158 CPDFXFA_Page* pPage = nullptr;
158 int nCount = m_XFAPageList.GetSize(); 159 int nCount = m_XFAPageList.GetSize();
159 if (nCount > 0 && page_index < nCount) { 160 if (nCount > 0 && page_index < nCount) {
160 pPage = m_XFAPageList.GetAt(page_index); 161 pPage = m_XFAPageList.GetAt(page_index);
161 if (pPage) 162 if (pPage)
162 pPage->AddRef(); 163 pPage->AddRef();
163 } else { 164 } else {
164 m_nPageCount = GetPageCount(); 165 m_nPageCount = GetPageCount();
165 m_XFAPageList.SetSize(m_nPageCount); 166 m_XFAPageList.SetSize(m_nPageCount);
166 } 167 }
167 if (pPage) 168 if (pPage)
168 return pPage; 169 return pPage;
170
169 pPage = new CPDFXFA_Page(this, page_index); 171 pPage = new CPDFXFA_Page(this, page_index);
170 if (!pPage->LoadPage()) { 172 if (!pPage->LoadPage()) {
171 pPage->Release(); 173 pPage->Release();
172 return nullptr; 174 return nullptr;
173 } 175 }
174 m_XFAPageList.SetAt(page_index, pPage); 176 m_XFAPageList.SetAt(page_index, pPage);
175 return pPage; 177 return pPage;
176 } 178 }
177 179
178 CPDFXFA_Page* CPDFXFA_Document::GetPage(CXFA_FFPageView* pPage) { 180 CPDFXFA_Page* CPDFXFA_Document::GetPage(CXFA_FFPageView* pPage) {
179 if (!pPage) 181 if (!pPage)
180 return NULL; 182 return nullptr;
181 183
182 if (!m_pXFADoc) 184 if (!m_pXFADoc)
183 return NULL; 185 return nullptr;
184 186
185 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) 187 if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
186 return NULL; 188 return nullptr;
187 189
188 int nSize = m_XFAPageList.GetSize(); 190 int nSize = m_XFAPageList.GetSize();
189 for (int i = 0; i < nSize; i++) { 191 for (int i = 0; i < nSize; i++) {
190 CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i); 192 CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i);
191 if (!pTempPage) 193 if (!pTempPage)
192 continue; 194 continue;
193 if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage) 195 if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage)
194 return pTempPage; 196 return pTempPage;
195 } 197 }
196 198
197 return NULL; 199 return nullptr;
198 } 200 }
199 201
200 void CPDFXFA_Document::DeletePage(int page_index) { 202 void CPDFXFA_Document::DeletePage(int page_index) {
203 // Delete from the document first because, if GetPage was never called for
204 // this |page_index| then |m_XFAPageList| may have size < |page_index| even
205 // if it's a valid page in the document.
206 if (m_pPDFDoc)
207 m_pPDFDoc->DeletePage(page_index);
208
201 if (page_index < 0 || page_index >= m_XFAPageList.GetSize()) 209 if (page_index < 0 || page_index >= m_XFAPageList.GetSize())
202 return; 210 return;
203 211
204 if (CPDFXFA_Page* pPage = m_XFAPageList.GetAt(page_index)) 212 if (CPDFXFA_Page* pPage = m_XFAPageList.GetAt(page_index))
205 pPage->Release(); 213 pPage->Release();
206 } 214 }
207 215
208 void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { 216 void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) {
209 m_XFAPageList.SetAt(page->GetPageIndex(), NULL); 217 m_XFAPageList.SetAt(page->GetPageIndex(), NULL);
210 } 218 }
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 } 1276 }
1269 1277
1270 return _GetHValueByName(szPropName, hValue, 1278 return _GetHValueByName(szPropName, hValue,
1271 m_pSDKDoc->GetEnv()->GetJSRuntime()); 1279 m_pSDKDoc->GetEnv()->GetJSRuntime());
1272 } 1280 }
1273 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name, 1281 FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name,
1274 FXJSE_HVALUE hValue, 1282 FXJSE_HVALUE hValue,
1275 IJS_Runtime* runTime) { 1283 IJS_Runtime* runTime) {
1276 return runTime->GetHValueByName(utf8Name, hValue); 1284 return runTime->GetHValueByName(utf8Name, hValue);
1277 } 1285 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfdoc_embeddertest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698