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 "fpdfsdk/javascript/Document.h" | 7 #include "fpdfsdk/javascript/Document.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 */ | 151 */ |
152 | 152 |
153 Document::Document(CJS_Object* pJSObject) | 153 Document::Document(CJS_Object* pJSObject) |
154 : CJS_EmbedObj(pJSObject), | 154 : CJS_EmbedObj(pJSObject), |
155 m_isolate(NULL), | 155 m_isolate(NULL), |
156 m_pDocument(NULL), | 156 m_pDocument(NULL), |
157 m_cwBaseURL(L""), | 157 m_cwBaseURL(L""), |
158 m_bDelay(FALSE) {} | 158 m_bDelay(FALSE) {} |
159 | 159 |
160 Document::~Document() { | 160 Document::~Document() { |
161 for (int i = 0; i < m_DelayData.GetSize(); i++) { | |
162 delete m_DelayData.GetAt(i); | |
163 } | |
164 | |
165 m_DelayData.RemoveAll(); | |
166 } | 161 } |
167 | 162 |
168 // the total number of fileds in document. | 163 // the total number of fileds in document. |
169 FX_BOOL Document::numFields(IJS_Context* cc, | 164 FX_BOOL Document::numFields(IJS_Context* cc, |
170 CJS_PropValue& vp, | 165 CJS_PropValue& vp, |
171 CFX_WideString& sError) { | 166 CFX_WideString& sError) { |
172 if (vp.IsSetting()) { | 167 if (vp.IsSetting()) { |
173 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 168 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
174 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | 169 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
175 return FALSE; | 170 return FALSE; |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 CJS_PropValue& vp, | 853 CJS_PropValue& vp, |
859 CFX_WideString& sError) { | 854 CFX_WideString& sError) { |
860 if (vp.IsGetting()) { | 855 if (vp.IsGetting()) { |
861 vp << m_bDelay; | 856 vp << m_bDelay; |
862 } else { | 857 } else { |
863 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 858 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
864 return FALSE; | 859 return FALSE; |
865 | 860 |
866 vp >> m_bDelay; | 861 vp >> m_bDelay; |
867 if (m_bDelay) { | 862 if (m_bDelay) { |
868 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) | 863 m_DelayData.clear(); |
869 delete m_DelayData.GetAt(i); | |
870 | |
871 m_DelayData.RemoveAll(); | |
872 } else { | 864 } else { |
873 CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess; | 865 std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; |
874 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { | 866 DelayDataToProcess.swap(m_DelayData); |
875 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { | 867 for (const auto& pData : DelayDataToProcess) |
876 DelayDataToProcess.Add(pData); | 868 Field::DoDelay(m_pDocument, pData.get()); |
877 m_DelayData.SetAt(i, NULL); | |
878 } | |
879 } | |
880 m_DelayData.RemoveAll(); | |
881 for (int i = 0, sz = DelayDataToProcess.GetSize(); i < sz; i++) { | |
882 CJS_DelayData* pData = DelayDataToProcess.GetAt(i); | |
883 Field::DoDelay(m_pDocument, pData); | |
884 DelayDataToProcess.SetAt(i, NULL); | |
885 delete pData; | |
886 } | |
887 } | 869 } |
888 } | 870 } |
889 return TRUE; | 871 return TRUE; |
890 } | 872 } |
891 | 873 |
892 FX_BOOL Document::keywords(IJS_Context* cc, | 874 FX_BOOL Document::keywords(IJS_Context* cc, |
893 CJS_PropValue& vp, | 875 CJS_PropValue& vp, |
894 CFX_WideString& sError) { | 876 CFX_WideString& sError) { |
895 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | 877 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
896 if (!pDictionary) | 878 if (!pDictionary) |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 | 1572 |
1591 FX_BOOL Document::getURL(IJS_Context* cc, | 1573 FX_BOOL Document::getURL(IJS_Context* cc, |
1592 const std::vector<CJS_Value>& params, | 1574 const std::vector<CJS_Value>& params, |
1593 CJS_Value& vRet, | 1575 CJS_Value& vRet, |
1594 CFX_WideString& sError) { | 1576 CFX_WideString& sError) { |
1595 // Unsafe, not supported. | 1577 // Unsafe, not supported. |
1596 return TRUE; | 1578 return TRUE; |
1597 } | 1579 } |
1598 | 1580 |
1599 void Document::AddDelayData(CJS_DelayData* pData) { | 1581 void Document::AddDelayData(CJS_DelayData* pData) { |
1600 m_DelayData.Add(pData); | 1582 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); |
1601 } | 1583 } |
1602 | 1584 |
1603 void Document::DoFieldDelay(const CFX_WideString& sFieldName, | 1585 void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
1604 int nControlIndex) { | 1586 int nControlIndex) { |
1605 CFX_DWordArray DelArray; | 1587 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; |
1606 CFX_ArrayTemplate<CJS_DelayData*> DelayDataForFieldAndControlIndex; | 1588 auto iter = m_DelayData.begin(); |
1607 | 1589 while (iter != m_DelayData.end()) { |
1608 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { | 1590 auto old = iter++; |
1609 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { | 1591 if ((*old)->sFieldName == sFieldName && |
1610 if (pData->sFieldName == sFieldName && | 1592 (*old)->nControlIndex == nControlIndex) { |
1611 pData->nControlIndex == nControlIndex) { | 1593 DelayDataForFieldAndControlIndex.push_back(std::move(*old)); |
1612 DelayDataForFieldAndControlIndex.Add(pData); | 1594 m_DelayData.erase(old); |
1613 m_DelayData.SetAt(i, NULL); | |
1614 DelArray.Add(i); | |
1615 } | |
1616 } | 1595 } |
1617 } | 1596 } |
1618 | 1597 |
1619 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { | 1598 for (const auto& pData : DelayDataForFieldAndControlIndex) |
1620 m_DelayData.RemoveAt(DelArray[j]); | 1599 Field::DoDelay(m_pDocument, pData.get()); |
1621 } | |
1622 | |
1623 for (int i = 0, sz = DelayDataForFieldAndControlIndex.GetSize(); i < sz; | |
1624 i++) { | |
1625 CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i); | |
1626 Field::DoDelay(m_pDocument, pData); | |
1627 DelayDataForFieldAndControlIndex.SetAt(i, NULL); | |
1628 delete pData; | |
1629 } | |
1630 } | 1600 } |
1631 | 1601 |
1632 CJS_Document* Document::GetCJSDoc() const { | 1602 CJS_Document* Document::GetCJSDoc() const { |
1633 return static_cast<CJS_Document*>(m_pJSObject); | 1603 return static_cast<CJS_Document*>(m_pJSObject); |
1634 } | 1604 } |
OLD | NEW |