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

Side by Side Diff: fpdfsdk/javascript/Document.cpp

Issue 2626073005: Use observed pointers in CPDFSDK_AnnotIterator. (Closed)
Patch Set: remove local Created 3 years, 11 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/cpdfsdk_pageview.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/javascript/Document.h" 7 #include "fpdfsdk/javascript/Document.h"
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "core/fpdfapi/font/cpdf_font.h" 12 #include "core/fpdfapi/font/cpdf_font.h"
13 #include "core/fpdfapi/page/cpdf_page.h" 13 #include "core/fpdfapi/page/cpdf_page.h"
14 #include "core/fpdfapi/parser/cpdf_array.h" 14 #include "core/fpdfapi/parser/cpdf_array.h"
15 #include "core/fpdfapi/parser/cpdf_document.h" 15 #include "core/fpdfapi/parser/cpdf_document.h"
16 #include "core/fpdfapi/parser/cpdf_string.h" 16 #include "core/fpdfapi/parser/cpdf_string.h"
17 #include "core/fpdfapi/parser/fpdf_parser_decode.h" 17 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
18 #include "core/fpdfdoc/cpdf_interform.h" 18 #include "core/fpdfdoc/cpdf_interform.h"
19 #include "core/fpdfdoc/cpdf_nametree.h" 19 #include "core/fpdfdoc/cpdf_nametree.h"
20 #include "fpdfsdk/cpdfsdk_annotiterator.h" 20 #include "fpdfsdk/cpdfsdk_annotiteration.h"
21 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" 21 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
22 #include "fpdfsdk/cpdfsdk_interform.h" 22 #include "fpdfsdk/cpdfsdk_interform.h"
23 #include "fpdfsdk/cpdfsdk_pageview.h" 23 #include "fpdfsdk/cpdfsdk_pageview.h"
24 #include "fpdfsdk/cpdfsdk_widget.h" 24 #include "fpdfsdk/cpdfsdk_widget.h"
25 #include "fpdfsdk/javascript/Annot.h" 25 #include "fpdfsdk/javascript/Annot.h"
26 #include "fpdfsdk/javascript/Field.h" 26 #include "fpdfsdk/javascript/Field.h"
27 #include "fpdfsdk/javascript/Icon.h" 27 #include "fpdfsdk/javascript/Icon.h"
28 #include "fpdfsdk/javascript/JS_Define.h" 28 #include "fpdfsdk/javascript/JS_Define.h"
29 #include "fpdfsdk/javascript/JS_EventHandler.h" 29 #include "fpdfsdk/javascript/JS_EventHandler.h"
30 #include "fpdfsdk/javascript/JS_Object.h" 30 #include "fpdfsdk/javascript/JS_Object.h"
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 return false; 1105 return false;
1106 } 1106 }
1107 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 1107 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1108 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1108 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1109 int nPageNo = params[0].ToInt(pRuntime); 1109 int nPageNo = params[0].ToInt(pRuntime);
1110 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); 1110 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime);
1111 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); 1111 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo);
1112 if (!pPageView) 1112 if (!pPageView)
1113 return false; 1113 return false;
1114 1114
1115 CPDFSDK_AnnotIterator annotIterator(pPageView, false); 1115 CPDFSDK_AnnotIteration annotIteration(pPageView, false);
1116 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; 1116 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr;
1117 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { 1117 for (const auto& pSDKAnnotCur : annotIteration) {
1118 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); 1118 CPDFSDK_BAAnnot* pBAAnnot =
1119 static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get());
1119 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { 1120 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) {
1120 pSDKBAAnnot = pBAAnnot; 1121 pSDKBAAnnot = pBAAnnot;
1121 break; 1122 break;
1122 } 1123 }
1123 } 1124 }
1124
1125 if (!pSDKBAAnnot) 1125 if (!pSDKBAAnnot)
1126 return false; 1126 return false;
1127 1127
1128 v8::Local<v8::Object> pObj = 1128 v8::Local<v8::Object> pObj =
1129 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); 1129 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID);
1130 if (pObj.IsEmpty()) 1130 if (pObj.IsEmpty())
1131 return false; 1131 return false;
1132 1132
1133 CJS_Annot* pJS_Annot = 1133 CJS_Annot* pJS_Annot =
1134 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); 1134 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
1135 if (!pJS_Annot) 1135 if (!pJS_Annot)
1136 return false; 1136 return false;
1137 1137
1138 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); 1138 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject());
1139 if (!pAnnot) 1139 if (!pAnnot)
1140 return false; 1140 return false;
1141 1141
1142 pAnnot->SetSDKAnnot(pSDKBAAnnot); 1142 pAnnot->SetSDKAnnot(pSDKBAAnnot);
1143
1144 vRet = CJS_Value(pRuntime, pJS_Annot); 1143 vRet = CJS_Value(pRuntime, pJS_Annot);
1145 return true; 1144 return true;
1146 } 1145 }
1147 1146
1148 bool Document::getAnnots(IJS_Context* cc, 1147 bool Document::getAnnots(IJS_Context* cc,
1149 const std::vector<CJS_Value>& params, 1148 const std::vector<CJS_Value>& params,
1150 CJS_Value& vRet, 1149 CJS_Value& vRet,
1151 CFX_WideString& sError) { 1150 CFX_WideString& sError) {
1152 if (!m_pFormFillEnv) { 1151 if (!m_pFormFillEnv) {
1153 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); 1152 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1154 return false; 1153 return false;
1155 } 1154 }
1156 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 1155 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1157 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1156 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1158 1157
1159 // TODO(tonikitoo): Add support supported parameters as per 1158 // TODO(tonikitoo): Add support supported parameters as per
1160 // the PDF spec. 1159 // the PDF spec.
1161 1160
1162 int nPageNo = m_pFormFillEnv->GetPageCount(); 1161 int nPageNo = m_pFormFillEnv->GetPageCount();
1163 CJS_Array annots; 1162 CJS_Array annots;
1164 1163
1165 for (int i = 0; i < nPageNo; ++i) { 1164 for (int i = 0; i < nPageNo; ++i) {
1166 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i); 1165 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i);
1167 if (!pPageView) 1166 if (!pPageView)
1168 return false; 1167 return false;
1169 1168
1170 CPDFSDK_AnnotIterator annotIterator(pPageView, false); 1169 CPDFSDK_AnnotIteration annotIteration(pPageView, false);
1171 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { 1170 for (const auto& pSDKAnnotCur : annotIteration) {
1172 CPDFSDK_BAAnnot* pSDKBAAnnot = 1171 if (!pSDKAnnotCur) {
1173 static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); 1172 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1174 if (!pSDKBAAnnot)
1175 return false; 1173 return false;
1176 1174 }
1177 v8::Local<v8::Object> pObj = 1175 v8::Local<v8::Object> pObj =
1178 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); 1176 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID);
1179 if (pObj.IsEmpty()) 1177 if (pObj.IsEmpty())
1180 return false; 1178 return false;
1181 1179
1182 CJS_Annot* pJS_Annot = 1180 CJS_Annot* pJS_Annot =
1183 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); 1181 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
1184 if (!pJS_Annot) 1182 if (!pJS_Annot)
1185 return false; 1183 return false;
1186 1184
1187 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); 1185 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject());
1188 if (!pAnnot) 1186 if (!pAnnot)
1189 return false; 1187 return false;
1190 1188
1191 pAnnot->SetSDKAnnot(pSDKBAAnnot); 1189 pAnnot->SetSDKAnnot(static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get()));
1192 annots.SetElement(pRuntime, i, CJS_Value(pRuntime, pJS_Annot)); 1190 annots.SetElement(pRuntime, i, CJS_Value(pRuntime, pJS_Annot));
1193 } 1191 }
1194 } 1192 }
1195
1196 vRet = CJS_Value(pRuntime, annots); 1193 vRet = CJS_Value(pRuntime, annots);
1197 return true; 1194 return true;
1198 } 1195 }
1199 1196
1200 bool Document::getAnnot3D(IJS_Context* cc, 1197 bool Document::getAnnot3D(IJS_Context* cc,
1201 const std::vector<CJS_Value>& params, 1198 const std::vector<CJS_Value>& params,
1202 CJS_Value& vRet, 1199 CJS_Value& vRet,
1203 CFX_WideString& sError) { 1200 CFX_WideString& sError) {
1204 vRet.SetNull(CJS_Runtime::FromContext(cc)); 1201 vRet.SetNull(CJS_Runtime::FromContext(cc));
1205 return true; 1202 return true;
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 } 1717 }
1721 } 1718 }
1722 1719
1723 for (const auto& pData : DelayDataForFieldAndControlIndex) 1720 for (const auto& pData : DelayDataForFieldAndControlIndex)
1724 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); 1721 Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
1725 } 1722 }
1726 1723
1727 CJS_Document* Document::GetCJSDoc() const { 1724 CJS_Document* Document::GetCJSDoc() const {
1728 return static_cast<CJS_Document*>(m_pJSObject); 1725 return static_cast<CJS_Document*>(m_pJSObject);
1729 } 1726 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_pageview.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698